搜索插件、代码仓与 APP 分类

插件详情v1.0.0

incrementally_loading_listview

列表视图小部件的扩展,可在滚动时逐步加载数据

近 30 天下载
218
喜欢数
46
Pub 分数
40

安装插件

flutter pub add incrementally_loading_listview

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Flutter 包,扩展了 ListView 小部件以在滚动时实现增量数据加载。当用户接近列表末尾时,它会自动触发数据获取,非常适合处理大型数据集而不会影响性能。该包通过无缝管理滚动事件和加载状态来简化分页逻辑。它支持自定义加载指示器和错误处理,确保流畅的用户体验。专为寻求高效、开箱即用的懒加载且无需大量样板代码的开发者设计。

适合场景

  • 实时加载大型数据集
  • 实现无限滚动信息流
  • 获取分页 API 结果
  • 构建聊天或时间线界面
  • 在长列表中提升性能

主要特点

  • 自动滚动加载数据
  • 可自定义的加载指示器
  • 内置错误处理
  • 与现有 ListView 的简单集成
  • 支持正向和反向分页

适合对象

  • 开发动态内容提要的开发者
  • 包含大量数据列表的应用程序
  • 需要流畅滚动性能的项目
  • 希望减少分页样板代码的团队
  • 依赖网络的数据移动应用

使用建议

  • 需要正确的状态管理
  • 可能需要针对复杂的加载逻辑进行自定义
  • 未针对极高频率的更新进行优化
  • 有限的平台特定优化
  • 依赖外部依赖项以实现完整功能

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

incrementally_loading_listview

pub package

An extension of the Flutter ListView widget for incrementally loading items upon scrolling. This could be used to load paginated data received from API requests.

NOTE: this package depends on rxdart. If you run into conflicts with different versions of rxdart, consider using dependency overrides as per this link

Getting Started

There's a working example that can be run to see how it works.

First import the library

import 'package:incrementally_loading_listview/incrementally_loading_listview.dart';

You can then use the IncrementallyLoadingListView widget in a similar way you would with the ListView.separated constructor

return IncrementallyLoadingListView(
    hasMore: () => _hasMoreItems,
    itemCount: () => items.length,
    loadMore: () async {
        // can shorten to "loadMore: _loadMoreItems" but this syntax is used to demonstrate that
        // functions with parameters can also be invoked if needed
        await _loadMoreItems();
    },
    loadMoreOffsetFromBottom: 2,
    itemBuilder: (context, index) {
        /// your builder function for rendering the item
    },
    separatorBuilder: (context, index) {
        /// your builder function for rendering the separator
    }
);

The widget allows passing in the same parameters you would to the ListView.builder constructor but itemCount is required so that when an item scrolls into view, it can see if it should attempt to load more items. Note that this is a callback that returns a boolean rather than being a boolean value. This allows the widget to not require a reference/copy of your data collection. The other parameters that can be specified are

  • hasMore: a callback that indicates if there are more items that can be loaded
  • loadMore: a callback to an asynchronous function that loads more items
  • loadMoreOffsetFromBottom: determines when the list view should attempt to load more items based on of the index of the item is scrolling into view. This is relative to the bottom of the list and has a default value of 0 so that it loads when the last item within the list view scrolls into view. As an example, setting this to 1 would attempt to load more items when the second last item within the list view scrolls into view
  • onLoadMore: a callback that is triggered when more items are being loaded. At first this will pass a boolean value of true to when items are being loaded by triggering the loadMore callback function. You could use this to update your UI to show a loading indicator
  • onLoadMoreFinished: a callback that is triggered when items have finished being loading. You can use this to hide your loading indicator
  • separatorBuilder: not required builder function that place separator between items

Providing onLoadMore and onLoadMoreFinished callbacks means the widget doesn't make assumptions on how you want to render a loading indicator so it will be up to your application to handle these callbacks to render the appropriate UI.

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。