Display SnackBar in Flutter

前端 未结 15 1543
一个人的身影
一个人的身影 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:49

    initState been called before build I guess _scaffoldKey.currentState has not been initialized when it is call.

    I don't know if you can get a ScaffoldState from initState. If you change your code you can show the snackbar from build method with:

    Scaffold.of(context).showSnackBar(SnackBar(Text(value)));
    

提交回复
热议问题