फ़्लटर में शो-डॉग बंद होने के बाद पैरेंट विजेट कैसे अपडेट करें?

Nov 29 2020

मेरे पास एक आइकन के साथ एक विजेट है जब मैं उस पर क्लिक करता हूं तो एक डायलॉग विजेट दिखाया जाता है, यहां डायलॉग के लिए कॉल है:

// this icon is in widget parent
           IconButton(
              icon: Icon(
                Icons.info_outline,
                size: mobileWidth * 0.07,
              ),
              tooltip: 'information',
              color: Colors.blueGrey,
              onPressed: () {
                showAlertInfo(context, code);
                setState(() {});
              },
            ),

यहाँ मेरा संवाद है:

showAlertInfo(BuildContext context, String code) {
  showDialog(
    context: context,
    builder: (context) {
      return StatefulBuilder(
        builder: (context, setState) {
          return AlertDialog(
            title: Text(
              "Information sur le client $code", ),
            content: SingleChildScrollView(
               child: Container( ..... 
               /* ...
               this dialog has some operations that changes info 
               values of the widget that called this in first place
               it is a big code to put here*/
             // here I have a close button
                    actions: [
            FlatButton(
            child: Text(
              "Fermer",
              style: TextStyle(
                color: Colors.red,
                fontSize: mobileWidth * 0.035,
                fontWeight: FontWeight.bold,
              ),
            ),
            onPressed: () {
              Navigator.of(context).pop(); // dismiss dialog
            },
          ),
        ],
      );  

जब मैं डायलॉग खारिज कर देता हूं तो मैं इसे हासिल करना चाहता हूं। मैं चाहता हूं कि पैरेंट विजेट अपडेट हो जाए, इसलिए setStateडायलॉग विजेट के बंद होने पर मैं पैरेंट विजेट को कैसे कॉल करूं?

जवाब

2 TahaMalik Nov 29 2020 at 06:58

Async फ़ंक्शन के लिए

awaitपहले जोड़ें showDialog()और setState((){})अगली पंक्ति पर कॉल करें ।

await showDialog(
    context: context,
    builder: (context) {
       return yourWidget;
    }
);
setState((){});

सिंक फंक्शन के लिए

.then()कॉलबैक का उपयोग करें , और इसमें कॉल करें setState((){})


showDialog(
    context: context,
    builder(context) {
        return yourWidget;
    }).then((_){
        setState((){});
    }
);