1

CupertinoTextField が空でない場合、CupertinoDialogAction を有効にするように設定したいのですが、それ以外の場合はデフォルトで無効にする必要があります。また、「isDefaultAction: false」を設定しましたが、それでもクリック可能です。

showDialog(
          context: context,
          builder: (BuildContext context) => CupertinoAlertDialog(
            actions: [
              CupertinoDialogAction(
                onPressed: () => (Navigator.of(context).pop()),
                child: Text("Cancel"),
              ),
              CupertinoDialogAction(
                child: Text("Save"),
                isDefaultAction: false,
              ),
            ],
            title: Text("New Folder"),
            content: Column(
              children: <Widget>[
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Text("Enter a name for this folder"),
                ),
                Container(
                  height: 30,
                  child: CupertinoTextField(
                    controller: folderName,
                    placeholder: "Name",
                    decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(8),
                    ),
                  ),
                )
              ],
            ),
          ),
        );
4

2 に答える 2

0

を無効にする場合は、プロパティをCupertinoDialogActionに設定する必要があります。次のようになります。onPressednull

       Bool isEnabled = false;

       @override
       void initState() {
         super.initState();

         folderName.addListener(enableButton); // addListened to your TextEditingController!
       }

isEnabled を true に設定します。

      enableButton()
      {
        if(folderName.text != "")
        {
          setState(() {
            isEnabled = true;
          });
        }                
      }

そして、このブールフィールドを使用できます。

      CupertinoDialogAction(
              onPressed: !isEnabled 
                  ? null
                  : () {
                      // Do what you need!
                      // Save method!
                    },
              child: Text("Save"),
              isDefaultAction: false,
            ),
于 2020-12-06T09:36:01.070 に答える