Flutter stream builders concept
306
You should be able to filter for specific events using where
:
stream: dataBloc.dataStream.where((item) => /* check criteria */ item['key'] == 'foo')
Comments
-
GoPro over 1 year
I have a map in which i store key and value pair. I have put this map in a stream, which we will call dataStream for ease.
now i have a stream builder, this stream-builder uses dataStream. I want this stream builder to build only if a specific key's value is altered.
Currently my stream builder responds to any change in the map. I want to instruct it to change only when a certain key's value in the map changes. Is this possible in stream builder and how?
return StreamBuilder( stream: dataBloc.dataStream, builder: (context, snapshot) { if(snapshot.hasData){ Map<String, String> dataMap = snapshot.data; // some logic } return widget; }
I want to see if a specific key's value in this map changes, only then rebuild my existing widget else, leave it as it is. Do not build it again
-
GoPro over 5 yearsDo i access the map which is inside my dataStream using snapshot.data ? I am not sure how to access it in the where clause;
-
Günter Zöchbauer over 5 yearsI see. Didn't recognize this is about Firebase.
item
is the same whatsnapshot.data
returns inbuilder: ...
-
GoPro over 5 yearsI have one more question, what happens if my where clause is false; Will it rebuild? Ideally i want it to rebuild if there is a change in the output of the where clause!
-
GoPro over 5 yearsfor example, if the condition is satisfied build, if it is not satisfied build but differently.
-
Günter Zöchbauer over 5 yearsIf the where clause is false, the event will be filtered and not passed to the listener (StreamBuilder), so no, it's as if the event were never sent.
-
Günter Zöchbauer over 5 years"if there is a change in the output of the where clause!" sorry, but I don't understand what that means.
-
GoPro over 5 yearsLet us continue this discussion in chat.