GithubHelp home page GithubHelp logo

zhaolongs / flutter_custom_refresh_plugin Goto Github PK

View Code? Open in Web Editor NEW
15.0 2.0 10.0 5.81 MB

flutter NestedScrollView 下拉刷新插件

License: Other

Java 4.10% Ruby 13.67% Objective-C 4.98% Dart 77.25%

flutter_custom_refresh_plugin's Introduction

custom_refresh_plugin

flutter NestedScrollView 下拉刷新插件

在 flutter 项目中使用

NestScrollView 设置下拉刷新效果


1 添加依赖

配制文件中 pubspec.yaml

custom_refresh_plugin:
  #git 方式依赖
  git:
    #仓库地址
    url: https://github.com/zhaolongs/flutter_custom_refresh_plugin.git
    # 分支
    ref: master

2 为 NestedScrollView 添加下拉刷新

@override
Widget build(BuildContext context) {
 return buildRootLayout();
}

Widget buildRootLayout() {
 return Scaffold(
   ///可滑动的布局
   body: CustomRefreshPage(
     ///子Widget
     child:NestedScrollView(
       .... 此处省略
     ),
     ///刷新控制器
     customRefreshController:customRefreshController,
   ),
 );
}

3 为 CustomRefreshController 下拉刷新控制器

3.1 创建 CustomRefreshController
声明成员变量
    CustomRefreshController customRefreshController = new CustomRefreshController();
3.2 CustomRefreshController 设置兼听
 CustomRefreshController customRefreshController = new CustomRefreshController();
  @override
  void initState() {
    super.initState();
    ///设置下拉刷新兼听
    ///本方法 是当下拉滑动到一定的距离时会触发一次
    customRefreshController.setOnRefreshListener(() {
      print("兼听到开始刷新回调");
      ///这里使用的是模拟网络加载效果
      Future.delayed(new Duration(milliseconds: 3000), () {
        ///结束刷新
        customRefreshController.closeRefresh();
        showCenterToast("已刷新");
      });
    });

    ///设置下拉滑动距离兼听
    ///[scrollPixe] 滑动距离兼听
    ///[totalScrollPixe] 总共可滑动的距离
    ///[toDown] true 向下滑动 false 向上滑动
    customRefreshController.setOnScrollListener(
      (double scrollPixe, double totalScrollPixe, bool toDown) {
        
      },
    );
    ///下拉刷新圆圈消失的回调方法
    customRefreshController.setOnRefreshFinishListener((){
      
    });
    
    
  }

flutter_custom_refresh_plugin's People

Contributors

zhaolongs avatar

Stargazers

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

Watchers

 avatar  avatar

flutter_custom_refresh_plugin'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.