英文:
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: () => Map<String, dynamic> from Function 'data':.
Tried calling: 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,
),
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<String, dynamic>;
And then, convert this Map<String, dynamic> data to List.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论