'Firebase updates doesn't change in screen (flutter)
in my project, i have a button that will change some value from firebase, what i am facing is that although i am using setState and futureBuilder, the changes doesn't really appear until i do a hot restart, what's the issue?
code:
Center(
child:
snapshot.data.docs[i].data()['isWatched'] == false?
IconButton(
onPressed: () {
setState(() async{
await watchLaterRef.doc(documentId).update({
'isWatched': true
});
});
},
icon: Icon(
Icons.check_box,
size: 50,
color: Colors.yellow,
))
:
IconButton(
onPressed: () {
setState(() async{
await watchLaterRef.doc(documentId).update({
'isWatched': false
});
});
},
icon: Icon(
Icons.check_box,
size: 50,
color: Colors.green,
))
)
Solution 1:[1]
Basically, you can't use async
and await
with setState
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | ouflak |