Reputation: 21
I'm populating a ListView from Streambuilder and want to show the length/nr of documents in the AppBar title. Right now I'm calling SetState everytime there's a change in the stream. It works but "feels" kinda resource heavy. Any ideas?
Thanks in advance.
Best, /j
StreamBuilder(
stream: Firestore.instance.collection('users').snapshots(),
builder: (context, snapshot) {
if (!snapshot.hasData) return const Text('Loading...');
appBarTitle = snapshot.data.documents.length;
Future.delayed(Duration.zero, () {
setState(() {
});
});
},
);
Upvotes: 2
Views: 2069
Reputation: 61
you can wrap title of appBar with Stream builder to update your screen title like this code
AppBar(title: StreamBuilder<Object>(
stream: bloc.myStream,
builder: (context, snapshot) {
return yourCustomWidget();
}
)
Upvotes: 3