[core] add default pagination value + implement pagination in example

This commit is contained in:
Salvatore Giordano
2021-02-19 13:14:31 +01:00
parent 24ce5333ce
commit 08bd5a8ca8
2 changed files with 44 additions and 25 deletions
@@ -67,6 +67,8 @@ class StreamExample extends StatelessWidget {
/// [ChannelListCore] is a `builder` with callbacks for constructing UIs based
/// on different scenarios.
class HomeScreen extends StatelessWidget {
final channelListController = ChannelListController();
@override
Widget build(BuildContext context) {
return Scaffold(
@@ -75,6 +77,15 @@ class HomeScreen extends StatelessWidget {
),
body: ChannelsBloc(
child: ChannelListCore(
channelListController: channelListController,
filter: {
'type': 'messaging',
'members': {
r'$in': [
StreamChatCore.of(context).user.id,
]
}
},
emptyBuilder: (BuildContext context) {
return Center(
child: Text('Looks like you are not in any channels'),
@@ -99,7 +110,11 @@ class HomeScreen extends StatelessWidget {
BuildContext context,
List<Channel> channels,
) =>
ListView.builder(
LazyLoadScrollView(
onEndOfPage: () async {
channelListController.paginateData();
},
child: ListView.builder(
itemCount: channels.length,
itemBuilder: (BuildContext context, int index) {
final _item = channels[index];
@@ -127,6 +142,7 @@ class HomeScreen extends StatelessWidget {
),
),
),
),
);
}
}
@@ -64,7 +64,10 @@ class ChannelListCore extends StatefulWidget {
this.filter,
this.options,
this.sort,
this.pagination,
this.pagination = const PaginationParams(
offset: 0,
limit: 25,
),
this.channelListController,
}) : assert(errorBuilder != null),
assert(emptyBuilder != null),