flutterdartflutter-dialog

Pass value when dialog closed


I'm trying to create an app in Flutter.

When a particular button is pressed a Dialog shows up. In the dialog, the user can write to TextField. I want to use this text in the previous screen when the dialog is closed with pop().

Is there any way to do it?


Solution

  • try this:

    showDialog(
      context: context,
      builder: (context) => Dialog(),
    ).then((result){
      // use the result here
    });
    

    and in dialog pop like this:

    Navigator.pop(context, result);