add pullToRefresh property to ChannelListView

This commit is contained in:
Salvatore Giordano
2020-08-25 11:07:29 +02:00
parent b8757e0e4c
commit 1e8fbd2854
+21 -7
View File
@@ -60,6 +60,7 @@ class ChannelListView extends StatefulWidget {
this.channelPreviewBuilder,
this.errorBuilder,
this.onImageTap,
this.pullToRefresh = true,
}) : super(key: key);
/// The builder that will be used in case of error
@@ -105,6 +106,9 @@ class ChannelListView extends StatefulWidget {
/// The function called when the image is tapped
final Function(Channel) onImageTap;
/// Set it to false to disable the pull-to-refresh widget
final bool pullToRefresh;
@override
_ChannelListViewState createState() => _ChannelListViewState();
}
@@ -115,19 +119,30 @@ class _ChannelListViewState extends State<ChannelListView>
@override
Widget build(BuildContext context) {
final channelsProvider = ChannelsBloc.of(context);
final channelsBloc = ChannelsBloc.of(context);
if (!widget.pullToRefresh) {
return _buildListView(channelsBloc);
}
return RefreshIndicator(
onRefresh: () async {
return channelsProvider.queryChannels(
return channelsBloc.queryChannels(
filter: widget.filter,
sortOptions: widget.sort,
paginationParams: widget.pagination,
options: widget.options,
);
},
child: StreamBuilder<List<Channel>>(
stream: channelsProvider.channelsStream,
child: _buildListView(channelsBloc),
);
}
StreamBuilder<List<Channel>> _buildListView(
ChannelsBlocState channelsBlocState,
) {
return StreamBuilder<List<Channel>>(
stream: channelsBlocState.channelsStream,
builder: (context, snapshot) {
if (snapshot.hasError) {
if (snapshot.error is Error) {
@@ -175,7 +190,7 @@ class _ChannelListViewState extends State<ChannelListView>
),
FlatButton(
onPressed: () {
channelsProvider.queryChannels(
channelsBlocState.queryChannels(
filter: widget.filter,
sortOptions: widget.sort,
paginationParams: widget.pagination,
@@ -212,8 +227,7 @@ class _ChannelListViewState extends State<ChannelListView>
},
),
);
}),
);
});
}
Widget _itemBuilder(context, int i, List<Channel> channels) {