【问题标题】:I can not get messages in firestore (closed)我无法在 Firestore 中收到消息(已关闭)
【发布时间】:2021-03-20 16:59:21
【问题描述】:

我有一个流生成器和流。 我想当我点击提交按钮时,我会看到用户发送的消息(现在只有我)。 怎么了?为什么我在屏幕上看不到我的消息?帮助...

这是我的 alertdialog 按钮,它有 textformfield,用户可以使用它并发送消息。

 Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: RaisedButton(
                    child: Text("Submit"),
                    onPressed: () {
                    
                      FirebaseFirestore.instance.collection('messages').doc(FirebaseAuth.instance.currentUser.uid).set({
                         'message' : alertDialogText,
                      'timestamp' : DateTime.now()
                      });

                    },
                  ),
                )

这里是我想在我的卡片中获取消息的部分

 class HomeScreenUI extends StatelessWidget {
      @override
      Widget build(BuildContext context) {
        return Consumer<FirestoreAuthentication>(
          builder: (context, fsAuth, child) {
              return StreamBuilder<QuerySnapshot>(
            stream: fsAuth.firestore.collection('messages').snapshots(),
            builder: (context, snapshot) {
              if (!snapshot.hasData) return CircularProgressIndicator();
              return ListView.builder(
                    itemCount: snapshot.data.docs.length,
                      itemBuilder: (context, index) {
                        return Card(...)

卡有用户发送的消息:

                          Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            Center(
                                child: Padding(
                              padding: const EdgeInsets.only(
                                  right: 8.0, top: 11.0),
                              child: Text(
                                "Message from user but for now it's string",
                                style: const TextStyle(
                                    color: Colors.black54, fontSize: 13),
                              ),
                            )),
                          ],
                        ),
)

最后在我的 Firestore 中截屏(如果我发送消息它会转到这里):

【问题讨论】:

  • 不要粘贴截图。编写代码更适合得到答案。
  • @Akif 我刚刚编辑了我的问题,我会等待答案。谢谢。

标签: firebase flutter dart google-cloud-firestore firebase-authentication


【解决方案1】:

在您的卡片中,您从字段中访问数据有误。我看到您尝试从字段“mesaj”而不是字段“message”获取数据,这就是为什么您会收到文本“字段不存在”的错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-23
    • 2019-11-15
    • 2022-08-11
    • 1970-01-01
    • 2020-11-04
    • 2014-08-21
    相关资源
    最近更新 更多