BaseComponent.dart 10.6 KB
Newer Older
林生雨's avatar
林生雨 committed
1 2 3 4 5 6 7
/*
 * @author lsy
 * @date   2019-10-13
 **/

import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
林生雨's avatar
林生雨 committed
8
import 'package:flutter/rendering.dart';
林生雨's avatar
林生雨 committed
9 10 11 12
import 'package:flutter_common/commonModel/eventbus/GlobalEventBus.dart';
import 'package:flutter_common/commonModel/view/iOSLoading.dart';
import 'package:flutter_svg/svg.dart';
import 'package:gm_flutter/commonModel/GMBase.dart';
林生雨's avatar
林生雨 committed
13 14
import 'package:gm_flutter/commonModel/util/DartUtil.dart';
import 'package:gm_flutter/commonModel/view/ImagesAnimation.dart';
林生雨's avatar
林生雨 committed
15
import 'package:lottie/lottie.dart';
林生雨's avatar
林生雨 committed
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import 'package:pull_to_refresh/pull_to_refresh.dart';

double SCREENWIDTH;
double SCREENHEIGHT;

AppBar baseAppBar(
    {String title,
    List<Widget> action,
    bool centerTitle,
    VoidCallback backClick,
    Color backgroundColor,
    Key key,
    bool showBack = true,
    double elevation = 0.0,
    Widget titleWidget = null}) {
  return _baseAppBarChangeTitle(
林生雨's avatar
林生雨 committed
32 33
      title:
          title == null ? Container() : baseText(title, 16, Color(0xff323232)),
林生雨's avatar
林生雨 committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
      action: action,
      centerTitle: centerTitle,
      backClick: backClick,
      backgroundColor: backgroundColor,
      key: key,
      showBack: showBack,
      elevation: elevation,
      titleWidget: titleWidget);
}

AppBar _baseAppBarChangeTitle(
    {Widget title,
    List<Widget> action,
    bool centerTitle,
    VoidCallback backClick,
    Color backgroundColor,
    Key key,
    bool showBack,
    double elevation,
    Widget titleWidget}) {
  return AppBar(
    key: key,
//    backgroundColor:
//        backgroundColor == null ? ALColors.ColorFFFFFF : backgroundColor,
    title: titleWidget == null ? title : titleWidget,
    centerTitle: centerTitle,
    elevation: elevation,
    leading: showBack
        ? GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: backClick,
            child: Hero(
                tag: "left_arrow",
                child: Container(
                    alignment: Alignment.centerLeft,
                    margin: EdgeInsets.only(left: 10),
                    child: Container(
                      width: 30,
                      height: 30,
                      child: Image.asset(
林生雨's avatar
林生雨 committed
74
                        "assets/left_arrow.png",
林生雨's avatar
林生雨 committed
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
                        color: Color(0xff323232),
                      ),
                    ))),
          )
        : Container(),
    actions: action == null ? List<Widget>() : action,
  );
}

Text baseText(String text, double fontSize, Color color, {bool bold = false}) {
  return Text(
    text,
    textScaleFactor: 1.0,
    style: TextStyle(
        decoration: TextDecoration.none,
        fontSize: fontSize,
        color: color,
        fontStyle: FontStyle.normal,
        fontWeight: bold ? FontWeight.w500 : FontWeight.w400),
  );
}

Widget baseDivide(double padding) {
  return Container(
    height: 0.5,
    width: double.maxFinite,
    margin: EdgeInsets.only(left: padding, right: padding),
    color: Color(0xffE5E5E5),
  );
}

Widget baseDivideWidth(double width, double padding) {
  return Container(
    height: 0.5,
    width: width,
    margin: EdgeInsets.only(left: padding, right: padding),
    color: Color(0xffE5E5E5),
  );
}

