【问题标题】:Inserting JSON information in Flutter Cards?在 Flutter Cards 中插入 JSON 信息?
【发布时间】:2017-12-20 04:32:04
【问题描述】:

如何向flutter Card Widgets 提供 JSON 信息,就像在 Swift 中使用 tableView 控制器一样;这是为各种数组提供标题、图像、描述,例如并索引每个项目?

**** 使用 JSON 解码代码更新

var httpClient = createHttpClient();
    var response = await httpClient.read(url);
    String data = JSON.decode(response);
    Map items = JSON.decode(data);
    Map<String, dynamic> decoded = new JsonCodec().decode(data);
    for (String key in decoded.keys) {
      print("Key $key contains: ${decoded[key]}");

我已经添加了上面的代码,现在我收到了这个错误。请提供有关如何修复的任何想法。顺便说一句...这是来自 YouTube ResponseList

type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'String' of 'data' where
      _InternalLinkedHashMap is from dart:collection
      String is from dart:core
      String is from dart:core

【问题讨论】:

    标签: arrays json widget flutter


    【解决方案1】:
    1. 以您选择的任何方法(文件 I/O、Web)以 String 的形式检索数据

    2. 使用JSON.decode 将其解码为地图。之后,我建议您使用地图构建模型对象,但这不是必需的。

    3. 将数据提供给读取所述数据的 Widget。

    【讨论】:

    • 最好的序列化方式是什么?即当你在“sn-ps”中的“项目”中的“标题”字典时
    • 请查看更新的代码和错误。请注意,Map items 未被使用,但会引发类似错误。
    猜你喜欢
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    • 2015-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多