Home > Blockchain >  Any way to show a snackBar once per stateful page build?
Any way to show a snackBar once per stateful page build?

Time:06-04

I want to show SnackBar pop-up once per build of a certain stateful page. This is a Flutter web project. Any help will be appreciated.

CodePudding user response:

i guess this is what you meant

Stafeful Widget {
    Widget build() {
       showsnackbar()
       return someWIdget();
   }

CodePudding user response:

Basically, I am using .addPostFrameCallback it will show after the frame is build.

 _showSnackBar() {
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      ScaffoldMessenger.of(context)
          .showSnackBar(SnackBar(content: Text("SnackBar")));
    });
  }

And place _showSnackBar() under build method.

  Widget build(BuildContext context) {
    _showSnackBar();
    ......
  • Related