Another exception was thrown: Bad state: No element
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],
),
);
},
);
Hi, are you still experiencing this issue?
No, I have found a workaround, so everything is fine for now haha.