Widget loadingItem({bool needBackground = false}) {
林生雨's avatar
林生雨 committed
116 117 118 119 120 121 122 123 124 125 126 127 128
//  return
//    Center(
//      child: Container(
//    width: 77,
//    height: 77,
//    decoration: BoxDecoration(
//        borderRadius: BorderRadius.circular(8),
//        color: needBackground ? Colors.black : Colors.transparent),
//    alignment: Alignment.center,
//    child: MyCupertinoActivityIndicator(
//      backColor: needBackground ? Colors.white : Colors.black,
//    ),
//  ));
林生雨's avatar
林生雨 committed
129
  return Center(
林生雨's avatar
林生雨 committed
130 131 132 133 134
    child: Container(
      width: 80,
      height: 80,
      child: Lottie.asset("assets/smart_refresh_header.json",
          repeat: true, reverse: false),
林生雨's avatar
林生雨 committed
135
    ),
林生雨's avatar
林生雨 committed
136
  );
林生雨's avatar
林生雨 committed
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
}

Widget netErrorItem() {}

Widget errorItem(VoidCallback retry, {String errorText, String retryText}) {
  return Container(
      width: SCREENWIDTH,
      height: SCREENHEIGHT,
      color: Colors.white,
      alignment: Alignment.center,
      child: Container(
          height: SCREENHEIGHT,
          child: Container(
            margin: EdgeInsets.only(top: 70),
            width: 175,
            height: 249,
            child: Stack(
              children: <Widget>[
                Positioned(
                  left: 0,
                  top: 0,
                  child: Container(
                    width: 175,
                    height: 199,
                    child: Image.asset("assets/error.png"),
                  ),
                ),
                Positioned(
                  left: 0,
                  top: 166,
                  child: Container(
                    width: 175,
                    alignment: Alignment.center,
                    child: baseText(errorText ?? "网络错误", 15, Color(0xff666666)),
                  ),
                ),
                Positioned(
                  top: 216,
                  left: 12,
                  child: Container(
                    width: 150,
                    height: 33,
                    decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(22.5),
                        color: Color(0xff51CDC7)),
                    alignment: Alignment.center,
                    child: baseText(retryText ?? "重新加载", 16, Colors.white),
                  ).gestureDetector(() {
                    retry();
                  }),
                )
              ],
            ),
          )));
}
//TODO

Widget refreshViewTop(RefreshController refreshController, VoidCallback refresh,
    Widget topFix, Widget List) {
  return SmartRefresher(
      enablePullDown: true,
      enablePullUp: false,
      header: WaterDropMaterialHeader(
        backgroundColor: Color.fromARGB(255, 236, 236, 236),
      ),
      controller: refreshController,
      onRefresh: refresh,
      child: CustomScrollView(
        slivers: <Widget>[
          SliverToBoxAdapter(
            child: topFix,
          ),
          List
        ],
      ));
}

Widget refreshViewbottom(RefreshController refreshController,
    VoidCallback refresh, Widget topFix, Widget List) {
  return SmartRefresher(
      enablePullDown: true,
      enablePullUp: false,
      header: WaterDropMaterialHeader(
        backgroundColor: Color.fromARGB(255, 236, 236, 236),
      ),
      controller: refreshController,
      onRefresh: refresh,
      child: CustomScrollView(
        slivers: <Widget>[
          List,

//          SliverToBoxAdapter(
//            child: topFix,
//          ),
        ],
      ));
}

Widget baseTextField(TextEditingController editingController,
    TextInputType inputType, String hintText) {
  return TextField(
    cursorColor: Color(0xff20BDBB),
    style: TextStyle(fontSize: 14),
    decoration: InputDecoration(
      hintText: hintText,
      hintStyle: TextStyle(fontSize: 14, color: Color(0xffCCCCCC)),
      isDense: true,
      border: InputBorder.none,
      contentPadding:
          const EdgeInsets.symmetric(horizontal: 0.0, vertical: 17.0),
    ),
    maxLines: 1,
    enableInteractiveSelection: true,
    autocorrect: false,
    autofocus: true,
    keyboardType: inputType,
    controller: editingController,
    minLines: 1,
  );
}

