一个可自定义的分页包,适用于 Flutter,可实现从 API 以逐页方式高效加载和显示数据。它支持下拉刷新和无限滚动交互,非常适合处理大型数据集的列表型应用。该包设计灵活,允许开发者自定义 UI、加载指示器和错误状态。它与异步数据获取无缝集成,并能处理空结果和网络故障等边缘情况。
适合场景
在列表中加载大型数据集
实现无限滚动
从 REST API 获取数据
显示分页搜索结果
构建新闻或社交媒体动态
主要特点
可自定义的 UI 组件
下拉刷新支持
无限滚动集成
错误和空状态处理
可配置的加载指示器
适合对象
包含大量数据列表的应用程序
基于API的内容展示
需要延迟加载的用户界面
寻求可重用分页逻辑的开发人员
需要响应式分页用户体验的项目
使用建议
需要手动处理 API 请求
有限的内置缓存
未针对极高频率的更新进行优化
依赖外部状态管理
复杂布局可能需要额外的样式
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Flutter Paginator
A customizable pagination package for Flutter. This package can be used
to fetch and display data from an API page by page.
Screenshots
Installing
dependencies:flutter_paginator:^0.0.6
Description
Paginator extends StatefulWidget has 3 constructors namely Paginator.listView, Paginator.gridView and Paginator.pageView. Paginator.listView, Paginator.gridView and Paginator.pageView are descendants of ListView, GridView and PageView. Paginator.listView, Paginator.gridView and Paginator.pageView got all the features of their ancestors and they are need to provide additional functions that are essential in doing their task.
PageLoadFuture
Loads the page asynchronously when the page number is given.
This should return an instance of a Future.
Called when the next page is needed to be loaded.
PageItemsGetter
This function should return list of page item data when page data is given.
This is called after successful completion of PageLoadFuture.
The page items returned by this method is added to the list of all the
page items.
ListItemBuilder
Builds list item when item data and item index are given.
This should return an instance of a Widget.
LoadingWidgetBuilder
Builds loading widget.
This should return an instance of a Widget.
ErrorWidgetBuilder
Builds error widget when page data and error callback are given.
This should return an instance of a Widget.
EmptyListWidgetBuilder
Builds empty list widget.
This is displayed when the total number of list items is zero.
This should return an instance of a Widget.
TotalItemsGetter
This should return total number of list items when page data is given.
PageErrorChecker
This should return true if page has error else false, when page data is given.