import 'dart:io';

import 'package:cached_network_image/cached_network_image.dart';
import 'package:chat/data/UserData.dart';
import 'package:chat/data/WebData.dart';
import 'package:chat/data/constants.dart';
import 'package:chat/generated/i18n.dart';
import 'package:chat/home/VerificationCenter.dart';
import 'package:chat/home/VipPage.dart';
import 'package:chat/home/realtimehelper/translation_evaluation_dialog.dart';
import 'package:chat/home/realtimehelper/translation_order_push_dialog.dart';
import 'package:chat/models/group_info_model.dart';
import 'package:chat/photo/ui/dialog/not_permission_dialog.dart';
import 'package:chat/utils/LoadingDialog.dart';
import 'package:chat/utils/TokenMgr.dart';
import 'package:chat/utils/msgHandler.dart';
import 'package:chat/utils/screen.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/services.dart';
import 'package:oktoast/oktoast.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:url_launcher/url_launcher.dart';
import 'dart:ui' as ui;
import '../r.dart';
import 'HttpUtil.dart';
import 'PicSwiper.dart';
import 'TutorialOverlay.dart';
import 'app_navigator.dart';
import 'conversation_table.dart';
import 'count_down_button.dart';

class NoKeyboardEditableTextFocusNode extends FocusNode {
//  @override
//  bool consumeKeyboardToken() {
//    return false;
//  }
}

class CustomUI {
  static Widget buildPageLoading(
      BuildContext context, Widget content, bool isShow) {
    return Stack(
      children: <Widget>[
        content,
        isShow
            ? Scaffold(
                backgroundColor: Colors.transparent,
                body: LoadingDialog(),
              )
            : Container(),
      ],
    );
  }

  static void showContentDialog(
      BuildContext context, int programId, int replyId, int type, callback,
      {int replyUserId = 0,
      String replyUserName = '',
      bool isAd = false,
      bool isMyself = false}) {
    if (UserData().isMan() && !UserData().isVip && !isMyself) {
      CustomUI.buildOneConfirm(
          context, I18n.of(context).cant_comment, I18n.of(context).joinvip, () {
        Navigator.of(context).pop();
        Navigator.of(context).push(
          new MaterialPageRoute(
            builder: (context) {
              return VipPage();
            },
          ),
        );
      });
      return;
    }
    if (!UserData().isMan() && !UserData().basicInfo.isAttestation) {
      buildNotTrue(context);
      return;
    }

    Navigator.of(context).push(TutorialOverlay(
        child: Scaffold(
            backgroundColor: Constants.BlackTextColor.withOpacity(0.0),
            body: buildInput(context, programId, replyId, type, callback,
                replyUserId: replyUserId,
                replyUserName: replyUserName,
                isAd: isAd,
                isMyself: isMyself))));
  }