Widget baseRedPoint(int num) {
  return Container(
    alignment: Alignment.center,
    width: 15,
    height: 15,
林生雨's avatar
林生雨 committed
263
    decoration: BoxDecoration(shape: BoxShape.circle, color: Color(0xffFF5963)),
林生雨's avatar
林生雨 committed
264 265 266
    child: baseText("${num}", 11, Color(0xffFFFFFF)),
  );
}
林生雨's avatar
林生雨 committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283

Widget baseRefreshView(RefreshController refreshController,
    VoidCallback refresh, Widget topFix, Widget List,
    {bool pullUp = false,
    bool pullDown = true,
    VoidCallback onLoading,
    ScrollController scrollController,
    CustomScrollView customScrollView}) {
  return SmartRefresher(
      enablePullDown: pullDown,
      enablePullUp: pullUp,
      onLoading: onLoading ?? () {},
      header: normalRefreshHeader(),
      controller: refreshController,
      onRefresh: refresh,
      footer: CustomFooter(
        builder: (BuildContext context, LoadStatus mode) {
林生雨's avatar
林生雨 committed
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
          Widget body = Container();
//          print("LOAD STATUE ${mode}");
//          if (mode == LoadStatus.idle) {
//            body = baseText("上拉加载更多", 12, Color(0xff545454));
//          } else if (mode == LoadStatus.loading) {
//            body = baseText("加载中", 12, Color(0xff545454));
//          } else if (mode == LoadStatus.failed) {
//            body = baseText("加载失败", 12, Color(0xff545454));
//          } else if (mode == LoadStatus.noMore) {
//            body = baseText("没有更多数据了", 12, Color(0xff545454));
//          }
//          else {
//            body = Container();
//          }
          if (mode == LoadStatus.loading) {
            body = Lottie.asset("assets/smart_refresh_header.json",
                repeat: true, reverse: false);
林生雨's avatar
林生雨 committed
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322
          }
          return Container(
            height: 55.0,
            child: Center(child: body),
          );
        },
      ),
      child: customScrollView ??
          CustomScrollView(
            controller: scrollController,
            slivers: <Widget>[
              SliverToBoxAdapter(
                child: topFix,
              ),
              List,
            ],
          ));
}

Widget normalRefreshHeader() {
  return CustomHeader(
    builder: (BuildContext context, RefreshStatus mode) {
林生雨's avatar
林生雨 committed
323
      Widget body = Container();
林生雨's avatar
林生雨 committed
324 325 326 327
//          if (mode == RefreshStatus.idle) {
//
//          } else
      if (mode == RefreshStatus.refreshing) {
林生雨's avatar
林生雨 committed
328 329 330 331 332 333 334 335
//        body = ImagesAnimation(
//            w: 46,
//            h: 15,
//            durationSeconds: 1500,
//            entry: ImagesAnimationEntry(1, 20, "assets/ptr_header_loading"));

        body = Lottie.asset("assets/smart_refresh_header.json",
            repeat: true, reverse: false);
林生雨's avatar
林生雨 committed
336 337 338 339 340
      }
//            else if (mode == RefreshStatus.failed) {
//            body = Text("Load Failed!Click retry!");
//          }
      else {
林生雨's avatar
林生雨 committed
341 342 343 344 345
//        body = Image.asset(
//          "assets/ptr_header_loading01.png",
//          width: 46,
//          height: 15,
//        );
林生雨's avatar
林生雨 committed
346 347 348 349 350 351 352 353
      }
      return Container(
        height: 55.0,
        child: Center(child: body),
      );
    },
  );
}
林生雨's avatar
林生雨 committed
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372

Widget emptyItem({String detail}) {
  return Column(
    mainAxisSize: MainAxisSize.min,
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
      Container(
        height: 210,
        width: 210,
        color: Colors.red,
      ),
      Container(
        margin: EdgeInsets.only(top: 8),
        child: baseText(
            detail == null ? "暂无消息,找人聊聊去" : detail, 15, Color(0xff9B9B9B)),
      ),
    ],
  );
}