项目作者: dangngocduc

项目描述 :
A small library support load infinite for ListView - GridView on Flutter.
高级语言: Dart
项目地址: git://github.com/dangngocduc/flutter_paging.git
创建时间: 2020-10-30T05:29:51Z
项目社区:https://github.com/dangngocduc/flutter_paging

开源协议:MIT License

下载


Paging




Pub Package




Star on GitHub


style: effective dart


MIT License


A Flutter package that supports pagination(load infinite) for ListView, GridView

Demo

DataSource

PageKeyedDataSource

To create a PagingListView or PagingGridView you will need create class which extended from PageKeyedDataSource.

When extended from PageKeyedDataSource, you will need override 2 methods is loadInitial and loadPageAfter.

Output of those function is a Tuple2 with item1 is List is List of data, end item2 is next page index.

Example: if your list start with page index is 0.
-> on loadInitial output is Tuple2([…], 1) 1 is next page when load more item.

Example:

  1. class ListViewDataSource extends paging.PageKeyedDataSource<int, Note> {
  2. NoteRepository noteRepository;
  3. ListViewDataSource(this.noteRepository);
  4. @override
  5. Future<Tuple2<List<Note>, int>> loadInitial(int pageSize) async {
  6. return Tuple2(await noteRepository.getNotes(0), 1);
  7. }
  8. @override
  9. Future<Tuple2<List<Note>, int>> loadPageAfter(int params, int pageSize) async {
  10. return Tuple2(await noteRepository.getNotes(params), params + 1);
  11. }
  12. }

Display on UI

To display on UI, currently you can use PagingListView or PagingGridView.

Example:

  1. ListViewDataSource dataSource = ListViewDataSource(NoteRepository());
  2. PagingListView<Note>(
  3. itemBuilder: (context, data, child) => NoteWidget(data),
  4. pageDataSource: dataSource,
  5. ),