Display SnackBar in Flutter

前端 未结 15 1522
一个人的身影
一个人的身影 2020-12-04 19:28

I want to display a simple SnackBar inside Flutter\'s stateful widget. My application creates new instance of MaterialApp with a stateful widget ca

15条回答
  •  情书的邮戳
    2020-12-04 19:48

    If you are inside a widget that does not has directly the return Scaffold(...) widget, you can do this:

    Scaffold.of(context).showSnackBar(SnackBar(content: Text("Hello from snackbar")));
    

    There is no need to create an extra Scaffold widget because the showSnackBar() method requires one, you can reuse.

提交回复
热议问题