![](/img/trans.png)
[英]Get data from Firebase (Real Time Database) Flutter using StreamBuilder
[英]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(),),
你的代码有错误的实现。
_firestore.collection('admin').doc({DOCID}).snapshots()
检查颤振火灾文档以获得正确的实施
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.