flutter_refresh_loadmore 0.1.8

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

flutter_refresh_loadmore #

A refresh loadmore listview package.

Getting Started #

Installing

flutter_refresh_loadmore: ^0.1.8

Import

import 'package:flutter_refresh_loadmore/flutter_refresh_loadmore.dart';

How To Use

    GlobalKey<ListViewRefreshLoadMoreWidgetState> _listViewKey = new GlobalKey();
    bool hasMoreData = true;
  
    Widget getList() {
      return ListViewRefreshLoadMoreWidget(
        key: _listViewKey,
        //listview  count
        itemCount: newsList.length,
  
        //listview 的item widget
        swrapInsideWidget: (buildContex, index) {
          return _widgetRow(index);
        },
        //下拉刷新
        refrshCallback: () async {
          await getNewsList(true, "", getCallbackAndSetData2(true));//获取数据 添加到newsList
          _listViewKey.currentState.changeData(newsList.length);
        },
        //加载更多
        loadMoreCallback: () async {
          await getNewsList(false, newsList.last.time, getCallbackAndSetData2(false)); //获取数据 添加到newsList
          _listViewKey.currentState.changeData(newsList.length,hasMoreData: hasMoreData);
        },
  
        /// 加载更多 用
        hasMoreData: hasMoreData,
  //    ///footer widget 非必须传有默认
  //    footerWidget: (statusStr){
  //      return null;
  //    },
  //    //head widget 非必传有默认
  //    headWidget: (headstate,currentHeight){
  //    return null;
  //    ;
  //    },
      );
    }

下拉默认刷新效果

image

加载默认更多效果

image

[0.0.1] - 2019/6/25

  • 下拉刷新 上拉加载更多

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_refresh_loadmore/flutter_refresh_loadmore.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
        appBar: AppBar(
          // Here we take the value from the MyHomePage object that was created by
          // the App.build method, and use it to set our appbar title.
          title: Text("title"),
        ),
        body: Myexample(),
      )
    );
  }
}

class Myexample extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return _MyexampleState();
  }

}
class _MyexampleState extends State<Myexample>{
  @override
  void initState() {
    list.add("a");
    list.add("a");
    list.add("a");
    list.add("a");
    list.add("a");list.add("a");list.add("a");list.add("a");list.add("a");list.add("a");
    list.add("a");list.add("a");list.add("a");list.add("a");list.add("a");

    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return getList();
  }


  GlobalKey<ListViewRefreshLoadMoreWidgetState> _listViewKey = new GlobalKey();
  bool hasMoreData = true;

  List<String> list=new List<String>();

  Widget getList() {
    return ListViewRefreshLoadMoreWidget(
      key: _listViewKey,
      //listview  count
      itemCount: list.length,

      //listview 的item widget
      swrapInsideWidget: (buildContex, index) {
        return Container(
          margin: EdgeInsets.only(bottom: 10),
          color: Colors.black38,
          height: 50,
          child: Center(child: Text("${list[index]}  ${index}"),),
        );
      },
      //下拉刷新
      refrshCallback: () async {
        await Future.delayed(Duration(milliseconds: 1000),(){
          list=new List();
          list.add("b");list.add("b");list.add("a");list.add("a");list.add("a");
          list.add("a");list.add("a");list.add("vvvv");
          list.add("a");list.add("a");list.add("vvvv");
          list.add("a");list.add("a");list.add("vvvv");
          list.add("a");list.add("a");list.add("vvvv");
        });//获取数据 添加到list
        _listViewKey.currentState.changeData(list.length);
      },
      //加载更多
      loadMoreCallback: () async {
        await Future.delayed(Duration(milliseconds: 1000),(){
          list.add("a");list.add("a");list.add("a");list.add("a");list.add("a");
          list.add("a");list.add("a");list.add("a");list.add("a");list.add("a");
          //如果加载完毕 hasMoreData设置为true

        });//获取数据 添加到list
        _listViewKey.currentState.changeData(list.length,hasMoreData: hasMoreData);
      },

      /// 加载更多 用
      hasMoreData: hasMoreData,
//    ///footer widget 非必须传有默认
//    footerWidget: (statusStr){
//      return null;
//    },
//    //head widget 非必传有默认
//    headWidget: (headstate,currentHeight){
//    return null;
//    ;
//    },
    );
  }

}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_refresh_loadmore: ^0.1.8

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

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

  • Dart: 2.6.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.6

Health suggestions

Fix lib/flutter_refresh_loadmore.dart. (-0.50 points)

Analysis of lib/flutter_refresh_loadmore.dart reported 1 hint:

line 35 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: ListViewRefreshLoadMoreWidget.hasMoreData, ListViewRefreshLoadMoreWidget.itemCount, ListViewRefreshLoadMoreWidget.footerWidget

Fix lib/refresh_head.dart. (-0.50 points)

Analysis of lib/refresh_head.dart reported 1 hint:

line 9 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: CustomHead.currentHeight, CustomHead.headStatus

Dependencies

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