Flutter Navigation pop to index 1

前端 未结 9 1354
梦毁少年i
梦毁少年i 2020-12-02 13:54

I am recursively adding routes to the navigator. There could be 20 views or more. Pop works as advertised, but I would like to pop to index 1 and remove all push history.

9条回答
  •  难免孤独
    2020-12-02 14:41

    You can also do it like this

    Navigator.of(context)
                .pushNamedAndRemoveUntil('/Destination', ModalRoute.withName('/poptillhere'),arguments: if you have any);
    

    The use case is to go the desired screen and pop the screens in between as you require.

    For more info, you can check this Post Explaining other Solutions

提交回复
热议问题