ConnectionState always waiting in StreamBuilder

345 views
Skip to first unread message

Tony Seng

unread,
Jan 11, 2020, 9:10:34 AM1/11/20
to Flutter Development (flutter-dev)
I using Bloc pattern in my flutter project. In MainPage, I will add List<HashMap<int,ABC>> into list.

var list = List<HashMap<int, ABC>>();
var hashMap = HashMap<int, ABC>();
var groupedList =
groupBy(listOfAbc, (ABC item) => item.id); // group by id

for (var key in groupedList.keys) {
for (var value in groupedList[key]) {
if ((value.notification_type == "abc")) {
setState(() {
hashMap[key] = value;
list.add(hashMap);
_abcBloc.abcSink.add(list);
});
}
}
}
After that I will display the stream in pageB.

return StreamBuilder<List<HashMap<int, ABC>>>(
stream: _abcBloc.abcStream,
builder: (context, snapshotData) {
switch (snapshotData.connectionState) {
case ConnectionState.active:
return Text(snapshotData.data.toString());
break;

case ConnectionState.waiting:
return Text("Waiting");
break;

default:
return Text("error");
}
});
If the list is not equal to zero, I can see Text(snapshotData.data.toString()) display on UI. But if the list is zero, the UI is displayed waiting. How can I fix it? Why it is always in ConnectionState.waiting: if there are nothing add into sink ?

Bloc

final _abc = BehaviorSubject<List<HashMap<int, ABC>>>();
get abcSink => _abc.sink;
get abcStream => _abc.stream;

Reply all
Reply to author
Forward
0 new messages