rxdart

StreamBuilder receives only last item from stream

微笑、不失礼 提交于 2019-12-11 07:51:56
问题 My ApplicationBloc is the root of the widget tree. In the bloc's constructor I'm listening to a stream from a repository that contains models decoded from JSON and forwarding them to another stream which is listened to by StreamBuilder. I expected that StreamBuilder would receive models one by one and add them to AnimatedList. But there's the problem: StreamBuilder's builder fires only once with the last item in the stream. For example, several models lay in the local storage with ids 0, 1, 2

How to show different Widget when user is offline while using StreamBuilder?

拈花ヽ惹草 提交于 2019-12-10 17:48:05
问题 I am trying to fetch some data from the internet. With the use of FutureBuilder , handling for various cases like offline, online,error is quite easy but I am using StreamBuilder and I am not able to understand how to handle offline case Following is my code to use StreamBuilder which works but I have not handled offline data or error return StreamBuilder( builder: (context, AsyncSnapshot<SchoolListModel> snapshot) { if (snapshot.hasError) { return Expanded( child: Center( child: Text

Flutter merge two firestore streams into a single stream

眉间皱痕 提交于 2019-12-06 11:09:21
问题 I simply want to perform an 'OR' operation and get the both results of two queries into one stream. Here's my code with a single stream StreamBuilder( stream: Firestore.instance .collection('list') .where('id', isEqualTo: 'false') .orderBy('timestamp') .snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) return Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Center( child: CircularProgressIndicator(), ) ], ); if (snapshot.data.documents.length == 0)

Flutter merge two firestore streams into a single stream

送分小仙女□ 提交于 2019-12-04 17:48:23
I simply want to perform an 'OR' operation and get the both results of two queries into one stream. Here's my code with a single stream StreamBuilder( stream: Firestore.instance .collection('list') .where('id', isEqualTo: 'false') .orderBy('timestamp') .snapshots(), builder: (context, snapshot) { if (!snapshot.hasData) return Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Center( child: CircularProgressIndicator(), ) ], ); if (snapshot.data.documents.length == 0) return const Center( child: Text( "Not Available", style: TextStyle(fontSize: 30.0, color: Colors.grey), )

Bad state: You cannot close the subject while items are being added from addStream in flutter

好久不见. 提交于 2019-12-04 14:47:52
I am using RxDart to observe changes and update the UI accordingly. When the app launches I am making a network call and successfully getting the data, observe the changes and update the UI accordingly. But when I am disposing the Subjects while closing the screen. Its giving following error: ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ I/flutter (15524): The following StateError was thrown while finalizing the widget tree: I/flutter (15524): Bad state: You cannot close the subject while items are being added from addStream Here is the

Merge Firestore streams using rxDart

纵然是瞬间 提交于 2019-12-02 14:53:14
问题 I am trying to merge two streams from Firestore into one stream using RxDart, but it's only returning results of one stream Stream getData() { Stream stream1 = Firestore.instance.collection('test').where('type', isEqualTo: 'type1').snapshots(); Stream stream2 = Firestore.instance.collection('test').where('type', isEqualTo: 'type2').snapshots(); return Observable.merge(([stream2, stream1])); } 回答1: Depending on your use case, you might not need RxDart to do this. If you just want to have two

Navigating to a new screen when stream value in BLOC changes

蹲街弑〆低调 提交于 2019-11-28 06:04:27
In Flutter how would I call Navigator.push when the value of a stream changes? I have tried the code below but get an error. StreamBuilder( stream: bloc.streamValue, builder: (BuildContext context, AsyncSnapshot<int> snapshot) { if (snapshot.hasData && snapshot.data == 1) { Navigator.push( context, MaterialPageRoute(builder: (context) => SomeNewScreen()), ); } return Text(""); }); You should not use StreamBuilder to handle navigation. StreamBuilder is used to build the content of a screen and nothing else. Instead, you will have to listen to the stream to trigger side-effects manually. This is

Navigating to a new screen when stream value in BLOC changes

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-27 00:48:10
问题 In Flutter how would I call Navigator.push when the value of a stream changes? I have tried the code below but get an error. StreamBuilder( stream: bloc.streamValue, builder: (BuildContext context, AsyncSnapshot<int> snapshot) { if (snapshot.hasData && snapshot.data == 1) { Navigator.push( context, MaterialPageRoute(builder: (context) => SomeNewScreen()), ); } return Text(""); }); 回答1: You should not use StreamBuilder to handle navigation. StreamBuilder is used to build the content of a