flutter版的下拉刷新,上拉加载库flutter_pulltorefresh

直接放上github地址:

https://github.com/peng8350/flutter_pulltorefresh/blob/master/README_CN.md

只能说超级好用,可定制性高,里面存在的bug少,用这个感觉都可以不用SingleChildScrollView这个控件了。

用法:

  dependencies:
     pull_to_refresh: ^1.5.0

导入包:

 import 'package:pull_to_refresh/pull_to_refresh.dart';

在某个Widget中进行使用

  List<String> items = ["1", "2", "3", "4", "5", "6", "7", "8"];
  RefreshController _refreshController =
      RefreshController(initialRefresh: true);

  void _onRefresh() async{
    // monitor network fetch
    await Future.delayed(Duration(milliseconds: 1000));
    // if failed,use refreshFailed()
    _refreshController.refreshCompleted();
  }

  void _onLoading() async{
    // monitor network fetch
    await Future.delayed(Duration(milliseconds: 1000));
    // if failed,use loadFailed(),if no data return,use LoadNodata()
    items.add((items.length+1).toString());
    if(mounted)
    setState(() {

    });
    _refreshController.loadComplete();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SmartRefresher(
        enablePullDown: true,
        enablePullUp: true,
        header: WaterDropHeader(),
        footer: CustomFooter(
          builder: (BuildContext context,LoadStatus mode){
            Widget body ;
            if(mode==LoadStatus.idle){
              body =  Text("pull up load");
            }
            else if(mode==LoadStatus.loading){
              body =  CupertinoActivityIndicator();
            }
            else if(mode == LoadStatus.failed){
              body = Text("Load Failed!Click retry!");
            }
            else{
              body = Text("No more Data");
            }
            return Container(
              height: 55.0,
              child: Center(child:body),
            );
          },
        ),
        controller: _refreshController,
        onRefresh: _onRefresh,
        onLoading: _onLoading,
        child: ListView.builder(
          itemBuilder: (c, i) => Card(child: Center(child: Text(items[i]))),
          itemExtent: 100.0,
          itemCount: items.length,
        ),
      ),
    );
  }

  // don't forget to dispose refreshController
  @override
  void dispose() {
    // TODO: implement dispose
    _refreshController.dispose();
    super.dispose();
  }

项目中使用效果图:


Flutter移动电商,关注公众号:蛇崽网盘资源,回复【Flutter移动电商】,即可领取。

关注「蛇崽网盘教程资源」公众号 ,在微信后台回复「领取资源」,获取IT资源200G干货大全。

更多资源请访问:

超详细图文搭建个人免费博客

关注「蛇崽网盘教程资源」公众号 ,在微信后台回复「领取资源」,获取IT资源200G干货大全。

在微信后台回复「130个小程序」,即可免费领取享有导入就能跑的微信小程序

flutter版的下拉刷新,上拉加载库flutter_pulltorefresh_第1张图片

你可能感兴趣的:(Flutter开发)