How to update the Homepage just after the showDialog()
is dismissed/disposed? Doesn't seem like it has an onDispose()
function.
Found another possible Answer : The WillPopScope
can help detect if the back button is pressed.
The widget that will be used in the showDialog
, in its build function the widget can be wrapped in return new WillPopScope(child: ______, onWillPop: _______);
The code can be run in the onWillPop
function. This can update the Homepage below.
In its on the pressed property, we have to use the showDialog widget of flutter. It takes context and a builder. In builder, we provide the AlertDialog widget with title, content(Description of a title), and actions (Yes or no buttons), and our alert dialog box is ready to use.
pop(result) to close the dialog rather just Navigator. pop(context, result).
You can do it using showGeneralDialog and put dismissible property to false , using this will ensure you that you are the only one who is handling pop up, like in your any action buttons in dialog.
Simply use await
or then
. the code in then
block will be run after the dialog is dismissed.
showDialog( // Your Dialog Code ).then((val){ Navigator.pop(_context); });
It really depends on the type of updates you want to have.
However, this is a simple example that may help you figure it out.
class Home extends StatefulWidget { @override _HomeState createState() => new _HomeState(); } class _HomeState extends State<Home> { String _homeData = "initial data"; @override Widget build(BuildContext context) { return new Scaffold( body: new Center( child: new Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ new Text(_homeData), new RaisedButton( child: new Text("Show Dialog"), onPressed: ()async{ bool shouldUpdate = await showDialog( context: this.context, child:new AlertDialog( content: new FlatButton( child: new Text("update home"), onPressed: () => Navigator.pop(context, true), ), ), ); setState(() { shouldUpdate ? this._homeData = "updated" : null; }); }, ), ], ), ), ); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With