Я создаю приложение для постов и комментариев. Когда я пишу комментарий в поле для сообщения c, текст применяется ко всем правам в других сообщениях.
Я использую Stream Builder для отображения сообщений в FireStore, я новичок во флаттере, может кто угодно дайте мне решение?
Я прикрепил ниже полную функцию Stream Builder, вы можете увидеть ее, чтобы определить проблему.
StreamBuilder(
stream: Firestore.instance.collection('Majors').document(majname).collection('Posts').snapshots(),
builder: (context, snapshot){
if(!snapshot.hasData)
{
const Text('Loading...');
}
else{
return ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
scrollDirection: Axis.vertical,
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index)
{
DocumentSnapshot mypost = snapshot.data.documents[index];
return Stack(
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 8.0,bottom: 8.0),
child: Container(
decoration: BoxDecoration(borderRadius:
BorderRadius.circular(15.0),color: Colors.white,boxShadow: [
BoxShadow(
color: Colors.black,
blurRadius: 25.0, // soften the shadow
spreadRadius: -10.0, //extend the shadow
)
],),
child: Container(
decoration: BoxDecoration(borderRadius:
BorderRadius.circular(15.0)),
child: Padding(
padding: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
SizedBox(height: 10.0,),
Container(
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(width: 5.0,),
Container(
width: 40.0,
height: 40.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.fill,
image: NetworkImage(
// user image url
'${mypost['uimg']}')
)
)),
SizedBox(width: 10.0,),
Text('${mypost['uname']}',style: TextStyle(fontSize: 14.0,fontWeight: FontWeight.bold),),
],
),
),
SizedBox(height: 20.0,),
Text('${mypost['text']}',style: TextStyle(fontSize: 16.0)),
SizedBox(height: 15.0,),
Visibility(
child: Text('${mypost['pid']}',style: TextStyle(fontSize: 16.0,fontWeight: FontWeight.bold,color: Colors.blueGrey),),
visible: false,
),
Visibility (
visible: _isVisible,
child:Image.network('${mypost['img']}' != null ? '${mypost['img']}' : showToast,
fit: BoxFit.fill,),
),
SizedBox(height: 15.0,),
Container(
padding: EdgeInsets.all(10.0),
decoration: BoxDecoration(borderRadius:
BorderRadius.circular(15.0),color: Color.fromRGBO(28, 10, 66, 1),),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(
height: 50,
width: 200,
// My Field !!!
child: TextField(
controller: commentTextField,
onChanged: (val) {
setState(() => commentText = val);
},
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
hintText: 'Write your comment',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0))),
),
),
SizedBox(width: 10,),
Container(
width: 50.0,
height: 50.0,
child: FlatButton(
padding: EdgeInsets.all(5.0),
child: Container(
width: 50.0,
height: 50.0,
decoration: BoxDecoration(
gradient: LinearGradient(colors: [Colors.deepPurple, Colors.purple],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
borderRadius: BorderRadius.circular(10.0)
),
child: Icon(Icons.send,color: Colors.white,),
),
onPressed: () async {
print('${mypost['pid']}');
/*
if (commentText == null || commentText == '' || commentText.contains(" "))
{
showWraning('You cannot publish a comment without text.');
}
else {
submitComment(mypost['pid'].toString(),context);
}
*/
},
),
),
],
),
),
],
),
),
),
),
),
],
);
}
);
}
return Container(
height: 0.0,
width: 0.0,
);
},
),