美文网首页
flutter路由

flutter路由

作者: 爱运动的年轻人 | 来源:发表于2020-08-06 14:46 被阅读0次
题记
当你在沉睡,我听得见自己的悲鸣,穿透骨髓,在眼睛里无数次破碎;
尘埃与硝烟,我看得见疼痛如心碎,重叠心底的眼泪,燃烧出血液中的无畏

1.直接进入页面(每次都将新建一个新的页面)

Navigator.of(context).pushNamed('routeName')

2.把当前页面在栈中的位置替换为跳转的页面, 当新的页面进入后,之前的页面将执行dispose方法
举个例子 页面1进入到页面2 在页面2中pushReplacementNamed打开页面3 此时 在页面3中按返回 退出到页面1

Navigator.of(context).pushReplacementNamed('routeName')

3.同上面2 区别 pushReplacementNamed 是路由名字 而pushReplacement 是页面名字

Navigator.pushReplacement( context, MaterialPageRoute(builder: (BuildContext context) => screen()))

4.pop 当前页面 跳转制定路由页面

popAndPushNamed——Navigator.popAndPushNamed(context, 'routeName')

5.跳转到路由页面 pop掉前面的所有页面

Navigator.of(context).pushNamedAndRemoveUntil('/screen', (Route<dynamic> route) => false)

6.跳转到新的路由 然后pop 其他所有页面

举个例子 page1-page2-page3-page4 这时候在page4页面中Navigator.popUntil(context, ModalRoute.withName('/page2')) 会回退到page2 pop掉page3 page4


popUntil——Navigator.popUntil(context, ModalRoute.withName('/page2'))

pop 当前页面

Navigator.of(context).pop()

相关文章

网友评论

      本文标题:flutter路由

      本文链接:https://www.haomeiwen.com/subject/bvgzrktx.html