简体   繁体   English

如何将 AsyncSnapshot 数据转换为 Map?

[英]How do I turn AsyncSnapshot data into a Map?

I want to get some json data in my FutureBuilder but for some reason my code throws a我想在我的 FutureBuilder 中获取一些 json 数据,但由于某种原因我的代码抛出一个
_TypeError (type '_JsonQuerySnapshot' is not a subtype of type 'Map<dynamic, dynamic>')
whenever I try to unpack the AsyncSnapshot into a Map.每当我尝试将 AsyncSnapshot 解压缩到 Map 时。

FutureBuilder(
    future: getFiyat(),
    builder: (BuildContext context, AsyncSnapshot snapshot) {
        if (snapshot.hasData) {
            lists.clear();

            // type error is thrown here
            Map<dynamic, dynamic> values = snapshot.data;

            values.forEach((key, values) {
                lists.add(values);
            });
        }

        return ListView.builder();
    },
);

What am I doing wrong here?我在这里做错了什么?

You have your QuerySnapshot data and you should call data() on this snapshot, to get its content.您有QuerySnapshot data ,您应该在此快照上调用data()以获取其内容。 In your case:在你的情况下:

QuerySnapshot<Object?>? querySnapshot = snapshot.data;
Map<dynamic, dynamic> values = querySnapshot.data();

我的 Querysnapshot Map 字符串变成 AsyncSnapshot<object> 没有理由<div id="text_translate"><p>我有一个 streamBuilder,其中“snapshots()”从Stream<QuerySnapshot<Map<String, dynamic>>>更改为AsyncSnapshot<Object?> 。 这很奇怪,因为我有另一个应用程序,具有相同的代码并且工作正常。 问题是,我无法访问“snapshot.data.docs”和所有 firestore 数据。 为什么会发生?</p><p> 我的代码:</p><pre> body: StreamBuilder( //Stream<QuerySnapshot<Map<String, dynamic>>> stream: firestore.collection('Books').orderBy('name').snapshots(), //AsyncSnapshot<Object?> builder: (context, snapshot ) { if (snapshot.connectionState == ConnectionState.waiting) return Center(child: CircularProgressIndicator()); { final document = snapshot.data?; //error here return ListView.builder( itemCount: document?.length, itemBuilder: (context, index) { return Column(</pre></div></object> - my Querysnapshot Map String become AsyncSnapshot<Object> with no reason

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何发送 webhook 数据并将其转换为 CSV 文件 - How do i send webhook data and turn it into a CSV file 我的 Querysnapshot Map 字符串变成 AsyncSnapshot<object> 没有理由<div id="text_translate"><p>我有一个 streamBuilder,其中“snapshots()”从Stream<QuerySnapshot<Map<String, dynamic>>>更改为AsyncSnapshot<Object?> 。 这很奇怪,因为我有另一个应用程序,具有相同的代码并且工作正常。 问题是,我无法访问“snapshot.data.docs”和所有 firestore 数据。 为什么会发生?</p><p> 我的代码:</p><pre> body: StreamBuilder( //Stream<QuerySnapshot<Map<String, dynamic>>> stream: firestore.collection('Books').orderBy('name').snapshots(), //AsyncSnapshot<Object?> builder: (context, snapshot ) { if (snapshot.connectionState == ConnectionState.waiting) return Center(child: CircularProgressIndicator()); { final document = snapshot.data?; //error here return ListView.builder( itemCount: document?.length, itemBuilder: (context, index) { return Column(</pre></div></object> - my Querysnapshot Map String become AsyncSnapshot<Object> with no reason Flutter Fire Type cast AsyncSnapshot <querysnapshot<map<string, dynamic> >> 列表<dynamic> ? </dynamic></querysnapshot<map<string,> - Flutter Fire Type cast AsyncSnapshot<QuerySnapShot<Map<String, dynamic>>> to List<dynamic>? Terraform 输出:如何创建(地图?)以及如何使用 map? map 是正确的工具吗? - Terraform Outputs: How do I create a (map?) and how do I use the map? Is a map even the right tool? 如何在不覆盖整个 Map 的情况下将新的 Map 条目添加到 Map? - How do I add a new Map entry to a Map without overwriting the entire Map? 如何将用户的 Firestore Map 读取为 Swift 字典? - How do I read a User's Firestore Map to a Swift Dictionary? 如何在 React 中使用 Map function 渲染 Firestore 集合? - How do I render Firestore collection using the Map function in React? 我如何在 useEffect 挂钩中从 firestore 数据库获取 map 数据 - How can I map data from a firestore database in a useEffect hook 如何正确获取map数据? - How to properly map data? map如何通过这个数据? 错误提示“无法读取未定义的属性‘map’” - How can I map through this data? Error says 'Cannot read property 'map' of undefined'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM