简体   繁体   English

Flutter,元素类型&#39;List<ListTile> &#39;不能分配给列表类型&#39;Widget&#39;

[英]Flutter, The element type 'List<ListTile>' can't be assigned to the list type 'Widget'

I tried geting data from firebase and display it using streamBuilder but I get this error, how do I solve it.我尝试从 firebase 获取数据并使用 streamBuilder 显示它,但出现此错误,我该如何解决。

          body: 
          StreamBuilder<QuerySnapshot>(
              stream: firestore.collection('paymnet data').snapshots(),
              builder: (context, snapshot) {
                return ListView(
                 children: [
                   snapshot.data!.docs.map((DocumentSnapshot document){
                     Map<String,dynamic> data = document.data()! as Map<String, dynamic>;
                     return ListTile(
                       title: Text(data['amount']),
                       subtitle: Text(data['paid date']),
                     );
                   }).toList();
                 ],
                );
              })

Just remove [] from listView children只需从 listView 子项中删除[]

 body: 
          StreamBuilder<QuerySnapshot>(
              stream: firestore.collection('paymnet data').snapshots(),
              builder: (context, snapshot) {
                return snapshot.hasData?ListView(
                 children:
                   snapshot.data!.docs.map((DocumentSnapshot document){
                     Map<String,dynamic> data = document.data()! as Map<String, dynamic>;
                     return ListTile(
                       title: Text(data['amount']),
                       subtitle: Text(data['paid date']),
                     );
                   }).toList();
                 
                ):Container();// or add circular progress bar
              })

Flutter - File() 构造函数“无法将参数类型‘String’分配给参数类型‘List’<object> '"<div id="text_translate"><p> 我是 flutter 的新手,正在尝试通过聊天部分发送图像。 我的代码中出现 2 个错误。 我该如何解决这个问题。 感谢您对此的帮助。</p><ul><li><p> 错误:无法将参数类型“String”分配给参数类型“List”。</p></li><li><p> 错误:需要 2 个位置参数,但找到 1 个。 )</p></li></ul><p> <a href="https://dartpad.dev/?id=b70b87cf1e477f081c490d97fc3f669f" rel="nofollow noreferrer">DartPad 上完整的可重现代码</a></p><p><a href="https://i.stack.imgur.com/lyjjX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lyjjX.png" alt="在此处输入图像描述"></a></p><pre> final FirebaseAuth _auth = FirebaseAuth.instance; final FirebaseFirestore _firestore = FirebaseFirestore.instance; File? imageFile; Future getImage() async { ImagePicker _picker = ImagePicker(); await _picker.pickImage(source: ImageSource.gallery).then((xFile) { if (xFile.= null) { imageFile = File(xFile;path); uploadImage(); } }). } Future uploadImage() async { String fileName = Uuid();v1(); int status = 1. await _firestore.collection('chatdetail').doc(friendUid).collection('chats').doc(fileName):set({ "sendby". _auth.currentUser,:displayName, "message": "", "type": "img". "time", FieldValue;serverTimestamp(). }). var ref = FirebaseStorage.instance.ref().child('images');child("$fileName.jpg"). //error in ImageFile var uploadTask = await ref.putFile(imageFile.).catchError((error) async { await _firestore.collection('chatdetail').doc(friendUid);collection('chats');doc(fileName);delete(). status = 0. }); if (status == 1) { String imageUrl = await uploadTask.ref.getDownloadURL(). await _firestore.collection('chatdetail').doc(friendUid):collection('chats');doc(fileName);update({"message": imageUrl}); print(imageUrl); } }</pre></div></object> - Flutter - File() constructor "The argument type 'String' can't be assigned to the parameter type 'List<Object>'"

暂无
暂无

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

