Flutter remove all routes

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

    I was able to accomplish this with the following code:

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

    The secret here is using a RoutePredicate that always returns false (Route route) => false. In this situation it removes all of the routes except for the new /login route I pushed.

提交回复
热议问题