Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another exception was thrown: Bad state: No element #6

Open
SoftDevCHD opened this issue Apr 16, 2022 · 2 comments
Open

Another exception was thrown: Bad state: No element #6

SoftDevCHD opened this issue Apr 16, 2022 · 2 comments

Comments

@SoftDevCHD
Copy link

I am getting this when I swap between screens that use ChannelListView with different filters. It is as if stream returns the last reference to a channel list before applying the new filters. For example, I am in my direct messages, I display a set of channels with a certain filter, then I leave the page to go on a different page that has a ChannelListView. I will get a red screen error, then after a second, the error goes away and the proper widget is shown. The issue I am seeing is twofold, when I go to direct messages, the previous ChannelListView is shown for a second, then updates, and when I go to the other screen, I get red screen error.
Here is the widget in one screen (Direct Messages)

Expanded(
              child: ChannelListView(
                
                filter: Filter.and(
                  [
                    Filter.equal('type', 'messaging'),
                    Filter.in_(
                      'members',
                      [
                        StreamChat.of(context).currentUser!.id,
                      ],
                    ),
                    Filter.equal('event', false),
                  ],
                ),
                emptyBuilder: (context) => noMessages(),
                errorBuilder: (context, error) => MessagesError(
                  error: error,
                ),
                loadingBuilder: (BuildContext context) =>
                    const Center(child: CircularProgressIndicator()),
                listBuilder: (context, channels) => ListView.builder(
                  itemCount: channels.length,
                  itemBuilder: (BuildContext context, int index) =>
                      ChannelTile(channel: channels[index], uid: uid),
                ),
              ),
            ),

Here is the widget in the other screen

return stream.ChannelListView(
              filter: stream.Filter.raw(
                value: {
                  'cid': {
                    r'$in': events.map((e) => "messaging:${e.eid}").toList(),
                  },
                  'event': true,
                  'type': 'messaging',
                },
              ),
              loadingBuilder: (BuildContext context) =>
                  const Center(child: CircularProgressIndicator()),
              emptyBuilder: (context) => noHostedEvents(),
              errorBuilder: (context, error) => MessagesError(
                error: error,
              ),
              listBuilder: (context, channels) {
                return ListView.builder(
                  itemCount: channels.length,
                  itemBuilder: (BuildContext context, int index) =>
                      EventChannelTile(
                    algoliaEvent: events.firstWhere(
                      (element) => element.eid == channels[index].id,
                    ),
                    channel: channels[index],
                  ),
                );
              },
            );
@HayesGordon
Copy link
Owner

Hi, are you still experiencing this issue?

@SoftDevCHD
Copy link
Author

No, I have found a workaround, so everything is fine for now haha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants