How to show snackbar after navigator.pop(context) in Flutter?

你。 提交于 2019-11-27 06:46:28

问题


We need close one screen and open second screen. And show snackbar on second screen from first screen.

I tried to use Navigator.push , but this screen is already open and we have this error "Bad state: Stream has already been listened to".


回答1:


Instead of Snackbar i would suggest you to use Flushbar plugin for flutter it is easy to use and it'll take care of everything and u can customize it to a great extent . Snackbar needs a scaffold ancestor to work but Flushbar doesn't and it takes care of all the extra stuff itself and provides with ton of cool features.

Flushbar Plugin here




回答2:


showSubmitRequestSnackBar(BuildContext context) async {

  Flushbar(
    flushbarPosition: FlushbarPosition.BOTTOM,
    message: "Request Successfully Saved",
    icon: Icon(
      Icons.info_outline,
      size: 28.0,
      color: Colors.red,
    ),
    backgroundColor: Colors.red,
    duration: Duration(seconds: 5),
    leftBarIndicatorColor: Colors.red,

  )
    ..show(context).then((r)=> Navigator.push(
        context, MaterialPageRoute(builder: (context) => ListPage(""))));
}


来源:https://stackoverflow.com/questions/51260227/how-to-show-snackbar-after-navigator-popcontext-in-flutter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!