【问题标题】:Pass arguments to pushnamed but in receiver widget give null in flutter将参数传递给 pushnamed 但在接收器小部件中在颤振中给出 null
【发布时间】:2021-08-22 04:09:49
【问题描述】:

我将数据从一个小部件发送到另一个小部件输入了值,但是当我转到下一个小部件或接收器小部件时,它给了我空值我尝试了 s.o.f 的所有答案,但没有任何效果。我正在使用稳定的频道 2.1。

发件人小部件

         routes: {
    '/result': (context) => LoginScreen(),
  },

      Navigator.pushNamed(context, '/result',arguments: {
                'weight':count,
                'height':heights,
              });

接收器小部件:

              final  argument= ModalRoute.of(context)!.settings.arguments as Map;
print(argument['weight']);

这是我在接收器小部件“类型 null 不是类型转换中类型映射的子类型”时遇到的错误

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    材料应用

      routes: {
        '/result': (context) => LoginScreen(),
      }
    

    导航

     Navigator.pushNamed(context, '/result', arguments: {
        'weight': count,
        'height': heights,
     });
    

    登录屏幕()

    final argument = ModalRoute.of(context)!.settings.arguments as Map<String, dynamic>;
    print(argument['weight']);
    

    【讨论】:

      【解决方案2】:

      在路线页面,试试这个:

      TestPage.routeName: (context) => TestPage(),
      

      打电话时,试试这个:

      Navigator.pushNamed(context, TestPage.routeName)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-11
        • 2021-03-04
        • 1970-01-01
        • 2020-02-13
        • 2013-01-31
        • 1970-01-01
        • 1970-01-01
        • 2020-07-24
        相关资源
        最近更新 更多