flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.62k stars 27.34k forks source link

ConnectionState always waiting in StreamBuilder #48633

Closed tony123S closed 4 years ago

tony123S commented 4 years ago

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;
iapicca commented 4 years ago

Hi @tony123S can you please provide your flutter doctor -v and a reproducible minimal code sample that does not involve 3rd party packages Thank you

iampawan commented 4 years ago

Yes that's an issue with me too on Flutter Dev v1.15.2

no-response[bot] commented 4 years ago

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away! Thanks for your contribution.

iapicca commented 4 years ago

Hi @iampawan can you please provide your flutter run --verbose and if possible a reproducible minimal code sample. Thank you

TahaTesser commented 4 years ago

Hi @tony123S

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. Please don't hesitate to comment on the bug if you have any more information for us; we will reopen it right away!
Thanks for your contribution.

github-actions[bot] commented 3 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.