Merge pull request #540 from GetStream/feat/channel-pagination-error-retry

fix: channel pagination error retry
This commit is contained in:
Salvatore Giordano
2021-07-14 13:48:16 +02:00
committed by GitHub
5 changed files with 149 additions and 145 deletions
@@ -202,6 +202,7 @@ class _ChannelListViewState extends State<ChannelListView> {
final _slideController = SlidableController();
late final _defaultController = ChannelListController();
ChannelListController get _channelListController =>
widget.channelListController ?? _defaultController;
@@ -237,11 +238,8 @@ class _ChannelListViewState extends State<ChannelListView> {
}
Widget _buildListView(BuildContext context, List<Channel> channels) {
late Widget child;
if (channels.isNotEmpty) {
if (widget.crossAxisCount > 1) {
child = GridView.builder(
return GridView.builder(
padding: widget.padding,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: widget.crossAxisCount,
@@ -251,12 +249,12 @@ class _ChannelListViewState extends State<ChannelListView> {
itemBuilder: (context, index) =>
_gridItemBuilder(context, index, channels),
);
} else {
child = ListView.separated(
}
return ListView.separated(
padding: widget.padding,
physics: const AlwaysScrollableScrollPhysics(),
itemCount:
channels.isNotEmpty ? channels.length + 1 : channels.length,
// all channels + progress loader
itemCount: channels.length + 1,
separatorBuilder: (_, index) {
if (widget.separatorBuilder != null) {
return widget.separatorBuilder!(context, index);
@@ -267,10 +265,6 @@ class _ChannelListViewState extends State<ChannelListView> {
_listItemBuilder(context, index, channels),
);
}
}
return child;
}
Widget _buildEmptyWidget(BuildContext context) => LayoutBuilder(
builder: (context, viewportConstraints) {
@@ -486,11 +480,14 @@ class _ChannelListViewState extends State<ChannelListView> {
Widget _listItemBuilder(BuildContext context, int i, List<Channel> channels) {
final channelsBloc = ChannelsBloc.of(context);
if (i == channels.length) {
return _buildQueryProgressIndicator(context, channelsBloc);
}
final onTap = _getChannelTap(context);
final chatThemeData = StreamChatTheme.of(context);
final backgroundColor = chatThemeData.colorTheme.inputBg;
if (i < channels.length) {
final channel = channels[i];
return StreamChannel(
@@ -588,9 +585,6 @@ class _ChannelListViewState extends State<ChannelListView> {
),
),
);
} else {
return _buildQueryProgressIndicator(context, channelsBloc);
}
}
ChannelTapCallback _getChannelTap(BuildContext context) {
@@ -661,26 +655,31 @@ class _ChannelListViewState extends State<ChannelListView> {
BetterStreamBuilder<bool>(
stream: channelsProvider.queryChannelsLoading,
initialData: false,
errorBuilder: (context, err) => Container(
color: StreamChatTheme.of(context)
.colorTheme
.accentError
.withOpacity(.2),
child: const Padding(
padding: EdgeInsets.symmetric(vertical: 16),
child: Center(
child: Text('Error loading channels'),
errorBuilder: (context, err) {
final theme = StreamChatTheme.of(context);
return Container(
color: theme.colorTheme.textLowEmphasis.withOpacity(0.9),
child: Padding(
padding: const EdgeInsets.all(16),
child: Text(
'Error loading channels',
style: theme.textTheme.body.copyWith(
color: Colors.white,
),
),
),
builder: (context, data) => data
? const Center(
);
},
builder: (context, showLoading) {
if (!showLoading) return const Offstage();
return const Center(
child: Padding(
padding: EdgeInsets.all(16),
child: CircularProgressIndicator(),
),
)
: const Offstage());
);
},
);
Widget _separatorBuilder(context, i) {
final effect = StreamChatTheme.of(context).colorTheme.borderBottom;
@@ -146,6 +146,8 @@ class ChannelsBlocState extends State<ChannelsBloc>
_paginationEnded = true;
}
} catch (e, stk) {
// reset loading controller
_queryChannelsLoadingController.sink.add(false);
if (_channelsController.hasValue) {
_queryChannelsLoadingController.addError(e, stk);
} else {
@@ -85,6 +85,7 @@ class _LazyLoadScrollViewState extends State<LazyLoadScrollView> {
final extentBefore = notification.metrics.extentBefore;
final extentAfter = notification.metrics.extentAfter;
final scrollingDown = _scrollPosition < pixels;
_scrollPosition = pixels;
if (scrollingDown) {
if (extentAfter <= scrollOffset) {
@@ -97,8 +98,6 @@ class _LazyLoadScrollViewState extends State<LazyLoadScrollView> {
return true;
}
}
_scrollPosition = pixels;
}
if (notification is OverscrollNotification) {
if (notification.overscroll > 0) {
@@ -98,6 +98,8 @@ class MessageSearchBlocState extends State<MessageSearchBloc>
_queryMessagesLoadingController.add(false);
}
} catch (e, stk) {
// reset loading controller
_queryMessagesLoadingController.add(false);
if (_messageResponses.hasValue) {
_queryMessagesLoadingController.addError(e, stk);
} else {
@@ -96,6 +96,8 @@ class UsersBlocState extends State<UsersBloc>
_queryUsersLoadingController.add(false);
}
} catch (e, stk) {
// reset loading controller
_queryUsersLoadingController.add(false);
if (_usersController.hasValue) {
_queryUsersLoadingController.addError(e, stk);
} else {