【问题标题】:How to pass Json data to another screen in flutter如何在颤动中将 Json 数据传递到另一个屏幕
【发布时间】:2019-09-21 05:06:45
【问题描述】:
List results;      
setState(() {
          var resBody = json.decode(res.body);
          print('Response body: ${resBody}');
          results = resBody;
        });
        Navigator.push(
            context,
            MaterialPageRoute(
              builder: (context) => SecondScreen(jsondata: results,),
            ));

results 是一个 jsondata 并将其作为 jsondata 传递到第二个屏幕

在 secondscreen 中如何检索 jsondata ?

【问题讨论】:

  • 你把它传给了构造函数。
  • 你已经通过了,我看不出有什么问题??

标签: json dart flutter


【解决方案1】:

您可以将 JsonData “状态”存储在模型类中并在另一个屏幕中使用它。

【讨论】:

    【解决方案2】:

    这可能会对您有所帮助。告诉我

    class SecondScreen extends StatefulWidget {
    
      final List jsondata;
    
      SecondScreen({Key key, this.jsondata}) : super(key: key);
    
      @override
      _SecondScreenState createState() => _SecondScreenState();
    }
    
    class _SecondScreenState extends State<SecondScreen> {
    
        // use jsondata here in widget here like this,
    **widget.jsondata**
    
    }
    

    【讨论】:

    • primo 谢谢它的作品
    猜你喜欢
    • 2021-11-07
    • 2020-07-12
    • 2021-07-01
    • 2023-01-11
    • 1970-01-01
    • 1970-01-01
    • 2020-02-16
    • 2019-07-18
    • 2022-01-12
    相关资源
    最近更新 更多