  static Widget buildInput(
      BuildContext context, int programId, int replyId, int type, callback,
      {int replyUserId = 0,
      String replyUserName = '',
      bool isAd: false,
      bool isMyself: false}) {
    print('replyUserName $replyUserName');
    var content = '';
    var hitStr = isMyself
        ? I18n.of(context).everyone_comment
        : I18n.of(context).your_comment;
    Widget input = Container(
      alignment: Alignment.topCenter,
      padding: EdgeInsets.only(left: 10, right: 10, bottom: 2),
      color: Colors.white,
      child: Row(
        children: <Widget>[
          Flexible(
            child: Container(
                margin: EdgeInsets.only(bottom: 10, right: 10),
                decoration: BoxDecoration(
                    border: Border(
                        bottom: BorderSide(color: const Color(0xFF0368FF)))),
                child: TextField(
                  keyboardAppearance: Brightness.light,
                  maxLines: 3,
                  minLines: 1,
                  style: TextStyle(textBaseline: TextBaseline.alphabetic),
                  autofocus: true,
                  inputFormatters: <TextInputFormatter>[
                    LengthLimitingTextInputFormatter(30) //限制长度
                  ],
                  decoration: new InputDecoration(
                    hintText: hitStr,
                    hintMaxLines: 1,
                    hintStyle: TextStyle(fontSize: 15),
                    border: InputBorder.none,
                  ),
                  onChanged: (str) {
                    content = str;
                  },
                )),
          ),
          RaisedButton(
            color: const Color(0xFF0368FF),
            child: Text(
              I18n.of(context).send,
              textScaleFactor: 1.0,
              style: TextStyle(color: Colors.white),
            ),
            onPressed: () async {
              content = content.trim();
              if (content == '' || content == null) {
                return;
              }
              if (isAd) {
                Map rdata = {
                  "userId": UserData().basicInfo.userId,
                  "adId": programId,
                };
                rdata['sign'] = TokenMgr().getSign(rdata);
                rdata['content'] = content;

                Response res = await HttpUtil().post(
                    'adActivity/reply/evaluate',
                    data: rdata,
                    isShowLoading: true);
                var resData = res.data;
                var data = {
                  'Pid': resData['data'],
                  'UserId': UserData().basicInfo.userId,
                  'NickName': UserData().basicInfo.nickName,
                  'Type': type,
                  'ReplyUserId': replyUserId,
                  'ReplyNickName': replyUserName,
                  'Content': content
                };
                showToast(resData['msg']);
                if (resData['code'] == 0) {
                  Navigator.of(context).pop();
                  callback(data);
                }
              } else {
                Map rdata = {
                  "userId": UserData().basicInfo.userId,
                  "id": programId,
                  "type": type,
                };
                rdata['sign'] = TokenMgr().getSign(rdata);
                rdata['content'] = content;
                rdata['replyId'] = replyId;
                Response res = await HttpUtil().post('station/reply/comment',
                    data: rdata, isShowLoading: true);
                var resData = res.data;
                print('station/reply/comment $resData');
                var data = {
                  'Pid': resData['data'],
                  'UserId': UserData().basicInfo.userId,
                  'NickName': UserData().basicInfo.nickName,
                  'Type': type,
                  'ReplyUserId': replyUserId,
                  'ReplyNickName': replyUserName,
                  'Content': content
                };
                showToast(resData['msg']);
                if (resData['code'] == 0) {
                  Navigator.of(context).pop();
                  callback(data);
                }
              }
            },
          )
        ],
      ),
    );
    Widget button = Expanded(
      child: InkWell(
        highlightColor: Colors.transparent,
        radius: 0,
        onTap: () {
          Navigator.pop(context);
        },
      ),
    );
    return Column(
      mainAxisAlignment: MainAxisAlignment.end,
      children: <Widget>[
        button,
        input,
      ],
    );
  }

  static void buildNotTrue(BuildContext context) {
    buildOneConfirm(context, I18n.of(context).after_authenticate,
        I18n.of(context).authenticate_now, () {
      Navigator.pop(context);
      Navigator.of(context).push(
        new MaterialPageRoute(
          builder: (context) {
            return VerificationCenterPage();
          },
        ),
      );
    });
  }

  static Widget buildCancleBotton(title, callback) {
    return InkWell(
      onTap: callback,
      child: Container(
          decoration: BoxDecoration(
              color: const Color(0XFFC7E5FF),
              borderRadius: BorderRadius.all(
                  Radius.circular(Constants.LittleButtonRadius))),
          margin: EdgeInsets.only(top: 0, bottom: 18.5),
          height: 37.5,
          width: 200,
          alignment: Alignment.center,
          child: fixedText(
            title,
            fontSize: 15,
            color: const Color(0xFF5781A6),
          )),
    );
  }

  static Widget _buildContentTip(tipTitle) {
    return tipTitle == ''
        ? Container()
        : Container(
            padding: EdgeInsets.only(top: 38.5, bottom: 31.5),
            child: Text(
              tipTitle,
              textScaleFactor: 1.0,
              style: TextStyle(
                  fontSize: 14, color: Constants.BlackTextColor, height: 1.30),
              textAlign: TextAlign.center,
            ));
  }

  static Widget buildConfirmContent(tip, content) {
    return Container(
      padding: EdgeInsets.only(left: 40, right: 40),
      child: Column(
        children: <Widget>[tip, content],
      ),
    );
  }

  static Widget buildImgLoding(context, url) {
    return Center(
        child: CircularProgressIndicator(
            valueColor: AlwaysStoppedAnimation(Constants.BlueTextColor)));
  }

  static Widget buildConfirmBotton(title, callback) {
    return InkWell(
      onTap: callback,
      child: Container(
          decoration: Constants.ConfirmBUttonBoxDecoration,
          height: 37.5,
          width: 200,
          alignment: Alignment.center,
          child: fixedText(
            title,
            fontSize: 15,
            color: Colors.white,
          )),
    );
  }

  static void buildOneConfirm(
      BuildContext context, String tipTitle, String buttonTitle, callback,
      {title = '', failcallbak}) {
    var confirm = buildConfirmBotton(buttonTitle, callback);
    buildTip(context, title,
        buildConfirmContent(_buildContentTip(tipTitle), confirm),
        failcallbak: failcallbak);
  }

