Display SnackBar in Flutter

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

    **

    ScaffoldState is now deprecated. Use ScaffoldMessengerState.

    **

    All the above solutions are amazing but as it's deprecated now you should use it this way.

        var snackBar = SnackBar(content: Text('Hello World'));
    
        ScaffoldMessenger.of(_scaffoldKey.currentContext)
        .showSnackBar(snackBar );
    

提交回复
热议问题