admin
2022-05-12 fa705507ba574c857b1667553737d23b1b7ff495
src/main/resources/code/flutter_module/lib/ui/widget/refresh_listview.dart
@@ -1,17 +1,19 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../ui/widget/button.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
typedef OnRefresh = void Function();
typedef OnLoadMore = void Function();
typedef BoolCallback = void Function(bool b);
typedef StringCallback = void Function(String s);
typedef GetViewState = RefreshListViewState Function();
class MyRefreshController extends RefreshController {
  MyRefreshController({
    bool initialRefresh = true,
  }) : super(
            initialRefresh: initialRefresh, initialLoadStatus: LoadStatus.idle);
      initialRefresh: initialRefresh, initialLoadStatus: LoadStatus.idle);
  //api错误
  VoidCallback? apiError;
@@ -37,7 +39,7 @@
  void dispose() {
    apiError = null;
    dataEmpty = null;
    dataNormal=null;
    dataNormal = null;
    setPullDownEnable = null;
    setPullUpEnable = null;
    setEditMode = null;
@@ -47,19 +49,23 @@
class RefreshListView extends StatefulWidget {
  final MyRefreshController refreshController;
  final Widget content;
  final Widget? emptyView;
  final OnRefresh? refresh;
  final OnLoadMore? loadMore;
  final Color loadTextColor;
  bool? enablePullDown;
  bool? enablePullUp;
  RefreshListView(
      {required this.refreshController,
      required this.content,
      this.refresh,
      this.loadMore,
      this.enablePullDown = true,
      this.enablePullUp = true});
        required this.content,
        this.emptyView,
        this.refresh,
        this.loadTextColor = const Color(0xFFB8AFB5),
        this.loadMore,
        this.enablePullDown = true,
        this.enablePullUp = true});
  @override
  State<StatefulWidget> createState() => _RefreshListViewState();
@@ -77,7 +83,7 @@
  bindController() {
    widget.refreshController.apiError = _apiError;
    widget.refreshController.dataEmpty = _dataEmpty;
    widget.refreshController.dataNormal =_dataNormal;
    widget.refreshController.dataNormal = _dataNormal;
    widget.refreshController.setPullDownEnable = _pullDownEnable;
    widget.refreshController.setPullUpEnable = _pullUpEnable;
    widget.refreshController.viewState = () {
@@ -88,7 +94,6 @@
        editMode = enable;
      });
    };
  }
  //视图状态 0-正常  1-空视图  2-网络请求错误
@@ -151,85 +156,100 @@
    return editMode
        ? widget.content
        : SmartRefresher(
            enablePullDown: widget.enablePullDown!,
            enablePullUp: widget.enablePullUp!,
            header: const WaterDropHeader(
              complete: Text(
                "刷新完成",
                style: TextStyle(color: Color(0xFFB8AFB5)),
              ),
            ),
            footer: CustomFooter(
              builder: (BuildContext context, LoadStatus? mode) {
                Widget body;
                if (mode == LoadStatus.idle) {
                  body = const Text("",
                      style: TextStyle(color: Color(0xFFB8AFB5)));
                } else if (mode == LoadStatus.loading) {
                  body = const CupertinoActivityIndicator();
                } else if (mode == LoadStatus.failed) {
                  body = const Text("加载失败!点击重试!",
                      style: TextStyle(color: Color(0xFFB8AFB5)));
                } else if (mode == LoadStatus.canLoading) {
                  body = const Text("松手,加载更多!",
                      style: TextStyle(color: Color(0xFFB8AFB5)));
                } else {
                  body = const Text("没有更多数据了!",
                      style: TextStyle(color: Color(0xFFB8AFB5)));
                }
                return SizedBox(
                  height: 55.0,
                  child: Center(child: body),
                );
              },
            ),
            controller: widget.refreshController,
            onRefresh: _onRefresh,
            onLoading: _onLoading,
            child: widget.content,
          );
  }
      enablePullDown: widget.enablePullDown!,
      enablePullUp: widget.enablePullUp!,
      header:
      MaterialClassicHeader(),
  Widget emptyView() {
    return Container(
      width: MediaQuery.of(context).size.width * 2 / 3,
      alignment: Alignment.center,
      // color: Colors.yellow,
      child: Stack(
        alignment: Alignment.bottomCenter,
        children: [
          Image.asset(
            "assets/imgs/common/ic_empty.png",
          ),
          const Text(
            "暂无数据     ",
            style: TextStyle(color: Color(0xFFF698C9), fontSize: 18),
          )
        ],
      // const WaterDropHeader(
      //   complete: Text(
      //     "刷新完成",
      //     style: TextStyle(color: Color(0xFFB8AFB5)),
      //   ),
      // ),
      footer: CustomFooter(
        builder: (BuildContext context, LoadStatus? mode) {
          Widget body;
          if (mode == LoadStatus.idle) {
            body = const Text("",
                style: TextStyle(color: Color(0xFFB8AFB5)));
          } else if (mode == LoadStatus.loading) {
            body = const CupertinoActivityIndicator();
          } else if (mode == LoadStatus.failed) {
            body = const Text("加载失败!点击重试!",
                style: TextStyle(color: Color(0xFFB8AFB5)));
          } else if (mode == LoadStatus.canLoading) {
            body = const Text("松手,加载更多!",
                style: TextStyle(color: Color(0xFFB8AFB5)));
          } else {
            body = Text("~到底了~",
                style: TextStyle(color: widget.loadTextColor));
          }
          return SizedBox(
            height: 55.0,
            child: Center(child: body),
          );
        },
      ),
      controller: widget.refreshController,
      onRefresh: _onRefresh,
      onLoading: _onLoading,
      child: widget.content,
    );
  }
  Widget errorView() {
    return InkWell(
        onTap: () {
          _onRefresh();
        },
        child: Container(
  Widget emptyView() {
    return widget.emptyView ??
        Container(
          width: MediaQuery.of(context).size.width * 2 / 3,
          alignment: Alignment.center,
          // color: Colors.yellow,
          child: Stack(
            alignment: Alignment.bottomCenter,
            children: [
              Image.asset("assets/imgs/common/ic_network_error.png",
                  width: MediaQuery.of(context).size.width * 2 / 5),
              Image.asset(
                "assets/imgs/common/ic_empty.png",
              ),
              const Text(
                "网络异常,点击重新加载",
                style: TextStyle(color: Color(0xFFF698C9), fontSize: 18),
                "~空空如也~",
                style: TextStyle(color: Color(0xFF999999), fontSize: 18),
              )
            ],
          ),
        ));
        );
  }
  Widget errorView() {
    return Container(
      alignment: Alignment.center,
      // color: Colors.yellow,
      child: Stack(
        alignment: Alignment.bottomCenter,
        children: [
          Image.asset("assets/imgs/common/ic_network_error.png",
              width: MediaQuery.of(context).size.width * 3 / 5),
          const Positioned(
              bottom: 50,
              left: 0,
              right: 0,
              child: Text(
                "网络请求出错",
                textAlign: TextAlign.center,
                style: TextStyle(fontSize: 15, color: Color(0xFF999999)),
              )),
          MyFillButton(
            "点击重新加载",
            18,
            width: 170,
            height: 36,
            fontSize: 15,
            onClick: () {
              _onRefresh();
            },
          )
        ],
      ),
    );
  }
  @override