Open flutter dialog after navigation

后端 未结 3 1228

I call Navigator pushReplacement to show a new view within my flutter app and want to immediately pop up a simple dialog to introduce the page to the user. (I want the user

3条回答
  •  独厮守ぢ
    2020-12-29 04:35

    You can call the dialog from inside 'initState()' dalaying its appearance after the first frame has been drawn.

      @override
      void initState() {
        super.initState();
        WidgetsBinding.instance.addPostFrameCallback((_) async {
          await showDialog(
            context: context,
            builder: (BuildContext context) => new AlertDialog(
                  title: new Text("title"),
                  content: new Text("Message"),
                  actions: [
                    new FlatButton(
                      child: new Text("OK"),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    ),
                  ],
                ),
          );
        });
      }
    

提交回复
热议问题