NoSuchMethodError (NoSuchMethodError: Closure call with mismatched arguments: function '\[\]' Receiver: Closure: () =\> Map\<String, dynami….)

huangapple go评论62阅读模式
英文:

NoSuchMethodError (NoSuchMethodError: Closure call with mismatched arguments: function '\[\]' Receiver: Closure: () =\> Map\<String, dynami....)

问题

我无法解决我的应用程序中出现的异常:出现异常。
NoSuchMethodError(NoSuchMethodError:使用不匹配的参数调用闭包:函数'[]'
接收器:Closure:()=> Map<String,dynamic> from Function'data':。
尝试调用:Found:=> Map<String,dynamic>)

GridView.builder(
    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
        crossAxisCount: 3),
    itemBuilder: (context, index) {
        var ourData = snapshot.data[index];

        return Card(
            elevation: 10.0,
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(20.0)),
            child: ClipRRect(
                borderRadius: BorderRadius.circular(20),
                child:
                    Image.network(ourData.data['img'], fit: BoxFit.cover),
            ),
        );
    },
    itemCount: snapshot.data.length,
),

提前感谢您的帮助。

我希望我的Cloud Firestore中存储的图像能够加载到页面上。

英文:

I am unable to solve this exception that appeared in my application: An exception occurred.
NoSuchMethodError (NoSuchMethodError: Closure call with mismatched arguments: function '[]'
Receiver: Closure: () =&gt; Map&lt;String, dynamic&gt; from Function 'data':.
Tried calling: Found: =&gt; Map&lt;String, dynamic&gt;)

GridView.builder(
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 3),
                itemBuilder: (context, index) {
                  var ourData = snapshot.data[index];

                  return Card(
                    elevation: 10.0,
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(20.0)),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(20),
                      child:
                          Image.network(ourData.data[&#39;img&#39;], fit: BoxFit.cover),
                    ),
                  );
                },
                itemCount: snapshot.data.length,
              ),

Thank you in advance for your help.

I hope that the images stored in my Cloud Firestore will load on the page.

答案1

得分: 1

我不知道你的数据结构是什么样的。但我认为它不是一个List,而是一个Map<String, dynamic>。

所以,如果你想从FireStore获取数据,尝试这样做。

// 根据你的条件更改ref。
final snapshot = await ref.get();
final data = snapshot.data() as Map<String, dynamic>;

然后,将这个Map<String, dynamic>数据转换成List。

英文:

I don't know what your data structure is like. But, I think it's not a List but a Map<String, dynamic>.

So, if you want to get the data from FireStore, try this.

// Change ref to suit your conditions.
final snapshot = await ref.get();
final data = snapshot.data() as Map&lt;String, dynamic&gt;;

And then, convert this Map<String, dynamic> data to List.

huangapple
  • 本文由 发表于 2023年6月29日 21:35:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/76581565.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定