路由返回传值
父:
onTap: () {
CommonUtil.openPage(context, CreatLogisticsPage()).then((value){
//value就是_dataRefresh()
refresh();//回来了~那就刷新
});
},
子:
Navigator.pop(context,'_dataRefresh()');
toast("提交成功");
路由替换
Navigator.pushReplacement(
context, new MaterialPageRoute(builder: (context) => widget));
组件回调传值
- 父引用组件
void onDataChange1(val) {
//各种在父操作,比如刷新数据,可判断if(val==ture){执行}
<!--if(mounted)-->
<!-- Future.delayed(Duration(milliseconds: 200)).then((e) {-->
<!-- setState(() {-->
<!-- isTab = val;-->
<!-- });-->
<!-- });-->
}
new DistributorProductListsPage(callback: (val)=> onDataChange1(val) ),
- 子文件:
import 'package:flutter/material.dart';
import 'package:jihong_horticulture_warehouse/common/CommonInsert.dart';
///E2供应商商品汇总
class DistributorProductListsPage extends StatefulWidget {
final callback;
DistributorProductListsPage({Key key, this.callback})
:super(key: key);
@override
_DistributorProductListsPageState createState() => _DistributorProductListsPageState();
}
class _DistributorProductListsPageState extends State<DistributorProductListsPage> {
void initState() {
// TODO: implement initState
super.initState();
widget.callback(true);
}
路由清除并跳转
Navigator.of(context).pushNamedAndRemoveUntil('/LoginPage', (Route<dynamic> route) => false);
or
Navigator.pushAndRemoveUntil(context, MaterialPageRoute(builder:(BuildContext context)=>LoginPage()), ModalRoute.withName('/'));