Route 路由以及页面间传值
一种页面跳转机制
路由 Route 对应到 Android 就是 Intent
Flutter 路由分两种:新建路由、注册路由
需要Route表示 Navigator进行管理
跳转页面 Navigator.push()
返回页面 Navigator.pop()
传值
1.新建路由
context
title
home
appBar
title
body
context
width infinity
color redAccent
child
crossAxisAlignment center
mainAxisAlignment center
children
style
fontSize
color white
color blue
child
style
color white
onPressed
context builder context
context
body
width infinity
color greenAccent
child
crossAxisAlignment center
mainAxisAlignment center
children
textDirection ltr
child
onPressed
context
2.注册路由
context
title
routes
context
context
home
context
appBar
title
body
width infinity
color redAccent
child
crossAxisAlignment center
mainAxisAlignment center
children
style
fontSize
color white
color blue
child
style
color white
onPressed
context
context
body
width infinity
color greenAccent
child
crossAxisAlignment center
mainAxisAlignment center
children
textDirection ltr
child
onPressed
context
3.传值(两种方式) 返回值
效果
3.1.新建路由传值
通过 MaterialPageRoute settings 参数包装要传递的值
RouteSettings 对象的 copyWith() 方法的arguments参数传值
具体请看详细代码或者源码
routeSettings copyWithSettings routeSettingsarguments _editControllertext
context
builder context
settings copyWithSettings
3.2.注册路由传值
比新建路由传值简单,arguments参数中传值
context
context arguments
示例代码
context
title
home
appBar
title
body
context
_editController
width infinity
color redAccent
child
crossAxisAlignment center
mainAxisAlignment center
children
style
fontSize
color white
margin
child
decoration
labelText
labelStyle color white
controller _editController
color blue
child
style
color white
onPressed
_editController context
margin
child secondValue
style
fontSize
fontWeight bold
color blue
secondValue
_editController context async
routeSettings
copyWithSettings
routeSettingsarguments _editControllertext
valueFromSecondPage await
context
builder context
settings copyWithSettings
secondValue secondValue
context
context arguments
context
passValue contextsettingsarguments
body
width infinity
color orange
child
crossAxisAlignment center
mainAxisAlignment center
children
style
fontSize
color white
textDirection ltr
margin
child
style
fontSize
color redAccent
textDirection ltr
child
onPressed
context
4.源码地址
https://github.com/jhbxyz/flutter_learn_art/tree/master/lib/ext/day1_route
5.文章
https://github.com/jhbxyz/flutter_learn_art/blob/master/article/Route.md
还没有评论,来说两句吧...