Flutter remove all routes

前端 未结 10 1891
难免孤独
难免孤独 2021-01-30 04:46

I want to develop a logout button that will send me to the log in route and remove all other routes from the Navigator. The documentation doesn\'t seem to explain h

10条回答
  •  广开言路
    2021-01-30 05:25

    I dont know why no one mentioned the solution using SchedularBindingInstance,A little late to the party though,I think this would be the right way to do it originally answered here

        SchedulerBinding.instance.addPostFrameCallback((_) async {
                                  Navigator.of(context).pushNamedAndRemoveUntil(
                                      '/login',
                                      (Route route) => false);
                                });
    

    The above code removes all the routes and naviagtes to '/login' this also make sures that all the frames are rendered before navigating to new route by scheduling a callback

提交回复
热议问题