flutter bloc go_route 对象传参
- 路由
GoRoute( name: 'login', path: '/login', builder: (BuildContext context, GoRouterState state) { //对象传值 User user = state.extra as User; return LoginPage( user: user, ); }, ),
- 如何使用,以下使用例子
@override Widget build(BuildContext context) { return AppBar( leading: IconButton( onPressed: () => { context.pushNamed('login', extra: context.read<UserBloc>().state.data!.first) }, icon: const Icon(Icons.apps), ),
效果图
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.user.name),
leading: IconButton(
onPressed: () => Navigator.pop(context),
icon: const Icon(Icons.arrow_back_outlined),
),
),
本作品采用《CC 协议》,转载必须注明作者和本文链接