How to show SnackBar in Flutter

后端 未结 3 1099
不思量自难忘°
不思量自难忘° 2021-01-25 08:23

I want to show a SnackBar Widget when the bottom tab is clicked. I am trying to show it as:

Scaffold.of(context).showSnackBar(new SnackBar(
                cont         


        
3条回答
  •  醉梦人生
    2021-01-25 09:00

    You do have a scaffold, but not above the context of MyHomePage. Your Scaffold is a child of MyHomePage, while doing Scaffold.of(context) is trying to access the closest parent Scaffold. And since you have none, it crash.

    You should probably wrap your BottomNavigationBar into a new class. And use that widget's context to do Scaffold.of(context).

提交回复
热议问题