Flutter Navigation pop to index 1

前端 未结 9 1350
梦毁少年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:59

    //========================================================
              new ListTile(
                title: new RaisedButton(
                  child: new Text("POP until"),
                  onPressed: () {
                    var route = new MaterialPageRoute(
                      builder: (BuildContext context) =>
                          new NextPage3(value:"hi there from 3"),
                    );
                   //Navigator.pop(context, ModalRoute.withName('/'));
                    Navigator.popUntil(context,ModalRoute.withName('/'));                
                  },
                ),
              ),
    //========================================================
    

    replace .pop with .popUntil, actually works very elegantly.

提交回复
热议问题