refreshable_stateful_list 0.1.0

refreshable_stateful_list #

refreshable list with views in multiple status (such as loading , empty, error) and give the chance to retry.

支持下拉刷新、上拉加载的列表,同时列表会自动切换到不同状态(比如加载中、错误、空数据)下,在错误和空数据视图中可以重试。

支持请求多个接口

只有一个接口能分页,默认为 [_requests] 中最后一个接口

刷新时,请求所有接口

上拉加载更多时,只请求分页接口

配置项 #

业务方可以控制很多配置,包括:

必传参数: #

  • 数据源列表(_requests),有三种类型的数据源:
    • Future(此时按没有分页处理)
    • 返回值为 Future 的方法(此时按分页处理,传入的方法只允许有1个参数:页码)
    • 数据列表
  • 每个数据源的 tag,方便业务方区分,以实现不同业务 (tags)
  • 每个数据源对应数据的 key,根据 key 获取每个接口返回的列表 (dataKeys)
  • 每个 item 的构建方法 (_buildItem,该方法会收到两个参数:数据 和 索引)

可选参数: #

  • 是否可以下拉刷新 (refreshable,默认为 true)
  • 分页时的初始页码 (initPageNo,默认为0)
  • 分页请求的总页数的 key (pageCountKey,默认为 pageCount)
  • 分隔线 (divider,默认为一条线)
  • 是否显示悬浮按钮,返回到列表顶部 (showFloating)
  • 监听事件,用于刷新列表数据 (listenTypes) 要实现该功能,请使用 '/event' 中的 eventBus 发送事件

APIs: #

  • jumpTo(double value)
  • animateTo(double offset, Duration duration, Curve curve)

example; #

只传入一个不分页的数据源 #

  @override
  Widget build(BuildContext context) {
    return RefreshableStatefulList(
      [http.get('https://www.wanandroid.com/tree/json')],
      [''],
      [''],
      (item, index){},
      divider: (index) {
        return Container(
          height: 20,
        );
      },
      showFloating: false,
      refreshable: false,
    );
  }

传入两个数据源,第一个不分页,第二个分页 #

  articles(pageNo) {
    return http.get('https://www.wanandroid.com/article/list/$pageNo/json');
  }

  @override
  Widget build(BuildContext context) {
    return RefreshableStatefulList(
      [
        http.get('https://www.wanandroid.com/tree/json'),
        articles,
      ],
      [
         '',
        'datas',
      ],
      [
        '',
        '',
       ],
      (item, index){},
      initPageNo: 1,
      pageCountKey: 'totalPageCount',
    );
  }

[0.1.0] - 2019-08-14.

  • complete all the functions

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  refreshable_stateful_list: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:refreshable_stateful_list/refreshable_stateful_list.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
48
Learn more about scoring.

We analyzed this package on Feb 13, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Health suggestions

Fix lib/refreshable_stateful_list.dart. (-1 points)

Analysis of lib/refreshable_stateful_list.dart reported 2 hints:

line 15 col 7: This class (or a class which this class inherits from) is marked as '@immutable', but one or more of its instance fields are not final: RefreshableStatefulList._state

line 273 col 10: This method overrides a method annotated as @mustCallSuper in 'AutomaticKeepAliveClientMixin', but doesn't invoke the overridden method.

Format lib/status.dart.

Run flutter format to format lib/status.dart.

Maintenance suggestions

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and refreshable_stateful_list.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
event_bus ^1.1.0 1.1.1
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test