Using Navigator.popUntil and route without fixed name

前端 未结 2 1994
小鲜肉
小鲜肉 2020-12-10 05:45

Is it possible to use Navigator.popUntil with routes that do not have fixed names?

I have a route created the following way:

  final _key_homepage =          


        
相关标签:
2条回答
  • 2020-12-10 05:55

    You should add a setting when pushing your route; with a custom name

    Navigator.pushReplacement(
      context,
      MaterialPageRoute(
        settings: RouteSettings(name: "Foo"),
        builder: ...,
      ),
    );
    

    Then you can use popUntil as you'd do with named routes

    Navigator.popUntil(context, ModalRoute.withName("Foo"))
    
    0 讨论(0)
  • 2020-12-10 06:12

    If you do not use named routes or we want to the navigator to First active, you can use

    Navigator.of(context).popUntil((route) => route.isFirst)
    
    0 讨论(0)
提交回复
热议问题