簡體   English   中英

實時顫動流構建器

[英]flutter streambuilder in real time

實時顫動應用程序流構建器這是群聊應用程序我需要實時從firebase firestore獲取布爾聊天值,如果真或假沒有退出頁面並重新打開以更新值或任何阻止用戶發送消息的方式當 Chat 的值等於 False 時的組這是我的代碼

StreamBuilder(builder: (context, snapshot) {
        if(chat == false){
          return  Container(
              child:
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 30,vertical: 5),
                child: Row(
                  children: [
                    Image.network('https://upload.wikimedia.org/wikipedia/commons/thumb/f/f0/Error.svg/1200px-Error.svg.png',height: 25,width: 25,),
                    SizedBox(width: 20,),
                    Expanded(child: Text('Only admin can send message',style: TextStyle(fontSize: 10),maxLines: 1,overflow: TextOverflow.ellipsis,))
                  ],
                ),
              )
          );
        }else{
          return Padding(
            padding: const EdgeInsets.all(10.0),
            child: Material(
              borderRadius: BorderRadius.circular(50),
              color: ColorConstants.appColor,
              child: Padding(
                padding: const EdgeInsets.only(bottom: 4.0,top: 4.0,left: 1.5,right: 1.5),
                child: Container(
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.circular(50)
                    ),
                    child:
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Expanded(child: TextField(
                          controller: messageedit,
                          onChanged: (value){
                            messageText = value;
                          },
                          decoration: InputDecoration(
                              contentPadding: EdgeInsets.symmetric(
                                  vertical: 10,
                                  horizontal: 20
                              ),
                              hintText: 'Write your message .... ',
                              border: InputBorder.none
                          ),
                        )),
                        IconButton(onPressed: ()  {
                          messageedit.clear();
                          _firestore.collection("messages").add({
                            'text': messageText,
                            'sender' : email,
                            'time' : FieldValue.serverTimestamp(),
                          }).whenComplete(() => sendNotification('$messageText', '$email'));
                        }, icon: Icon(Icons.send_rounded,color: ColorConstants.appColor,))
                      ],
                    )
                ),
              ),
            ),
          );
        }
      },stream:  _firestore.collection('admin').doc('admin').snapshots(),),

你的代碼有錯誤的實現。

  1. 提供文檔時,它應該是 firestore 上的 docId ({DOCID}),例如: _firestore.collection('admin').doc({DOCID}).snapshots()
  2. 我不明白你如何創建聊天變量
  3. 我在代碼中的任何地方都看不到您在哪里處理來自 firestore 的快照數據

檢查顫振火災文檔以獲得正確的實施

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM