[英]The relevant error-causing widget was StreamBuilder<QuerySnapshot<Object?>>
I am trying to find the solution for this error, help?我正在尝试找到此错误的解决方案,帮助? how can i solve this: i use this to make a chat app using firebase ════════ Exception caught by widgets library ═══════════════════════════════════ Bad state?
我该如何解决这个问题:我用它来使用 firebase ════════ 小部件库捕获的异常═════════════════════════════════════════════ ══════════════ 坏 state? field does not exist within the DocumentSnapshotPlatform The relevant error-causing widget was StreamBuilder<QuerySnapshot<Object?>>
DocumentSnapshotPlatform 中不存在字段相关的导致错误的小部件是 StreamBuilder<QuerySnapshot<Object?>>
import 'package:chat_app/Widgets/chat_bubble.dart';
import 'package:chat_app/constant.dart';
import 'package:flutter/src/foundation/key.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import '../models/message.dart';
class ChatPage extends StatelessWidget {
static String id = 'ChatPage';
CollectionReference messages =
FirebaseFirestore.instance.collection(KMessagesCollection);
TextEditingController controller = TextEditingController();
@override
Widget build(BuildContext context) {
return StreamBuilder<QuerySnapshot>(
stream: messages.snapshots(),
builder: ((context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (snapshot.hasData) {
List<Message> messagesList = [];
for (int i = 0; i < snapshot.data!.docs.length; i++) {
messagesList.add(Message.fromJason(snapshot.data!.docs[i]));
}
return Scaffold(
appBar: AppBar(
automaticallyImplyLeading: false,
backgroundColor: kPrimaryColor,
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: const EdgeInsets.all(5.0),
child: CircleAvatar(
backgroundColor: Colors.white,
child: Image.asset(
Klogo,
height: 50,
),
),
),
Text('Chat'),
],
),
centerTitle: true,
),
body: Container(
child: Column(
children: [
Expanded(
child: ListView.builder(
itemCount: messagesList.length,
itemBuilder: (context, index) {
return ChatBubble(
message: messagesList[index],
);
}),
),
Padding(
padding: const EdgeInsets.all(16),
child: TextField(
controller: controller,
onSubmitted: (data) {
messages.add({
'message': data,
});
controller.clear();
},
decoration: InputDecoration(
hintText: 'Send Message',
suffixIcon: Icon(
Icons.send,
color: kPrimaryColor,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(16),
borderSide: BorderSide(color: kPrimaryColor),
),
),
),
),
],
),
));
} else {
return Text('Loading...');
}
}),
);
}
}
This error might occur inside the Message.fromJson() constructor.此错误可能发生在 Message.fromJson() 构造函数中。 There might be a field you forgot or a typo.
可能存在您忘记的字段或错字。 Check if all fields in the constructor match your fields in Firebase exactely.
检查构造函数中的所有字段是否与 Firebase 中的字段完全匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.