【问题标题】:Flutter Futurebuilder showing error when showing snapshot data valueFlutter Futurebuilder 在显示快照数据值时显示错误
【发布时间】:2021-01-02 08:19:48
【问题描述】:

我在应用程序中使用 Future builder,它工作正常,但是当数据加载以及我在 Text 小部件中显示它时,它会显示此错误

Class '_InternalLinkedHashMap<String, dynamic>' has no instance getter 'approved_value'.
Receiver: _LinkedHashMap len:31
Tried calling: approved_value

我的代码

class _ClaimsScreenState extends State<ClaimsScreen> {
  @override
  initState() {
    super.initState();
    doSomeAsyncStuff();
  }

  Future<List> doSomeAsyncStuff() async {
    final storage = new FlutterSecureStorage();
    String value = await storage.read(key: 'health_card');
    print(value);

    String url2 =
        'api.com';

    final response2 = await http.get(url2);
    var Data = json.decode(response2.body);
    print(Data);
    var DisplayData = Data["records"];

    return DisplayData;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text('IGI GENERAL INSURANCE'),
      ),
      body: FutureBuilder<List>(
          future: doSomeAsyncStuff(),
          builder: (BuildContext context, AsyncSnapshot<List> snapshot) {
            if (snapshot.hasData) {
              print('ss');
              print(snapshot.data);
              return ListView.builder(
                  itemCount: snapshot.data.length,
                  itemBuilder: (BuildContext context, int index) {
                    return Card(
                      child: Column(
                        children: <Widget>[
                          Row(
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text('Approved Value:'),
                                  Text(snapshot.data[index].approved_value)
                                ],
                              ),
                              Row(
                                children: <Widget>[
                                  Text('Patient Name:'),
                                  Text(snapshot.data[index].patient_name)
                                ],
                              )
                            ],
                          ),
                          Row(
                            children: <Widget>[
                              Row(
                                children: <Widget>[
                                  Text('Claimed Value:'),
                                  Text(snapshot.data[index].claimed_value)
                                ],
                              ),
                              Row(
                                children: <Widget>[
                                  Text('status:'),
                                  Text(snapshot.data[index].patient_name)
                                ],
                              )
                            ],
                          )
                        ],
                      ),
                    );
                  });
            } else if (snapshot.hasError) {
              return Padding(
                padding: const EdgeInsets.only(top: 16),
                child: Text('Error: ${snapshot.error}'),
              );
            } else {
              return Padding(
                padding: EdgeInsets.only(top: 16),
                child: Text('Awaiting result...'),
              );
            }
          }),
    );
  }
}

我在未来的构建器中使用列表视图构建器,因为值在数组中并且需要在文本小部件中显示全部

我不知道为什么它显示这个错误如果删除值它工作正常只是当我在文本小部件中显示值然后它显示错误。

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    snapshot.data[index] 返回一个MapMap 类没有 approved_value getter。你可能打算改用snapshot.data[index]['approved_value']

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-02
      • 2021-11-17
      • 1970-01-01
      • 2020-04-25
      • 2021-02-10
      • 2020-02-10
      • 2022-01-02
      • 2020-04-12
      相关资源
      最近更新 更多