How to show snackBar without Scaffold

前端 未结 3 1968
清歌不尽
清歌不尽 2021-01-18 05:28

I am trying to show snackbar in my app to notify User but without scaffold it shows me error. My current code is:

scaffoldKey.currentState?.showSnackBar(
           


        
3条回答
  •  無奈伤痛
    2021-01-18 05:48

    It can get the current context and show snackbar like this:

    void _showToast(BuildContext context) {
      final scaffold = Scaffold.of(context);
      scaffold.showSnackBar(
        SnackBar(
          content: const Text('Updating..'),
        ),
      );
    
    this._showToast(context);
    

提交回复
热议问题