flutter 命名路由传参
2022-09-29 本文已影响0人
neobuger
需要展示的页面
class BreachDetailVC extends StatefulWidget {
String breachApplyId = "";
BreachDetailVC({Key? key}) : super(key: key);
BreachDetailVC.needId({Key? key, required this.breachApplyId}) : super(key: key);
@override
State<BreachDetailVC> createState() => _BreachDetailVCState();
}
class _BreachDetailVCState extends State<BreachDetailVC> {
@override
//在 initState写 获取参数的代码会报错
//breachApplyId是传入的参数
void didChangeDependencies() {
super.didChangeDependencies();
RouteSettings sttings = ModalRoute.of(context)!.settings!;
var args=sttings!.arguments;
Map params = args as Map;
this.widget.breachApplyId = params["breachApplyId"];
print(args);
print("breachApplyId" + this.widget.breachApplyId);
queryData();
}
}
//路由配置
class MyBreahRouteGenerator {
static final routes = {
"/breachList/detail":(context) => BreachDetailVC(),
// "/breachList/detail":(context, {arguments}) => BreachDetailVC(),
};
}
//跳转代码
Navigator.pushNamed(context, '/breachList/detail', arguments: {
"breachApplyId" : this.widget.model["breachApplyId"]
});