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