Using Navigator.popUntil and route without fixed name

前端 未结 2 2005
小鲜肉
小鲜肉 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"))
    

提交回复
热议问题