简体   繁体   English

相关的导致错误的小部件是 StreamBuilder <querysnapshot<object?> &gt; </querysnapshot<object?>

[英]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.

相关问题 Flutter StreamBuilder小部件错误:类型'()=&gt; Map<string, dynamic> ' 不是类型 'DocumentSnapshot 的子类型<object?> ' 在类型转换中</object?></string,> - Flutter StreamBuilder widget Error : type ' () => Map<String, dynamic >' is not a subtype of type 'DocumentSnapshot<Object?>' in type cast Flutter 错误:参数类型 'QuerySnapshot<object?> ' 不能分配给参数类型 'Recipe'</object?> - Flutter error: The argument type 'QuerySnapshot<Object?>' can't be assigned to the parameter type 'Recipe' 'Future 类型的值<querysnapshot<map<string, dynamic> &gt;&gt;' 不能分配给“QuerySnapshot”类型的变量<object?> ' </object?></querysnapshot<map<string,> - A value of type 'Future<QuerySnapshot<Map<String, dynamic>>>' can't be assigned to a variable of type 'QuerySnapshot<Object?>' 没有为类型“QuerySnapshot”定义吸气剂“文档”<object?> '</object?> - The getter 'documents' isn't defined for the type 'QuerySnapshot<Object?>' 如何在 Flutter 中将 Firebase 实时数据库读取为“字符串”(没有 Widget,streambuilder)? - How to read Firebase realtime database as "string"(without Widget, streambuilder) in Flutter? Flutter 云Firestore StreamBuilder<documentsnapshot> 错误</documentsnapshot> - Flutter cloud firestore StreamBuilder<DocumentSnapshot> error Streambuilder 空错误。 变量返回 Null - Streambuilder Null Error. Variable returning Null 未为类型“QuerySnapshot”定义运算符“[]”<object?> ' 尝试定义运算符 '[]' - Flutter</object?> - The operator '[]' isn't defined for the type 'QuerySnapshot<Object?>' Try defining the operator '[]' - Flutter 输入“未来” <querysnapshot<map<string, dynamic> >>' 不是类型 'DocumentSnapshot' 的子类型<object?> ' 在类型转换中</object?></querysnapshot<map<string,> - Type 'Future<QuerySnapshot<Map<String, dynamic>>>' is not a subtype of type 'DocumentSnapshot<Object?>' in type cast Flutter:查询firebase实时数据库数据列表,streambuilder出错 - Flutter: querying firebase realtime database data list with streambuilder error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM