Paging

Pub Package
Star on GitHub style: effective dart MIT License


A new Flutter package for paging

Demo

DataSource

PageKeyedDataSource

Example for load with page index

1, Define Source

class ListViewDataSource extends paging.PageKeyedDataSource<int, Note> {
  NoteRepository noteRepository;
  ListViewDataSource(this.noteRepository) {
    isEndList = false;
  }

  @override
  Future<Tuple2<List<Note>, int>> loadInitial() async {
    final result = await noteRepository.getNotes(0);
    return Tuple2(result, 0);
  }

  @override
  Future<Tuple2<List<Note>, int>> loadPageAfter(int params) async {
    if (params == 6) isEndList = true;
    final result = await noteRepository.getNotes(params + 1);
    return Tuple2(result, params + 1);
  }
}

2, ListView

      ListView<Note>(
        key: key,
        padding: EdgeInsets.all(16),
        itemBuilder: (context, data, child) {
          return NoteWidget(data);
        },
        pageDataSource: dataSource,
      ),

3, GridView

      paging.GridView<Note>(
        key: key,
        padding: EdgeInsets.all(16),
        itemBuilder: (context, data, child) {
          return NoteGridWidget(data);
        },
        delegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
          mainAxisSpacing: 16,
          crossAxisSpacing: 16
        ),
        pageDataSource: dataSource,
      ),

ItemKeyedDataSource

Coming Soon :))

OffsetDataSource

Coming Soon :))

IndexDataSource

Coming Soon :))

Documentation

BaseWidget Class

Dart attributeDescriptionDefault Value
emptyBuilderbuilder for empty widget
loadingBuilderbuilder for loading widget
errorBuilderbuilder for error widget
itemBuilderbuilder for item widget
pageDataSourceDataSource for this widget

Libraries

fl_paging