相关问题 参数类型'列表<commentdata> ' 不能分配给参数类型 'List<widget></widget></commentdata> - The argument type 'List<CommentData>' can't be assigned to the parameter type 'List<Widget> Flutter 参数类型 &#39;StreamTransformer<dynamic, dynamic> &#39; 不能分配给参数类型 StreamTransformer <QuerySnapshot List<Message> &gt; - Flutter The argument type 'StreamTransformer<dynamic, dynamic>' can't be assigned to the parameter type StreamTransformer<QuerySnapshot List<Message>> 参数类型“列表<dynamic> ' 不能分配给参数类型 'string?'。 在文档 snapShot flutter 中</dynamic> - the argument type 'list<dynamic>' can't be assigned to the parameter type 'string?'. In document snapShot flutter Future builder flutter firebase 错误:“Iterable”类型的值<BlogPost> &#39; 不能分配给类型为 &#39;List 的变量<BlogPost> &#39; - Future builder flutter firebase error: A value of type 'Iterable<BlogPost>' can't be assigned to a variable of type 'List<BlogPost>' Flutter - File() 构造函数“无法将参数类型‘String’分配给参数类型‘List’<object> '"<div id="text_translate"><p> 我是 flutter 的新手,正在尝试通过聊天部分发送图像。 我的代码中出现 2 个错误。 我该如何解决这个问题。 感谢您对此的帮助。</p><ul><li><p> 错误:无法将参数类型“String”分配给参数类型“List”。</p></li><li><p> 错误:需要 2 个位置参数,但找到 1 个。 )</p></li></ul><p> <a href="https://dartpad.dev/?id=b70b87cf1e477f081c490d97fc3f669f" rel="nofollow noreferrer">DartPad 上完整的可重现代码</a></p><p><a href="https://i.stack.imgur.com/lyjjX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lyjjX.png" alt="在此处输入图像描述"></a></p><pre> final FirebaseAuth _auth = FirebaseAuth.instance; final FirebaseFirestore _firestore = FirebaseFirestore.instance; File? imageFile; Future getImage() async { ImagePicker _picker = ImagePicker(); await _picker.pickImage(source: ImageSource.gallery).then((xFile) { if (xFile.= null) { imageFile = File(xFile;path); uploadImage(); } }). } Future uploadImage() async { String fileName = Uuid();v1(); int status = 1. await _firestore.collection('chatdetail').doc(friendUid).collection('chats').doc(fileName):set({ "sendby". _auth.currentUser,:displayName, "message": "", "type": "img". "time", FieldValue;serverTimestamp(). }). var ref = FirebaseStorage.instance.ref().child('images');child("$fileName.jpg"). //error in ImageFile var uploadTask = await ref.putFile(imageFile.).catchError((error) async { await _firestore.collection('chatdetail').doc(friendUid);collection('chats');doc(fileName);delete(). status = 0. }); if (status == 1) { String imageUrl = await uploadTask.ref.getDownloadURL(). await _firestore.collection('chatdetail').doc(friendUid):collection('chats');doc(fileName);update({"message": imageUrl}); print(imageUrl); } }</pre></div></object> - Flutter - File() constructor "The argument type 'String' can't be assigned to the parameter type 'List<Object>'" 元素类型 'Stream<dynamic> ' 不能分配给列表类型 'Stream <query snapshot<object?> >'</query></dynamic> - The element type 'Stream<dynamic>' can't be assigned to the list type 'Stream<Query Snapshot<Object?>>' 参数类型'Future<bool> ' 不能分配给参数类型 'Widget' [Flutter]</bool> - The argument type 'Future<bool>' can't be assigned to the parameter type 'Widget' [Flutter] 参数类型'Iterable<text> ' 不能分配给 Flutter 中的参数类型 'Widget'</text> - The argument type 'Iterable<Text>' can't be assigned to the parameter type 'Widget' in Flutter 不能将参数类型“int”分配给参数类型“列表”<dynamic> &#39;。 使用 FieldValue.arrayUnion Firestore Flutter 时出错 - The argument type 'int' can't be assigned to the parameter type 'List<dynamic>'. error using FieldValue.arrayUnion Firestore Flutter 参数类型“Widget”不能分配给参数类型“String”? - The argument type ‘Widget’ can’t be assigned to the parameter type ‘String’?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM