flutter_futrue 1.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 50

百花齐放


语言 : 中文 | English

Flutter Futrue #

针对Flutter(Android、IOS)项目,从进入页面开始获取数据,对数据正常\异常时的整体解决方案。 使用flutter_futrue前后对比.png

从上图中可发现 flutter_futrue就是把你打开页面、访问网络数据后的一些列事情及情况都进行了封装,只需要去做对应数据处理(ListView 画 Item)、数据异常后的对应数据(自带重新功能)、登录失效的处理以及对应的接口API的封装。相对来说减轻了开发量及页面代码。


正式项目: AndroidIOS

AndroidIOS

flutter_futrue 特点

  • 半自动处理网络断开、服务器超时、数据为空、登录失效等情况 。
  • 可根据结果集类型定制半自动处理逻辑(耦合不同的格式的JSON结果集)。
  • 可自定义错误页面(含重试功能)。
  • 可自定义转圈页面(随时呼出)。
  • 初入页面时呼出默认转圈。
  • 下拉刷新数据。
  • 上拉加载更多数据。

刷新效果图 #

模式无内容、无网络模拟返回页面时的情况

使用 #

  1. 添加依赖
dependencies:
  flutter_futrue: latest_version
  1. 引入
import 'package:flutter_futrue/flutter_futrue.dart';
  1. 替换当前页面extends State更改为extends BaseState
...
//class _YourPageName extends State<YourPageName>{...}
class _YourPageName extends BaseState<YourPageName>{...}
...
  1. 在build中的使用
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(... ),
      body: bodyWidget(
        modelList: modelList,
        onRefresh: onRefresh,
        onLoading: onLoading,
        contentBody: body(),
      ),
    );
  }
...
  1. onRefresh(onLoading)获取数据的封装
  void onRefresh() async {
    callRefresh(
      modelList: modelList,
      dao: yourGetDataInterfaceMethod(),
      dataCallback: (Object bean) {
       //当前页面的数据处理,注意bean的类型取决于yourGetDataInterfaceMethod
      },
      tokenInvalidCallback: (msg) =>
          defaultHandlingTokenInvalid(context, msg: msg,page:new Login()),
    );
  }
...

总结了一下开发流程(极简、规范): #

1.把当前页面extends State更改为extends BaseState(内部封装了刷新等逻辑及数据粗颗粒处理等逻辑)。 2.在build中使用bodyWidget方法。 3.书写onRefresh/onLoading方法,使用当前页面对应的接口获取数据,处理具体数据(数据正常时、数据为空时,服务器异常时、手机无网络等情况)。 4.书写onBody方法,选择是ListView或GridView及具体Item绘制。 如此,让开发分工于接口接入\测试,UI绘制,逻辑处理,极大的提高了团队的开发效率。

传送门 #

联系方式 #

我的FlutterQQ群:10788108 Flutter专栏QQ群:497219582

1.1.0 #

  • Fixed an issue where extended loops failed when there was a head layout
  • Logic when optimizing non-data type data result sets
  • Optimized support for drop-down refresh
  • Added universal search widget

1.0.9 #

  • Fixed an issue where the previous version of the custom circle and the error page could not be used

1.0.8 #

  • Remove the base data in the base base class and execute the setState after the callback, avoiding some of the page combination with the TabView error setState() called after dispose()

1.0.7 #

  • ptimize the use of TabView, if the page is not sliding in order (the first page directly into the third page), and the login failure, the BuildContext is empty
  • Added helper class, providing common routing function, routing function with return parameters, text button in the upper right corner of AppBar, etc.

1.0.6 #

  • happy mid-Autumn Festival!
  • Optimize laps, error pages, head layout, bottom layout performance

1.0.5 #

  • Major optimization upgrade

1.0.4 #

  • Add more extension methods for processing data
  • Adapt to Androidx

1.0.3 #

  • Add pull-down refresh switch
  • Optimize when no more loads are loaded

1.0.2 #

  • dartfmt fromt code

1.0.1 #

  • initRelease

1.0.0 #

  • initRelease

example/README.md

flutter_future example 说明文档 #

需要说明的是,该插件不适合使用集合了多方API(这里指JSON格式不一致的)

  1. 我的环境(mac+win10台式)

    Flutter: 1.9
    Java sdk: 8
    Android Studio: 3.4.2
    Android Tools: 3.4.2
    Gradle: gradle-5.1.1-all.zip
    
  2. 我司接口格式

   {
       "msg": "查找成功",
       "ver": "1.5.0",
       "data": [],
       "success": true,
       "code": "200"
   }

核心字段:msg、code、data(注意: "data":{}或 "data":[])

  1. 完整页面的使用
...
import 'package:flutter_futrue/flutter_futrue.dart';
class SimplePage1 extends StatefulWidget {
  @override
  _SimplePage1State createState() => _SimplePage1State();
}

class _SimplePage1State extends BaseState<SimplePage1>
    with SingleTickerProviderStateMixin {
  List<SimpleDataBean> modelList = [];
  bool isPrint = true;

  @override
  void initState() {
    onRefresh();
    super.initState();
  }

  @override
  void dispose() {
    refreshController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar( title: Text('随机模拟所有情况') ),
      body: bodyWidget(
        modelList: modelList,
        onRefresh: onRefresh,
        onLoading: onLoading,
        contentBody: body(),
      ),
    );
  }

  void onRefresh() async {
    var path = Api.randomPath('onRefresh');
    callRefresh(
      modelList: modelList,
      dao: HttpManager().get(
        who: 'path',
        path: path,
      ),
      dataCallback: (Object bean) {
        List<dynamic> temp = bean;
        temp.length >= 10 ? isLoading = true : isLoading = false;
        temp.forEach((v) {
          modelList.add(new SimpleDataBean.fromJson(v));
        });
      },
      tokenInvalidCallback: (msg) =>
      defaultHandlingTokenInvalid(context, msg: msg,page:new Login),
    );
  }

  void onLoading() async {
    var path = Api.randomPath('onLoading');
    callLoading(
      dao: HttpManager().get(
        who: path,
        path: path,
      ),
      dataCallback: (Object bean) {
        List<dynamic> temp = bean;
        temp.length >= 10 ? isLoading = true : isLoading = false;
        temp.forEach((v) {
          modelList.add(new SimpleDataBean.fromJson(v));
        });
      },
        tokenInvalidCallback: (msg) {
          print('根据自己项目的需求处理token失效');
          Navigator.of(context).pop();
        },
    );
  }

  Widget body() {
    return ListView.builder(
      itemCount: modelList.length,
      itemBuilder: (BuildContext context, int index) {
        return Container(
          alignment: Alignment.center,
          height: 80.0,
          child: Text('${modelList[index].name}'),
        );
      },
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  flutter_futrue: ^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:flutter_futrue/flutter_futrue.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
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]
50
Learn more about scoring.

We analyzed this package on Dec 10, 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

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
connectivity ^0.4.5+2 0.4.6 0.4.6+1
flutter 0.0.0
pull_to_refresh ^1.5.7 1.5.7
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