  static void buildContacts(
      BuildContext context, String tipTitle, String buttonTitle, callback,
      {title = '', failcallbak}) {
    var confirm = buildConfirmBotton(buttonTitle, callback);
    buildTip(
        context,
        title,
        buildConfirmContent(
            Container(
                alignment: Alignment.center,
                padding: EdgeInsets.only(top: 38.5, bottom: 31.5),
                child: Column(
                  children: <Widget>[
                    Text(
                      tipTitle,
                      textScaleFactor: 1.0,
                      style: TextStyle(
                          fontSize: 14,
                          color: Constants.BlackTextColor,
                          height: 1.30),
                      textAlign: TextAlign.center,
                    ),
                    SizedBox(
                      height: 5,
                    ),
                    GestureDetector(
                      child: Text(
                        I18n.of(context).privacy,
                        style: TextStyle(color: Colors.blue, fontSize: 14),
                      ),
                      onTap: () {
                        launch(
                            'http://datechatagent.chengyouhd.com/zh-CN/Home/Privacy?language=${UserData().language}');
                      },
                    )
                  ],
                )),
            confirm),
        failcallbak: failcallbak);
  }

  static Widget buildNoData(BuildContext context, {String str, double height}) {
    if (height == null) {
      height = MediaQuery.of(context).size.height * 0.8;
    }
    return Container(
        width: MediaQuery.of(context).size.width,
        height: height,
        alignment: Alignment.center,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
                child: Icon(
              IconData(
                0xe869,
                fontFamily: 'iconfont',
              ),
              size: 60,
              color: Constants.BlueTextColor,
            )),
            Container(
                alignment: Alignment.center,
                child: fixedText(str != null ? str : I18n.of(context).no_data,
                    color: Constants.BlueTextColor)),
          ],
        ));
  }

  static Widget buildImgCover(
      int imgId,
      List<PicSwiperItem> pics,
      String imgUrl,
      double width,
      double raduis,
      bool isWatch,
      BuildContext context,
      int type,
      {bool isMyself = false,
      int payStatus = 0,
      int state = 1}) {
    Color color = isWatch
        ? const Color(0xFF999999)
        : const Color(0xFFFB5656); //const Color(0xfffb5656);

    String bottomStr = '';
    if (type == PhotoType.money.index) {
      bottomStr = I18n.of(context).red_photo;
    } else if (type == PhotoType.destroyMoney.index) {
      bottomStr = I18n.of(context).red_photo; //I18n.of(context).red_photo1;
    } else if (type == PhotoType.destroy.index) {
      bottomStr =
          isWatch ? I18n.of(context).destroyed : I18n.of(context).destroy_after;
    }

    double opacity = 0.5;

    Widget normalCover = isMyself && state == 0
        ? Positioned(
            right: 5,
            top: 5,
            child: Container(
              alignment: Alignment.center,
              width: width,
              height: width,
              decoration: BoxDecoration(
                  color: Colors.black.withOpacity(opacity),
                  borderRadius: BorderRadius.all(Radius.circular(raduis - 2))),
              child: Text(I18n.of(context).reviewing,
                  textAlign: TextAlign.center,
                  textScaleFactor: 1.0,
                  style: TextStyle(fontSize: 12, color: Colors.white)),
            ),
          )
        : Container(
            width: width,
            height: width,
            decoration: BoxDecoration(
                border: Border.all(color: Colors.grey[300], width: 1),
                borderRadius: BorderRadius.circular(raduis)),
          );

    return InkWell(
        onTap: () {
          Navigator.of(context).push(
            new MaterialPageRoute(
              builder: (context) {
                return PicSwiper(
                  id: imgId,
                  pics: pics,
                );
              },
            ),
          );
        },
        child: Stack(
          alignment: Alignment.center,
          children: <Widget>[
            Container(
                decoration:
                    BoxDecoration(borderRadius: BorderRadius.circular(2.0)),
                width: width,
                height: width,
                margin: EdgeInsets.all(5),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(raduis),
                  child: CachedNetworkImage(
                    imageUrl: imgUrl == null ? "" : imgUrl,
                    placeholder: CustomUI.buildImgLoding,
                    fit: BoxFit.cover,
                  ),
                )),
            (type == PhotoType.free.index ||
                    (!isMyself &&
                        type == PhotoType.money.index &&
                        payStatus == 1))
                ? normalCover
                : Stack(
                    alignment: Alignment.center,
                    children: <Widget>[
                      Container(
                        width: width,
                        height: width,
                        decoration: BoxDecoration(
                          border: Border.all(color: color, width: 1),
                          borderRadius: BorderRadius.circular(raduis),
                        ),
                        margin: EdgeInsets.all(5),
                        child: ClipRRect(
                            borderRadius: BorderRadius.circular(raduis),
                            child: BackdropFilter(
                              //背景滤镜器
                              filter: ui.ImageFilter.blur(
                                  sigmaX: 10.0,
                                  sigmaY: 10.0), //图片模糊过滤，横向竖向都设置5.0
                              child: Opacity(
                                //透明控件
                                opacity: isMyself ? 0 : 0.5,
                                child: Container(
                                  decoration: BoxDecoration(
                                    border: Border.all(color: color, width: 0),
                                    borderRadius: BorderRadius.circular(0),
                                  ),
                                  alignment: Alignment.center,
                                ),
                              ),
                            )),
                      ),
                      isMyself && state == 0
                          ? Positioned(
                              right: 6,
                              top: 6,
                              child: Container(
                                alignment: Alignment.center,
                                width: width - 2,
                                height: width - 2,
                                decoration: BoxDecoration(
                                    color: Colors.black.withOpacity(opacity),
                                    borderRadius: BorderRadius.all(
                                        Radius.circular(raduis - 1))),
                                child: Text(I18n.of(context).reviewing,
                                    textScaleFactor: 1.0,
                                    style: TextStyle(
                                        fontSize: 12, color: Colors.white)),
                              ),
                            )
                          : Text(''),
                      Positioned(
                        left: 0,
                        top: 0,
                        child: Container(
                          width: 18,
                          height: 18,
                          margin: EdgeInsets.all(5),
                          decoration: BoxDecoration(
                              color: color,
                              borderRadius: BorderRadius.only(
                                  topLeft: Radius.circular(raduis),
                                  bottomRight: Radius.circular(raduis))),
                          child: Icon(
                            IconData(
                              type == PhotoType.money.index ? 0xe632 : 0xe634,
                              fontFamily: 'iconfont',
                            ),
                            color: Colors.white,
                            size: 15,
                          ),
                        ),
                      ),
                      Positioned(
                          bottom: 6,
                          child: Container(
                            width: width - 2,
                            padding: EdgeInsets.only(
                                bottom: 1, top: 2, left: 5, right: 5),
                            decoration: isMyself
                                ? BoxDecoration(
                                    color: Colors.red.withOpacity(0.7),
                                    borderRadius: BorderRadius.only(
                                        bottomLeft: Radius.circular(raduis - 1),
                                        bottomRight:
                                            Radius.circular(raduis - 1)))
                                : BoxDecoration(),
                            child: Text(bottomStr,
                                textScaleFactor: 1.0,
                                textAlign: TextAlign.center,
                                style: TextStyle(
                                    color: isMyself ? Colors.white : color,
                                    fontSize: 10)),
                          )),
                    ],
                  ),
          ],
        ));
  }

  static void buildTowConfirm(
      BuildContext context,
      String tipTitle,
      String confirmButtonTitle,
      confirmCallback,
      cancleButtonTitle,
      cancleCallback,
      {title = ''}) {
    var confirm = buildConfirmBotton(confirmButtonTitle, confirmCallback);
    var cancle = buildCancleBotton(cancleButtonTitle, cancleCallback);
    buildTip(
        context,
        title,
        buildConfirmContent(
            _buildContentTip(tipTitle),
            Column(
              children: <Widget>[cancle, confirm],
            )));
  }

  static Widget buildTipContent(
      BuildContext context, String tips, Widget content,
      {failcallbak}) {
    return Container(
        child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
          Stack(
            children: <Widget>[
              Container(
                padding: EdgeInsets.only(bottom: 25),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(10.0)),
                width: MediaQuery.of(context).size.width * 0.91,
                child: Column(
                  children: <Widget>[
                    tips == ''
                        ? Container()
                        : Container(
                            margin:
                                EdgeInsets.only(top: 15.5, left: 40, right: 40),
                            padding: EdgeInsets.only(bottom: 10.5),
                            decoration: BoxDecoration(
                                border: Border(
                                    bottom: BorderSide(
                                        color: Constants.DividerLineColor))),
                            alignment: Alignment.center,
                            child: Text(
                              tips,
                              textScaleFactor: 1.0,
                              style: TextStyle(
                                  color: Constants.BlackTextColor,
                                  fontSize: 16.5,
                                  fontWeight: FontWeight.w400),
                              textAlign: TextAlign.center,
                            ),
                          ),
                    content
                  ],
                ),
              ),
              Positioned(
                  top: -40,
                  right: 0,
                  child: InkWell(
                      highlightColor: Colors.transparent,
                      radius: 0,
                      onTap: () {
                        Navigator.of(context).pop();
                        if (failcallbak != null) failcallbak();
                      },
                      child: Container(
                        width: 40,
                        height: 40,
                        alignment: Alignment.center,
                        margin: EdgeInsets.only(top: 36.5),
                        decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(50.0)),
                        child: Icon(
                          // IconData(
                          //   0xe679,
                          //   fontFamily: 'iconfont',
                          // ),
                          Icons.close,
                          color: Colors.grey[700],
                          size: 24,
                        ),
                      )))
            ],
          )
        ]));
    // return Container(
    //     child: Column(
    //         mainAxisAlignment: MainAxisAlignment.center,
    //         children: <Widget>[
    //       Container(
    //         padding: EdgeInsets.only(bottom: 25),
    //         alignment: Alignment.center,
    //         decoration: BoxDecoration(
    //             color: Colors.white, borderRadius: BorderRadius.circular(10.0)),
    //         width: MediaQuery.of(context).size.width * 0.91,
    //         child: Column(
    //           children: <Widget>[
    //             tips == ''
    //                 ? Container()
    //                 : Container(
    //                     margin: EdgeInsets.only(top: 15.5, left: 40, right: 40),
    //                     padding: EdgeInsets.only(bottom: 10.5),
    //                     decoration: BoxDecoration(
    //                         border: Border(
    //                             bottom: BorderSide(
    //                                 color: Constants.DividerLineColor))),
    //                     alignment: Alignment.center,
    //                     child: Text(
    //                       tips,
    //                       textScaleFactor: 1.0,
    //                       style: TextStyle(
    //                           color: Constants.BlackTextColor,
    //                           fontSize: 16.5,
    //                           fontWeight: FontWeight.w400),
    //                       textAlign: TextAlign.center,
    //                     ),
    //                   ),
    //             content
    //           ],
    //         ),
    //       ),
    //       InkWell(
    //           highlightColor: Colors.transparent,
    //           radius: 0,
    //           onTap: () {
    //             Navigator.of(context).pop();
    //             if (failcallbak != null) failcallbak();
    //           },
    //           child: Container(
    //             width: 40,
    //             height: 40,
    //             alignment: Alignment.center,
    //             margin: EdgeInsets.only(top: 36.5),
    //             decoration: BoxDecoration(
    //                 color: Colors.white,
    //                 borderRadius: BorderRadius.circular(50.0)),
    //             child: Icon(
    //               IconData(
    //                 0xe679,
    //                 fontFamily: 'iconfont',
    //               ),
    //               size: 20,
    //             ),
    //           ))
    //     ]));
  }

  static void buildTip(BuildContext context, String tips, Widget content,
      {failcallbak}) {
    Navigator.of(context).push(TutorialOverlay(
        child:
            buildTipContent(context, tips, content, failcallbak: failcallbak)));
  }

  static Future<bool> showIosDialog(BuildContext context, String title,
      Function sureFunction, Function cancelFunction) async {
    bool isDismiss = await showDialog(
        context: context,
        builder: (context) {
          return CupertinoAlertDialog(
            title: fixedText(title),
            actions: <Widget>[
              CupertinoDialogAction(
                  child: fixedText(I18n.of(context).determine),
                  onPressed: sureFunction),
              CupertinoDialogAction(
                  child: fixedText(I18n.of(context).cancel),
                  onPressed: cancelFunction),
            ],
          );
        });
    return isDismiss;
  }

  static Widget buildTopTip(double leftPadding, str,
      {double fontSize = 15, bool showStar = false}) {
    return Container(
      decoration: BoxDecoration(
          color: Colors.white,
          border: Border(bottom: Constants.GreyBorderSide)),
      margin: EdgeInsets.only(top: 20),
      padding: EdgeInsets.only(left: leftPadding, top: 8, bottom: 8),
      alignment: Alignment.centerLeft,
      child: Row(
        children: <Widget>[
          showStar
              ? Padding(
                  padding: EdgeInsets.only(top: 2, right: 2),
                  child: Text(
                    '*',
                    style: TextStyle(color: Colors.red),
                  ))
              : Text(''),
          Container(
            width: Screen.width - leftPadding * 2,
            child: Text(str,
                textScaleFactor: 1.0,
                style: TextStyle(
                    color: Constants.BlackTextColor,
                    fontSize: fontSize,
                    fontWeight: FontWeight.w500)),
          )
        ],
      ),
    );
  }

  static Widget buildAudioContaniner(double height) {
    return ClipRRect(
      borderRadius: BorderRadius.circular(2.5),
      child: Container(
        height: height,
        color: const Color(0xFF04A4FE),
        width: 5,
      ),
    );
  }

  static Widget buildBox(nums, str) {
    return Container(
      width: (Screen.width - 80) / 3,
      child: Column(
        children: <Widget>[
          Container(
            alignment: Alignment.center,
            margin: EdgeInsets.only(top: 10),
            width: 58.1,
            height: 24.85,
            decoration: BoxDecoration(
                color: nums > 0 ? Constants.BlueTextColor : Colors.grey[200],
                borderRadius:
                    BorderRadius.circular(Constants.LittleButtonRadius)),
            child: Text(
              nums > 99 ? '99+' : nums.toString(),
              textScaleFactor: 1.0,
              style: TextStyle(
                  fontSize: 17.76,
                  color: nums > 0 ? Colors.white : Colors.grey),
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 5),
            alignment: Alignment.center,
            child: Text(
              str,
              textScaleFactor: 1.0,
              style: TextStyle(color: Constants.BlackTextColor, fontSize: 12),
            ),
          ),
        ],
      ),
    );
  }

  static Future<bool> _willPop(BuildContext context, bool isForceUpdate) async {
    print('_willPop $isForceUpdate');
    if (isForceUpdate) {
      await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
    } else {
      Navigator.pop(context);
    }

    return null;
  }

  static void buildVersionUpdate(
      BuildContext context,
      String versionName,

      ///版本号
      bool isForceUpdate,

      ///强制升级
      String describe,

      ///版本描述
      ValueNotifier<String> updateProgress,

      ///进度更新
      Function go

      ///点击开始体验回调
      ) {
    Navigator.of(context).push(TutorialOverlay(
        child: WillPopScope(
            child: Container(
              alignment: Alignment.center,
              width: 296,
              child: Container(
                width: 296,
                height: 387,
                child: Stack(
                  children: <Widget>[
                    Positioned(
                        top: 10,
                        child: Container(
                            height: 307,
                            width: 296,
                            child: Column(
                              children: <Widget>[
                                SizedBox(
                                  height: 75,
                                ),
                                Container(
                                  padding: EdgeInsets.fromLTRB(20, 10, 20, 10),
                                  height: 161,
                                  width: 296,
                                  child: SingleChildScrollView(
                                    child: Text(
                                      describe ?? '',
                                      textAlign: TextAlign.left,
                                      style: TextStyle(
                                          fontSize: 15,
                                          fontWeight: FontWeight.w300),
                                    ),
                                  ),
                                ),
                                ValueListenableBuilder(
                                  builder: (BuildContext context, String value,
                                      Widget child) {
                                    return value == '-1'
                                        ? GestureDetector(
                                            onTap: go,
                                            child: Container(
                                              alignment: Alignment.center,
                                              width: 164,
                                              height: 40,
                                              child: Text(
                                                I18n.of(context).test_it,
                                                style: TextStyle(
                                                    fontWeight: FontWeight.w500,
                                                    color: Colors.white,
                                                    fontSize: 17),
                                              ),
                                              decoration: BoxDecoration(
                                                  color: Color(0xff3875E9),
                                                  borderRadius:
                                                      BorderRadius.all(
                                                          Radius.circular(
                                                              3.0))),
                                            ),
                                          )
                                        : Container(
                                            alignment: Alignment.center,
                                            width: 164,
                                            height: 40,
                                            child: Stack(
                                              children: <Widget>[
                                                SizedBox(
                                                  //限制进度条的高度
                                                  height: 40,
                                                  //限制进度条的宽度
                                                  width: 164,
                                                  child: ClipRRect(
                                                    borderRadius:
                                                        BorderRadius.all(
                                                            Radius.circular(
                                                                3.0)),
                                                    child:
                                                        LinearProgressIndicator(

                                                            //0~1的浮点数，用来表示进度多少;如果 value 为 null 或空，则显示一个动画，否则显示一个定值
                                                            value: double.parse(
                                                                    value) /
                                                                100,
                                                            //背景颜色
                                                            backgroundColor:
                                                                Color(
                                                                    0xff4E5D7A),
                                                            //进度颜色
                                                            valueColor:
                                                                new AlwaysStoppedAnimation<
                                                                        Color>(
                                                                    Color(
                                                                        0xff65A5FC))),
                                                  ),
                                                ),
                                                Container(
                                                  alignment: Alignment.center,
                                                  child: Text(
                                                    '$value %',
                                                    style: TextStyle(
                                                        fontWeight:
                                                            FontWeight.w500,
                                                        color: Colors.white,
                                                        fontSize: 19),
                                                  ),
                                                )
                                              ],
                                            ),
                                            decoration: BoxDecoration(
                                                color: Color(0xff3875E9),
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(3.0))),
                                          );
                                  },
                                  valueListenable: updateProgress,
                                )
                              ],
                            ),
                            decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(12)))),
                    Container(
                      height: 81,
                      child: Stack(
                        children: <Widget>[
                          Image.asset(
                            R.assetsImagesImgUpdateBg,
                            height: 81,
                          ),
                          Positioned.fill(
                              child: Align(
                            alignment: Alignment.center,
                            child: Text(
                              '${I18n.of(context).found_new} ($versionName)',
                              style:
                                  TextStyle(color: Colors.white, fontSize: 18),
                            ),
                          )),
                          Positioned.fill(
                              child: Offstage(
                            offstage: isForceUpdate,
                            child: Align(
                              alignment: Alignment.topRight,
                              child: Container(
                                width: 50,
                                height: 50,
                                child: GestureDetector(
                                  onTap: () {
                                    Navigator.of(context).pop();
                                  },
                                  child: Icon(
                                    IconData(
                                      0xe679,
                                      fontFamily: 'iconfont',
                                    ),
                                    size: 16,
                                    color: Color(0xffa4c1fe),
                                  ),
                                ),
                              ),
                            ),
                          ))
                        ],
                      ),
                    )
                  ],
                ),
              ),
            ),
            onWillPop: () => _willPop(context, isForceUpdate))));
  }

  ///访问相册权限
  static Future<bool> showPhotoPermissionSetting(BuildContext context) async {
    return showPermissionSetting(
        context,
        Platform.isAndroid ? PermissionGroup.storage : PermissionGroup.photos,
        Platform.isAndroid
            ? I18n.of(context).location_permission
            : I18n.of(context).photo_permission);
  }

  ///权限申请被拒后 弹窗提示到设置界面打开
  static Future<bool> showPermissionSetting(BuildContext context,
      PermissionGroup permissionGroup, String tips) async {
    final PermissionStatus addStatus =
        await PermissionHandler().checkPermissionStatus(permissionGroup);
    print('check :$permissionGroup addStatus: $addStatus');
    if (addStatus == PermissionStatus.granted) {
      return true;
    } else {
      ///   ios第一次-发起询问权限  ||  android 第一次发起请求或者被拒过
      if (addStatus == PermissionStatus.unknown ||
          (addStatus == PermissionStatus.denied && Platform.isAndroid)) {
        Map<PermissionGroup, PermissionStatus> permissionRequestResult =
            await PermissionHandler().requestPermissions([permissionGroup]);

        PermissionStatus status = permissionRequestResult[permissionGroup];
        print('status: $status');
        if (status == PermissionStatus.granted) {
          return true;
        } else {
          var result = await showDialog(
            context: context,
            builder: (ctx) => NotPermissionDialog(tips),
          );
          if (result == true) {
            PermissionHandler().openAppSettings();
          }

          return false;
        }
      } else {
        ///被用户禁用，所以弹窗去设置打开权限
        var result = await showDialog(
          context: context,
          builder: (ctx) => NotPermissionDialog(tips),
        );
        if (result == true) {
          PermissionHandler().openAppSettings();
        }

        return false;
      }
    }
  }

  goScanPage(BuildContext context) async {
    if (await CustomUI.showPermissionSetting(
        context, PermissionGroup.camera, I18n.of(context).camera_permission)) {
      AppNavigator.pushScannerPage(context);
    }
  }

  getSearchResult(String searchKey, List<FriendModel> sourceList) {
    List<FriendModel> res = [];
    for (var i = 0; i < sourceList.length; i++) {
      var friendModel = sourceList[i];
      if ((friendModel.refName != null &&
              friendModel.refName.contains(searchKey)) ||
          friendModel.name.contains(searchKey)) {
        res.add(friendModel);
      }
    }
    return res;
  }

  getGroupSearchResult(
      String searchKey, List<GroupInfoModel> sourceList, Map refMap) {
    List<GroupInfoModel> res = [];
    for (var i = 0; i < sourceList.length; i++) {
      var groupModel = sourceList[i];
      if ((groupModel.name.contains(searchKey)) ||
          groupModel.getGroupName(refMap).contains(searchKey)) {
        res.add(groupModel);
      }
    }
    return res;
  }

  static Widget buildLoaingAnim(BuildContext context,
      {String str, double height}) {
    if (height == null) {
      height = MediaQuery.of(context).size.height * 0.8;
    }
    return Container(
        width: MediaQuery.of(context).size.width,
        height: height,
        alignment: Alignment.topCenter,
        child: Container(
          width: 40,
          height: 40,
          margin: EdgeInsets.only(top: 20),
          padding: EdgeInsets.all(10),
          decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.white,
              boxShadow: [BoxShadow(blurRadius: 3.0, color: Colors.black26)]),
          child: new CircularProgressIndicator(
            strokeWidth: 2,
          ),
        ));
  }

  static Widget buildLoadingFooter() {
    return CustomFooter(
      builder: (BuildContext context, LoadStatus mode) {
        Widget body = Container();
        if (mode == LoadStatus.idle) {
          //body = Text("pull up load");
        } else if (mode == LoadStatus.loading) {
          body = CupertinoActivityIndicator();
        } else if (mode == LoadStatus.failed) {
          //body = Text("Load Failed!Click retry!");
        } else if (mode == LoadStatus.canLoading) {
          //body = Text("release to load more");
        } else {
          //body = Text("No more Data");
        }
        return Container(
          //height: 50.0,
          child: Center(child: body),
        );
      },
    );
  }

  static PreferredSizeWidget buildSearchButton(BuildContext context, callback,
      {double bottom = 14}) {
    return PreferredSize(
      preferredSize: Size.fromHeight(49),
      child: InkWell(
          onTap: callback,
          child: Container(
              alignment: Alignment.center,
              margin: EdgeInsets.only(bottom: bottom, left: 12.5, right: 12.5),
              height: 35,
              decoration: BoxDecoration(
                  color: const Color(0xFFEEEEEE),
                  borderRadius: BorderRadius.all(Radius.circular(8))),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.only(left: 15, right: 15, bottom: 0),
                    child: Icon(
                      IconData(
                        0xe664,
                        fontFamily: Constants.IconFontFamily,
                      ),
                      color: const Color(0xFFA0A0A0),
                      size: 18,
                    ),
                  ),
                  Container(
                      margin: EdgeInsets.only(bottom: 0),
                      child: Text(I18n.of(context).search,
                          style:
                              TextStyle(fontSize: 14.5, color: Colors.grey))),
                ],
              ))),
    );
  }

  static Widget buildCustomLeading(BuildContext context,
      {onTap, double iconPadding = 10}) {
    return InkWell(
      onTap: onTap == null
          ? () {
              Navigator.of(context).pop();
            }
          : onTap,
      child: Container(
          margin:
              EdgeInsets.only(top: 2, left: iconPadding, right: iconPadding),
          child: Image.asset(
            'assets/images/back.png',
            scale: 2,
          )),
    );
  }

  static Widget buildImageLabel(String url, int nums,
      {bool isLeft = true, double imgOpc = 0.6, double imgHeight = 14}) {
    double radius = 2.75;
    return Container(
      margin: EdgeInsets.only(top: 16, bottom: 14),
      height: 18.5,
      constraints: BoxConstraints(minWidth: 30),
      decoration: BoxDecoration(
          color: const Color(0xFFF0F0F0),
          borderRadius: isLeft
              ? BorderRadius.only(
                  topLeft: Radius.circular(radius),
                  bottomLeft: Radius.circular(radius))
              : BorderRadius.only(
                  topRight: Radius.circular(radius),
                  bottomRight: Radius.circular(radius))),
      child: Row(
        children: <Widget>[
          Container(
            margin: EdgeInsets.only(top: 2.5, bottom: 2.5),
            width: !isLeft ? 0.5 : 0,
            color: const Color(0xFFDEDEDE),
          ),
          Opacity(
              opacity: imgOpc,
              child: Container(
                  height: imgHeight,
                  margin: EdgeInsets.only(left: 5.5),
                  child: Image.asset(url))),
          Opacity(
              opacity: 0.8,
              child: Container(
                  margin: EdgeInsets.only(left: 7, right: 7),
                  child: Text(
                    nums.toString(),
                    style:
                        TextStyle(color: const Color(0xFF4C4C4C), fontSize: 12),
                  ))),
        ],
      ),
    );
  }

  ///** isUser 是否是用户，或为 翻译
  static void buildTranslationHelperOrderDialog(
      BuildContext context, bool isUser,
      {String orderId, int scenes = 0, String desc,Function userStartChat,int createTime}) {


    Navigator.of(context).push(TutorialOverlay(
      child:  TranslateOrderPushPage(isUser,orderId: orderId,scenes: scenes,desc: desc,userStartChat: userStartChat,createTime: createTime,),
    ));
  }

  static void buildTranslationEvaluationDialog(BuildContext context) {
    Navigator.of(context).push(TutorialOverlay(
      child: TravelEvaluationPage(),
    ));
  }

  static double getRealTextWidht(String text, double fontSize) {
    TextPainter _textPainter = TextPainter(
        maxLines: 2,
        text: TextSpan(
            text: text,
            style: TextStyle(fontSize: fontSize, color: Colors.black)),
        textDirection: TextDirection.ltr)
      ..layout();
    return _textPainter.width;
  }
}
