fix channellistview loading when client is not initialized
This commit is contained in:
@@ -205,8 +205,20 @@ class _ChannelListViewState extends State<ChannelListView>
|
||||
}
|
||||
|
||||
if (!snapshot.hasData) {
|
||||
return Center(
|
||||
child: CircularProgressIndicator(),
|
||||
return LayoutBuilder(
|
||||
builder: (context, viewportConstraints) {
|
||||
return SingleChildScrollView(
|
||||
physics: AlwaysScrollableScrollPhysics(),
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
minHeight: viewportConstraints.maxHeight,
|
||||
),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -374,7 +386,7 @@ class _ChannelListViewState extends State<ChannelListView>
|
||||
filter: widget.filter,
|
||||
sortOptions: widget.sort,
|
||||
paginationParams: widget.pagination.copyWith(
|
||||
offset: channelsProvider.channels.length,
|
||||
offset: channelsProvider.channels?.length ?? 0,
|
||||
),
|
||||
options: widget.options,
|
||||
);
|
||||
@@ -426,7 +438,7 @@ class _ChannelListViewState extends State<ChannelListView>
|
||||
void didUpdateWidget(ChannelListView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
|
||||
if (widget.filter != oldWidget.filter ||
|
||||
if (widget.filter?.toString() != oldWidget.filter?.toString() ||
|
||||
widget.sort != oldWidget.sort ||
|
||||
widget.pagination != oldWidget.pagination ||
|
||||
widget.options != oldWidget.options) {
|
||||
|
||||
+14
-13
@@ -56,8 +56,7 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
||||
final BehaviorSubject<bool> _queryChannelsLoadingController =
|
||||
BehaviorSubject.seeded(false);
|
||||
|
||||
final BehaviorSubject<List<Channel>> _channelsController =
|
||||
BehaviorSubject.seeded([]);
|
||||
final BehaviorSubject<List<Channel>> _channelsController = BehaviorSubject();
|
||||
|
||||
/// The stream notifying the state of queryChannel call
|
||||
Stream<bool> get queryChannelsLoading =>
|
||||
@@ -73,7 +72,10 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
||||
Map<String, dynamic> options,
|
||||
bool onlyOffline = false,
|
||||
}) async {
|
||||
if (_queryChannelsLoadingController.value == true) {
|
||||
final client = StreamChat.of(context).client;
|
||||
|
||||
if (client.state?.user == null ||
|
||||
_queryChannelsLoadingController.value == true) {
|
||||
return;
|
||||
}
|
||||
_queryChannelsLoadingController.sink.add(true);
|
||||
@@ -82,16 +84,15 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
||||
final clear = paginationParams == null ||
|
||||
paginationParams.offset == null ||
|
||||
paginationParams.offset == 0;
|
||||
final oldChannels = List<Channel>.from(channels);
|
||||
StreamChat.of(context)
|
||||
.client
|
||||
final oldChannels = List<Channel>.from(channels ?? []);
|
||||
client
|
||||
.queryChannels(
|
||||
filter: filter,
|
||||
sort: sortOptions,
|
||||
options: options,
|
||||
paginationParams: paginationParams,
|
||||
onlyOffline: onlyOffline,
|
||||
)
|
||||
filter: filter,
|
||||
sort: sortOptions,
|
||||
options: options,
|
||||
paginationParams: paginationParams,
|
||||
onlyOffline: onlyOffline,
|
||||
)
|
||||
.listen((channels) {
|
||||
if (clear) {
|
||||
_channelsController.add(channels);
|
||||
@@ -139,7 +140,7 @@ class ChannelsBlocState extends State<ChannelsBloc>
|
||||
}
|
||||
|
||||
_subscriptions.add(client.on(EventType.channelHidden).listen((event) async {
|
||||
final newChannels = List<Channel>.from(channels);
|
||||
final newChannels = List<Channel>.from(channels ?? []);
|
||||
final channelIndex = newChannels.indexWhere((c) => c.cid == event.cid);
|
||||
if (channelIndex > -1) {
|
||||
final channel = newChannels.removeAt(channelIndex);
|
||||
|
||||
Reference in New Issue
Block a user