Flutter remove all routes

前端 未结 10 2033
难免孤独
难免孤独 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:14

    If you are using namedRoutes, you can do this by simply :

    Navigator.pushNamedAndRemoveUntil(context, "/login", (Route route) => false);
    

    Where "/login" is the route you want to push on the route stack.

    Note That :

    This statement removes all the routes in the stack and makes the pushed one the root.

提交回复
热议问题