Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
StreamBuilder does not update state
Post Flair (click to view more posts with a particular flair)
Post Body

I have a StreamBuilder that is for a firestore.

I have a button in a different page that is saving item prices into firestore. My StreamBuilder is for the total price of these items.

return Scaffold(
appBar: PreferredSize(
child: AppBar(
elevation: 0,
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
title: Center(child: Text('Main page')),
),
preferredSize: Size.fromHeight(30),
),
body: StreamBuilder(
stream: FirestoreAPI.getTotalUnpaid(currentUser),
builder: (BuildContext context, AsyncSnapshot snapshot) {
switch (snapshot.connectionState) {
case ConnectionState.waiting:
return Center(
child: CircularProgressIndicator(),
);
default:
if (snapshot.hasError)
return Center(child: Text(snapshot.error.toString()));
else {
return Center(
child: Text(
snapshot.data['total'].toString(),
style: style,
),
);
}
}
},
),
);

The StreamBuilder should keep showing the value of the 'total' field every time it changes.

However, it only updates it after I hot reload the app. Why?

Should I be calling setState somewhere?

Also, can this be resolved by didUpdateWidget?

I have a somewhat similar problem elsewhere where the streambuilder does not update the first time only. But works fine after that.

Author
Account Strength
90%
Account Age
8 years
Verified Email
Yes
Verified Flair
No
Total Karma
3,352
Link Karma
759
Comment Karma
2,442
Profile updated: 5 days ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
4 years ago