Giter Site home page Giter Site logo

pull_to_refresh's Introduction

pull_to_refresh

A widget that provided to pull-up load and pull-down refresh with Flutter.

Features

  • pull up and pull down
  • Simple interface, easy access
  • support most of the component in Flutter such as scroll and non-scroll component

Show cases

Quick Start

  1. Add import package:pull_to_refresh/pull_to_refresh_widget.dart;
  2. Using PullToRefreshWidget wrap outside your content widget
PullToRefreshWidget(
    isRefreshEnable: true,
    headerBuilder: _buildHeaderWidget,
    onRefresh: _handleRefresh,
    isLoadMoreEnable: hasMore,
    onLoadMore: _onLoadMore,
    footerBuilder: _buildFootWidget,
    child: ListView.builder(
        itemCount: items.length,
        itemBuilder: (context, index) {
        return new ListTile(
            title: Text("Index$index"),
        );
    }));
  1. You should set the headerBuilder and footerBuilder in PullToRefreshWidget that generate header widget and footer widget. The header widget must inherit DefaultRefreshHeaderWidget.
DefaultRefreshHeaderWidget _buildHeaderWidget(BuildContext context) {
    return DefaultRefreshHeaderWidget();
  }

Widget _buildFootWidget(BuildContext context) {
    return new Container(
      alignment: Alignment.center,
      height: 60.0,
      child: new Center(
        child: new Row(
            textDirection: TextDirection.ltr,
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              new Text("正在加载中。。。"),
              new CircularProgressIndicator(strokeWidth: 2.0)
            ]),
      ),
    );
  }
  1. The onRefresh and onLoadMore will be callback when the indicator state is refreshed and load more. The function returned [Future] must complete when the refresh operation is finished.
  Future<Null> _handleRefresh() async {
    await Future.delayed(Duration(seconds: 50), () {
      setState(() {
        items.clear();
        items = List.generate(40, (i) => i);
      });
    });
  }

  Future<Null> _onLoadMore() async {
    await Future.delayed(Duration(seconds: 50), () {
      setState(() {
        if (index == 2) {
          hasMore = false;
        }
        int length = items.length;
        index++;
        items.addAll(List.generate(16, (i) => i + length));
      });
    });
  }

full example see here: main.dart.

pull_to_refresh's People

Contributors

kongshanshan33 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pull_to_refresh's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.