flutter bloc go_route 对象传参

  1. 路由
    GoRoute(
       name: 'login',
       path: '/login',
       builder: (BuildContext context, GoRouterState state) {
         //对象传值
         User user = state.extra as User;
         return LoginPage(
           user: user,
         );
       },
     ),
  2. 如何使用,以下使用例子
    @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),
          ),
        ),

flutter go_route 对象传参

本作品采用《CC 协议》,转载必须注明作者和本文链接
pangxianfei
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!