auto_refresh_list_view 1.1.0

auto_refresh_list_view #

功能完善的列表刷新组件,使用MVP设计模式.

开始 #

安装 #

在pubspec.yaml中加入

dependencies:
  auto_refresh_list_view: <latest version>

介绍 #

采用MVP设计模式,将AutoRefreshListView最大限度进行解耦.由3个Presenter组成,将数据处理、item的展示、状态视图展示分别由不同Presenter提供实现.

new AutoRefreshListView(
      itemPresenter: _itemPresenter,
      dataPresenter: _dataPresenter,
      stateViewPresenter: _stateViewPresenter,
    )

dataPresenter #

负责提供数据和处理数据.比如拉取网络数据,然后将数据加入list或者其他操作.

stateViewPresenter #

负责提供加载中、加载失败、空页面、加载更多等view.支持自定义.

itemPresenter #

负责创建ListView的item、header、footer、sectionHeader、sectionFooter等.一般情况下会持有dataPresenter,因为视图的展示基本上都需要由数据来驱动.

效果图 #

使用 #

_MyHomePageState #

class _MyHomePageState extends State<MyHomePage> {
  RefreshListViewHomeItemPresenter _itemPresenter;
  RefreshListViewHomeDataPresenter _dataPresenter =
      RefreshListViewHomeDataPresenter();
  RefreshListHomeStateViewPresenter _stateViewPresenter =
      RefreshListHomeStateViewPresenter();
  AutoRefreshListViewController _listViewController = AutoRefreshListViewController();

  @override
  void initState() {
    super.initState();
    _itemPresenter = RefreshListViewHomeItemPresenter(_dataPresenter);
  }


  Widget _buildListView() {
    return QRefreshListView(
      itemPresenter: _itemPresenter,
      dataPresenter: _dataPresenter,
      stateViewPresenter: _stateViewPresenter,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
        actions: <Widget>[
          IconButton(
              icon: Icon(Icons.refresh),
              onPressed: () {
                _listViewController.beginRefresh();
              })
        ],
      ),
      body: _buildListView(),
    );
  }

}

RefreshListViewDataPresenter #

class RefreshListViewHomeDataPresenter extends RefreshListViewDataPresenter {
  @override
  int pageSize = 10;

  @override
  Future<RefreshListItemDataEntity> fetchDataEntity() {
    /// mocked data
    return Future.delayed(Duration(seconds: 2)).then((_) {
      List titles = [];
      var count = Random().nextBool() ? pageSize : (pageSize - 1);
      for (int i = 0; i < count; i++) {
        titles.add(WordPair.random().asPascalCase);
      }
      return titles;
    }).then((_) {
      return RefreshListItemDataEntity()
        ..success = Random().nextBool()
        ..entityList = _;
    });
  }
}

RefreshListViewItemIPresenter #

class RefreshListViewHomeItemPresenter extends RefreshListViewItemIPresenter {
  final RefreshListViewHomeDataPresenter dataPresenter;

  RefreshListViewHomeItemPresenter(this.dataPresenter);

  @override
  Widget items(BuildContext context, int section, int index) {
    return Container(
      alignment: Alignment.center,
      child: Text(dataPresenter.entityList[index]),
      height: 50,
    );
  }

  @override
  int rowCount(int section) => dataPresenter.entityList?.length ?? 0;

  @override
  void itemOnTap(BuildContext context, int section, int index) {
    showDialog(
        context: context,
        builder: (_) => AlertDialog(
              title: Text(dataPresenter.entityList[index]),
            ));
  }
}

RefreshListStateViewPresenter #

class RefreshListHomeStateViewPresenter extends RefreshListStateViewPresenter {
  @override
  Color themeColor = Colors.cyan;

  @override
  String emptyOnLoadText = '没有数据了~';

  @override
  Widget emptyImageWidget = Image.asset(
    'assets/load_empty.png',
    width: 215,
    height: 120,
  );

  @override
  Widget loadErrorImageWidget = Image.asset(
    'assets/load_error.png',
    width: 160,
    height: 160,
  );
}

[0.4.0]

  • 修改readme.

[0.5.0]

  • 添加reloadData方法.

[0.6.0]

  • 修改beginRefresh方法显示头部开始转圈圈.

[0.7.0]

  • 修复在没有mounted情况下setState的bug.
  • 修复item没有铺满全屏时,listView响应范围过小的bug.

[0.8.0]

  • 修复'data.success'为null情况下的直接判断的bug.
  • 添加refreshIndicatorColor和refreshIndicatorBackgroundColor属性

[0.9.0]

  • 更新list_view_item_builder的依赖版本

[1.0.0]

  • 增加jumpTo和animateTo功能.

[1.1.0]

  • 修复部分代码混乱的问题.

example/README.md

refresh_list_view #

A new Flutter module.

Getting Started #

For help getting started with Flutter, view our online documentation.

Use this package as a library

1. Depend on it

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


dependencies:
  auto_refresh_list_view: ^1.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:auto_refresh_list_view/auto_refresh_list_view.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
33
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

We analyzed this package on Sep 17, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.5.0
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/auto_refresh_list_view.dart.

Run flutter format to format lib/auto_refresh_list_view.dart.

Format lib/src/data_presenter.dart.

Run flutter format to format lib/src/data_presenter.dart.

Format lib/src/item_presenter.dart.

Run flutter format to format lib/src/item_presenter.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
list_view_item_builder ^1.0.0 1.2.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test