login_page_f.dart 44.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 74 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 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 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 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064


import 'dart:async';
import 'dart:convert';
import 'dart:io';

import 'package:common_utils/common_utils.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluwx/fluwx.dart';

import 'package:one_key/app.dart';
import 'package:one_key/constant/constant.dart';

import 'package:one_key/models/store_info.dart';
import 'package:one_key/net/dio_util.dart';
import 'package:one_key/provider/create_store_model.dart';
import 'package:one_key/provider/other_login_provider.dart';
import 'package:one_key/pages/login/huawei_login_view.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/route/navigate_service.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/dialog_util.dart';
import 'package:one_key/utils/utils.dart';
import 'package:one_key/widgets/MyDivider.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/loading.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';
import 'package:sign_in_with_apple/sign_in_with_apple.dart';
// import '../constant/constant.dart';

class LoginPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new LoginState();
  }
}

class LoginState extends State<LoginPage> with WidgetsBindingObserver {
  TextEditingController _sellerCodeController = TextEditingController();
  TextEditingController _accountController = TextEditingController();
  final TextEditingController _pwdController = TextEditingController();
  final ScrollController _scrollController = new ScrollController();

  final FocusNode _sellerCodeFocusNode = new FocusNode();
  final FocusNode _accountFocusNode = new FocusNode();
  final FocusNode _pwdFocusNode = new FocusNode();

  bool obscureText = true; //是否隐藏密码
  bool isActivate = false; //是否激活登录

  String errorText = ""; //错误提示

  bool _check = false;
  HuaweiLoginViewController? _huaweiLoginViewController;

  OtherLoginProvider? otherLoginProvider;
  late CreateStoreModel createStoreModel;
  Fluwx fluwx = Fluwx();

  Function(WeChatResponse)? responseListener;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    //第一次打开应用

    // _checkWechat();
    isLogin();
    WidgetsBinding.instance.addObserver(this);
    WidgetsBinding.instance.addPostFrameCallback((_) {
      final UserModel userModel =
          Provider.of<UserModel>(context, listen: false);
      if (userModel.user != null) {
        Future.delayed(Duration(milliseconds: 50), () {
          _sellerCodeController.text = userModel.user!.sellercode ?? "";
          _accountController.text = userModel.user!.account ?? "";
          // FocusScope.of(context).requestFocus(_pwdFocusNode);
        });
      }
    });
  }

  //当页面离开时要清除监听器
  @override
  void dispose() {
    _huaweiLoginViewController?.dispose();
    super.dispose();
    if (responseListener != null) {
      fluwx.removeSubscriber(responseListener!);
    }

    WidgetsBinding.instance.removeObserver(this);
  }

  //微信是否安装
  _checkWechat() async {
    // await registerWxApi(
    //     appId: "wx85aa3cdd0f791e65",
    //     doOnAndroid: true,
    //     doOnIOS: true,
    //     universalLink: "https://xt04.colorcun.com/link/OneKey/");

    var result = await fluwx.isWeChatInstalled;
    if (result) {
      App.isInstallWx = true;

      _getWxCode();
    } else {
      App.isInstallWx = false;
    }
    setState(() {});
    LogUtil.v("is installed $result");
  }

  handlePostFrame(_) {
    // _scrollController.jumpTo(_scrollController.position.maxScrollExtent);
  }

  @override
  void didChangeMetrics() {
    // TODO: implement didChangeMetrics
    WidgetsBinding.instance.addPostFrameCallback(handlePostFrame);
    super.didChangeDependencies();
  }

  //监听输入框,设置登录按钮状态
  setActivate() {
    if (_sellerCodeController.text.isNotEmpty &&
        _accountController.text.isNotEmpty &&
        _pwdController.text.isNotEmpty) {
      setState(() {
        errorText = "";
        isActivate = true;
      });
    } else {
      setState(() {
        errorText = "";
        isActivate = false;
      });
    }
  }

  //判断是否登录
  void isLogin() async {
    // UserModel userModel = Provider.of<UserModel>(context, listen: false);
    // userModel.initUser();
    if (App.sp!.getBool("isLogin") ?? false) {
      Future.delayed(Duration(milliseconds: 200), () {
        // NavigatorUtil.goHomePage(context);
        //获取登陆接口返回的vid 如果是14 极速版,则跳转至极速版
        //  if (user['sellerVersion'] == '14') {
        if (Constant.normalApp) {
          NavigatorUtil.goHomePage(context);
        } else {
          if (Provider.of<UserModel>(context, listen: false)
                  .user!
                  .sellerVersion ==
              '14') {
            NavigatorUtil.goHomePageSim(context);
          } else {
            NavigatorUtil.goHomePage(context);
          }
        }
      });
    } else {
      _checkWechat();
    }
  }

  ///微信登陆

  _wxLogin() {
    //去授权
    fluwx
        .authBy(
            which: NormalAuth(
          scope: 'snsapi_userinfo',
          state: 'wechat_sdk_demo_test',
        ))
        .then((data) {});
    // }
  }

  ///华为账号一键登录按钮
  _onHuaweiLoginViewCreated(HuaweiLoginViewController controller) {
    _huaweiLoginViewController = controller;
    controller.events.listen((event) {
      if (!mounted) return;
      final method = event['method']?.toString();
      switch (method) {
        case 'loginStart':
          setState(() {});
          break;
        case 'loginEnd':
          setState(() {});
          break;
        case 'agreementNotAccepted':
          _showHuaweiAgreementDialog();
          break;
        case 'loginSuccess':
          _handleHuaweiLoginResultFromNative(event['data']);
          break;
        case 'loginError':
          final err = event['data']?.toString() ?? '';
          print('HuaweiLoginError: $err');
          Utils.showToast('华为账号登录失败:$err');
          break;
        default:
          break;
      }
    });
    controller.setAgreementStatus(_check);
  }

  void _showHuaweiAgreementDialog() {
    if (_check) return;
    DialogUtil.openAlertDialogLogin(context, 530, onTap: () {
      if (Navigator.canPop(context)) {
        Navigator.pop(context);
      }
      setState(() {
        _check = true;
      });
      _huaweiLoginViewController?.setAgreementStatus(true);
      _huaweiLoginViewController?.continueLogin();
    });
  }

  void _handleHuaweiLoginResultFromNative(dynamic data) {
    Map<String, String> result = {};
    if (data is String && data.isNotEmpty) {
      try {
        final decoded = jsonDecode(data);
        if (decoded is Map) {
          decoded.forEach((key, value) {
            result[key.toString()] = value?.toString() ?? '';
          });
        }
      } catch (_) {}
    }
    _handleHuaweiLoginResult(result);
  }

  void _handleHuaweiLoginResult(Map<String, String> data) {
    String openId = data['openID'] ?? '';
    String unionId = data['unionID'] ?? '';
    if (unionId.isEmpty) {
      Utils.showToast('华为账号授权失败,请稍后重试');
      return;
    }
    App.sp!.setString('openid', openId);
    App.sp!.setString('unionid', unionId);
    String authorizationCode = data['authorizationCode'] ?? '';
    if (authorizationCode.isNotEmpty) {
      App.sp!.setString('huawei_authorization_code', authorizationCode);
    }
    String idToken = data['idToken'] ?? '';
    if (idToken.isNotEmpty) {
      App.sp!.setString('huawei_id_token', idToken);
    }

    createStoreModel.storeInfo = StoreInfo();
    NavigatorUtil.goIfNeedCreateStorePage(context);
  }

  ///获取微信登录code
  _getWxCode() {
    responseListener = (res) {
      if (res is WeChatAuthResponse && res.errCode == 0) {
        LogUtil.v("code:" + res.code!);
        // Loading.showLoading(context);
        _getAccessToken(res.code);
      } else {
//        Utils.showToast(res.errStr??"登录失败,请稍后重试");
      }
    };
    fluwx.addSubscriber(responseListener!);
  }

  //获取用户信息
  _getUserInfo(String? access_token, String? openid) async {
    Response response = await DioUtil.getInstance().getDio()!.get(
        "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid");
    LogUtil.v('userinfo:' + response.data);
    Map<String, dynamic> responseData = json.decode(response.data.toString());
    if (responseData["errcode"] != null) {
      App.sp!.setString("headImg", '');
//      Utils.showToast(responseData["errmsg"]??"登录,请稍后重试");
    } else {
      // App.sp.setString("nickName", responseData["nickname"]);
      App.sp!.setString("headImg", responseData["headimgurl"]);
    }
  }

  ///获取微信登录access_token
  _getAccessToken(String? code) async {
    Response response = await DioUtil.getInstance().getDio()!.get(
        "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx4d105e36a36a6139&secret=90ba794b30d2fe388309149174874603&code=$code&grant_type=authorization_code");
    LogUtil.v("access_token:${response.toString()}");
    Map<String, dynamic> responseData = json.decode(response.data.toString());
    if (responseData["errcode"] != null) {
      Utils.showToast(responseData["errmsg"] ?? "登录失败,请稍后重试");
      // Loading.hideLoading(context);
    } else {
      App.sp!.setString("openid", responseData["openid"]);
      App.sp!.setString("unionid", responseData["unionid"]);
      await _getUserInfo(
          responseData["access_token"], responseData["openid"]); //获取用户信息

      //跳转至手机号绑定页面
      //判断是否已经绑定手机号码  ******调用接口*******
      //有,通过手机号吗或者opened查找店铺信息进行登陆
      //没有,跳转至绑定手机号码页面
      // Map<String, String> params = {
      //   "unionid": responseData["unionid"],
      // };
      // BuildContext contextTemp =
      //     App.getIt<NavigateService>().key.currentState.overlay.context;
      // CheckbindPhoneSunModel model =
      //     await otherLoginProvider.checkbindPhone(contextTemp, params);
      // // Loading.hideLoading(context);
      // if (model != null) {
      //   createStoreModel.storeInfo = StoreInfo();
      //   createStoreModel.storeInfo.phone = model.phone;
      // fluwx.removeSubscriber(responseListener);
      createStoreModel.storeInfo = StoreInfo();
      NavigatorUtil.goIfNeedCreateStorePage(context);
      // } else {
      //   NavigatorUtil.goBindingPhonePage(context);
      // }

      // _getUserInfo(responseData["access_token"], responseData["openid"]);
    }
  }

//   //获取用户信息
//   _getUserInfo(String access_token, String openid) async {
//     Response response = await DioUtil.getInstance().getDio().get(
//         "https://api.weixin.qq.com/sns/userinfo?access_token=$access_token&openid=$openid");
//     LogUtil.v('userinfo:' + response.data);
//     Map<String, dynamic> responseData = json.decode(response.data.toString());
//     if (responseData["errcode"] != null) {
// //      Utils.showToast(responseData["errmsg"]??"登录,请稍后重试");
//     } else {
//       App.sp.setString("nickName", responseData["nickname"]);
//       App.sp.setString("headImg", responseData["headimgurl"]);
//       App.sp.setString("unionid", responseData["unionid"]);
//       App.sp.setBool("isLogin", true);
//       // _fromTypeGo();
//       String unionId = App.sp.getString("unionid");
//       _getMiniOpenid(unionId);
//     }
//   }
//     //获取绑定小程序openid
//   _getMiniOpenid(String unionId) async {
//     UserModel userInfoProvider = UserModel();
//     // Provider.of<UserInfoProvider>(context, listen: false);
//     Map<String, String> params = {"unionid": unionId};
//     String miniOpenid =
//         await userInfoProvider.getMiniProgramOpenid(context, params);
//     if (miniOpenid == null) {
//       goMiniProgramMd(unionId);
//     }
//   }

  /*
   苹果登录获取用户信息
  */
  _getUserInfoIOS() async {
    // Map<String, String> params = {"openid": App.sp.getString("openid")};
    // UserInfoProvider userInfoProvider =
    //     Provider.of<UserInfoProvider>(context, listen: false);
    // UseInfoItemModel useInfoItemModel =
    //     await userInfoProvider.getUserInfo(context, params);

    // if (ObjectUtil.isNotEmpty(useInfoItemModel.openid)) {
    //   _hideLoading(context);
    //   App.sp.setString("nickName", useInfoItemModel.nickname);
    //   App.sp.setString("headImg", '');
    //   App.sp.setString("unionid", '');
    //   App.sp.setBool("isLogin", true);
    //   UserInfoProvider userInfoProvider = new UserInfoProvider();
    //   userInfoProvider.initPlatformState(context);
    //   // Loading.hideLoading(context);
    //   _fromTypeGo();
    // } else {
    //   // 已经授权,但是后台库里没有数据,版本差异,重新插入数据库
    //   Map param = {
    //     'openid': App.sp.getString("openid"),
    //     'avatar': 'ios_avatar',
    //     'nickname': '',
    //     'gender': '1'
    //   };
    //   LoginRespository().appleLogin(context, param, () {
    //     _getUserInfoIOS();
    //   });
    // }
  }

  _showLoading(BuildContext context) {
    showGeneralDialog(
        context: context,
        barrierDismissible: false,
        barrierLabel:
            MaterialLocalizations.of(context).modalBarrierDismissLabel,
        transitionDuration: const Duration(milliseconds: 150),
        pageBuilder: (BuildContext context, Animation animation,
            Animation secondaryAnimation) {
          return Align(
            child: ClipRRect(
              borderRadius: BorderRadius.circular(10),
              child: Container(
                width: 80,
                height: 80,
                child: CupertinoActivityIndicator(),
              ),
            ),
          );
        }).then((v) {});
  }

  ///苹果登陆
  _iosLogin(UserModel value) async {
    String info = await Utils.getDeviceInfoSystem();
    int systemInfo = info.compareTo('13');
    if (systemInfo < 0) {
      Utils.showToast('该系统版本不支持苹果登录');
      return;
    }
    final credential = await SignInWithApple.getAppleIDCredential(
      scopes: [
        AppleIDAuthorizationScopes.email,
        AppleIDAuthorizationScopes.fullName,
      ],
      webAuthenticationOptions: WebAuthenticationOptions(
        // TODO: Set the `clientId` and `redirectUri` arguments to the values you entered in the Apple Developer portal during the setup
        clientId: 'com.naji.reserveLine',
        redirectUri: Uri.parse(
          'https://flutter-sign-in-with-apple-example.glitch.me/callbacks/sign_in_with_apple',
        ),
      ),
    );
    // _showLoading(context);
    // print(credential.userIdentifier);
    _loginAppleData(value);
    // NavigatorUtil.goBindingPhonePage(context, wechat: false);
    // String mdString = Utils.generateMd5(credential.userIdentifier);
    // String temp = mdString.substring(8, mdString.length - 2);
    // String openid = 'IOSID_$temp';
    // App.sp.setString("openid", openid);
    // App.sp.setString("unionid", '');
    // print(openid.length);

    // 第一次授权
    // if (ObjectUtil.isNotEmpty(credential.familyName)) {
    //   Map param = {
    //     'openid': openid,
    //     'avatar': 'ios_avatar',
    //     'nickname': '${credential.familyName}${credential.givenName}',
    //     'gender': '1'
    //   };
    //   LoginRespository().appleLogin(context, param, () {
    //     _getUserInfoIOS();
    //   });
    // } else {
    //   if (ObjectUtil.isNotEmpty(App.sp.getString("newUserMsg"))) {
    //     Map newUserMsg = jsonDecode(App.sp.getString("newUserMsg"));
    //     //上次失败了,这次重新传
    //     LoginRespository().appleLogin(context, newUserMsg, () {
    //       _getUserInfoIOS();
    //     });
    //   } else {
    //     _getUserInfoIOS();
    //   }
    // }
  }

  _loginAppleData(UserModel value) {
    if (App.sp!.containsKey('unionid')) {
      //微信登陆的时候,退出清空数据
      App.sp!.remove('openid');
      App.sp!.remove("unionid");
    }
    Map<String, String> params = {
      "seller_code": "004352",
      "alias": "ssahdahgdafgahjkhakjgh",
      "account": "0000",
      "password": "123456"
    };
    value.login(context, params).then((value) {
      // setState(() {
      //   // errorText = value ?? "";
      // });
    });
  }

  @override
  Widget build(BuildContext context) {
    // ScreenUtil.init(context, width: 750, height: 1334);
    otherLoginProvider =
        Provider.of<OtherLoginProvider>(context, listen: false);
    createStoreModel = Provider.of<CreateStoreModel>(context, listen: false);
    final Size size = MediaQuery.of(context).size;
    App.screenWidth = size.width;
    App.screenHeight = size.height;
    App.statusBarHeight = MediaQuery.of(context).padding.top;
    App.bottomBarHeight = MediaQuery.of(context).padding.bottom;

    final double prefixIconWidth = ScreenUtil().setWidth(24);

    return Scaffold(
        backgroundColor: MyColours.color_ffffff,
        body: Container(
          width: double.infinity,
          height: double.infinity,
          child: SingleChildScrollView(
            controller: _scrollController,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: <Widget>[
                // VEmptyView(218 - App.statusBarHeight),
                VEmptyView(80 + App.statusBarHeight),
                // Padding(
                //     padding: EdgeInsets.symmetric(
                //         horizontal: ScreenUtil().setWidth(40)),
                //     child: Row(
                //       mainAxisAlignment: MainAxisAlignment.start,
                //       children: [
                //         Image.asset(
                //           "assets/logo.png",
                //           width: ScreenUtil().setWidth(40 * 2),
                //           height: ScreenUtil().setWidth(40 * 2),
                //         )
                //       ],
                //     )),
                VEmptyView(80),
                VEmptyView(120),
                Image.asset(
                  Utils.getImgPath('login_bg'),
                ),
                // Container(
                //     height: ScreenUtil().setHeight(84),
                //     width: ScreenUtil().setWidth(611),
                //     padding: EdgeInsets.only(left: ScreenUtil().setWidth(20)),
                //     alignment: Alignment.center,
                //     decoration: BoxDecoration(
                //         border: Border.all(
                //             color: MyColours.color_bff6f7,
                //             width: ScreenUtil().setWidth(2)),
                //         borderRadius:
                //             BorderRadius.circular(ScreenUtil().setWidth(8))),
                //     child: Row(
                //       crossAxisAlignment: CrossAxisAlignment.center,
                //       children: <Widget>[
                //         Image.asset(
                //           "assets/icon_sellercode.png",
                //           width: prefixIconWidth,
                //         ),
                //         HEmptyView(26),
                //         Center(
                //             child: Text(
                //           "商户编号",
                //           style: TextStyle(
                //               color: MyColours.color_353535,
                //               fontSize: ScreenUtil().setSp(28)),
                //         )),
                //         Expanded(
                //           child: Container(
                //               height: ScreenUtil().setHeight(84),
                //               padding: EdgeInsets.only(
                //                   left: ScreenUtil().setWidth(20),
                //                   right: ScreenUtil().setWidth(20),
                //                   top: ScreenUtil().setWidth(8)),
                //               child: TextField(
                //                 controller: _sellerCodeController,
                //                 focusNode: _sellerCodeFocusNode,
                //                 // autofocus: _sellerCodeController.text.isEmpty,
                //                 style: TextStyle(
                //                     color: MyColours.color_353535,
                //                     fontSize: ScreenUtil().setSp(28),
                //                     textBaseline: TextBaseline.alphabetic),
                //                 // textAlignVertical: TextAlignVertical.center,
                //                 decoration: InputDecoration(
                //                   hintText: "请输入6位商户编码",
                //                   hintStyle: TextStyle(
                //                     color: MyColours.color_c1c1c1,
                //                     fontSize: ScreenUtil().setSp(28),
                //                   ),
                //                   border: OutlineInputBorder(
                //                       borderSide: BorderSide.none),
                //                   contentPadding: EdgeInsets.zero,
                //                 ),
                //                 onChanged: (_) {
                //                   setActivate();
                //                 },
                //                 keyboardType: TextInputType.numberWithOptions(decimal: true),
                //               )),
                //         )
                //       ],
                //     )),

                // Container(
                //     height: ScreenUtil().setHeight(84),
                //     width: ScreenUtil().setWidth(611),
                //     padding: EdgeInsets.only(left: ScreenUtil().setWidth(20)),
                //     margin: EdgeInsets.only(top: ScreenUtil().setHeight(8)),
                //     alignment: Alignment.center,
                //     decoration: BoxDecoration(
                //         border: Border.all(
                //             color: MyColours.color_bff6f7,
                //             width: ScreenUtil().setWidth(2)),
                //         borderRadius:
                //             BorderRadius.circular(ScreenUtil().setWidth(8))),
                //     child: Row(
                //       crossAxisAlignment: CrossAxisAlignment.center,
                //       children: <Widget>[
                //         Image.asset(
                //           "assets/icon_account.png",
                //           width: prefixIconWidth,
                //         ),
                //         HEmptyView(26),
                //         Text(
                //           "工        号",
                //           style: TextStyle(
                //               color: MyColours.color_353535,
                //               fontSize: ScreenUtil().setSp(28)),
                //         ),
                //         Expanded(
                //             child: Container(
                //           height: ScreenUtil().setHeight(84),
                //           padding: EdgeInsets.only(
                //               left: ScreenUtil().setWidth(20),
                //               right: ScreenUtil().setWidth(20),
                //               top: ScreenUtil().setWidth(8)),
                //           child: TextField(
                //             controller: _accountController,
                //             focusNode: _accountFocusNode,
                //             style: TextStyle(
                //                 color: MyColours.color_353535,
                //                 fontSize: ScreenUtil().setSp(28)),
                //             decoration: InputDecoration(
                //               hintText: "请输入4位工号",
                //               hintStyle: TextStyle(
                //                   color: MyColours.color_c1c1c1,
                //                   fontSize: ScreenUtil().setSp(28)),
                //               border: OutlineInputBorder(
                //                   borderSide: BorderSide.none),
                //               contentPadding: EdgeInsets.zero,
                //             ),
                //             onChanged: (_) {
                //               setActivate();
                //             },
                //             keyboardType: TextInputType.numberWithOptions(decimal: true),
                //           ),
                //         ))
                //       ],
                //     )),
                // Container(
                //     height: ScreenUtil().setHeight(84),
                //     width: ScreenUtil().setWidth(611),
                //     padding: EdgeInsets.only(
                //         left: ScreenUtil().setWidth(20),
                //         right: ScreenUtil().setWidth(27)),
                //     margin: EdgeInsets.only(top: ScreenUtil().setHeight(8)),
                //     alignment: Alignment.center,
                //     decoration: BoxDecoration(
                //         border: Border.all(
                //             color: MyColours.color_bff6f7,
                //             width: ScreenUtil().setWidth(2)),
                //         borderRadius:
                //             BorderRadius.circular(ScreenUtil().setWidth(8))),
                //     child: Row(
                //       crossAxisAlignment: CrossAxisAlignment.center,
                //       children: <Widget>[
                //         Image.asset(
                //           "assets/icon_pwd.png",
                //           width: prefixIconWidth,
                //         ),
                //         HEmptyView(26),
                //         Text(
                //           "密        码",
                //           style: TextStyle(
                //               color: MyColours.color_353535,
                //               fontSize: ScreenUtil().setSp(28)),
                //         ),
                //         Expanded(
                //           child: Container(
                //               height: ScreenUtil().setHeight(84),
                //               padding: EdgeInsets.only(
                //                   left: ScreenUtil().setWidth(20),
                //                   right: ScreenUtil().setWidth(20),
                //                   top: ScreenUtil().setWidth(8)),
                //               child: TextField(
                //                 controller: _pwdController,
                //                 focusNode: _pwdFocusNode,
                //                 // autofocus: _sellerCodeController.text.isNotEmpty &&
                //                 //     _accountController.text.isNotEmpty &&
                //                 //     _pwdController.text.isEmpty,
                //                 style: TextStyle(
                //                     color: MyColours.color_353535,
                //                     fontSize: ScreenUtil().setSp(28)),
                //                 decoration: InputDecoration(
                //                   hintText: "请输入密码",
                //                   hintStyle: TextStyle(
                //                       color: MyColours.color_c1c1c1,
                //                       fontSize: ScreenUtil().setSp(28)),
                //                   border: OutlineInputBorder(
                //                       borderSide: BorderSide.none),
                //                   contentPadding: EdgeInsets.zero,
                //                 ),
                //                 onChanged: (_) {
                //                   setActivate();
                //                 },
                //                 obscureText: obscureText,
                //                 keyboardType: TextInputType.text,
                //               )),
                //         ),
                //         GestureDetector(
                //           child: Padding(
                //             padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
                //             child: Image.asset(
                //               obscureText
                //                   ? "assets/icon_pwd_show.png"
                //                   : "assets/icon_pwd_hide.png",
                //               width: ScreenUtil().setWidth(35),
                //               height: ScreenUtil().setHeight(24),
                //             ),
                //           ),
                //           onTap: () {
                //             setState(() {
                //               obscureText = !obscureText;
                //             });
                //           },
                //         )
                //       ],
                //     )),

                // Container(
                //   width: ScreenUtil().setWidth(611),
                //   margin: EdgeInsets.only(top: ScreenUtil().setHeight(16)),
                //   alignment: Alignment.centerLeft,
                //   child: Text(
                //     errorText,
                //     // 'hfhfhf',
                //     style: TextStyle(
                //         color: MyColours.color_d93535,
                //         fontSize: ScreenUtil().setSp(16)),
                //   ),
                // ),
                VEmptyView(60),
                // Consumer<UserModel>(
                //   builder:
                //       (BuildContext context, UserModel value, Widget child) {
                //     return GestureDetector(
                //       onTap: () {
                //         if (!isActivate) return;
                //         if (!_check) {
                //           Utils.showToast('请先仔细阅读并同意协议');
                //           return;
                //         }
                //         if (App.sp.containsKey('unionid')) {
                //           //微信登陆的时候,退出清空数据
                //           App.sp.remove('openid');
                //           App.sp.remove("unionid");
                //         }
                //         Map<String, String> params = {
                //           "seller_code": "${_sellerCodeController.text}",
                //           "alias": "ssahdahgdafgahjkhakjgh",
                //           "account": "${_accountController.text}",
                //           "password": "${_pwdController.text}"
                //         };
                //         value.login(context, params).then((value) {
                //           setState(() {
                //             errorText = value ?? "";
                //           });
                //         });
                //       },
                //       child: Container(
                //         height: ScreenUtil().setWidth(84),
                //         width: ScreenUtil().setWidth(611),
                //         alignment: Alignment.center,
                //         decoration: BoxDecoration(
                //             color: isActivate
                //                 ? MyColours.color_2bb5b7
                //                 : MyColours.color_2bb5b7,
                //             boxShadow: [
                //               BoxShadow(
                //                 color: MyColours.color_26000000,
                //                 offset: Offset(0, ScreenUtil().setWidth(4)),
                //               )
                //             ],
                //             borderRadius: BorderRadius.all(
                //                 Radius.circular(ScreenUtil().setWidth(8)))),
                //         child: Text(
                //           "登录",
                //           style: TextStyle(
                //               color: MyColours.color_ffffff,
                //               fontSize: ScreenUtil().setSp(34)),
                //         ),
                //       ),
                //     );
                //   },
                // ),

                Row(
                  // mainAxisSize: MainAxisSize.min,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    InkWell(
                        onTap: () {
                          setState(() {
                            _check = !_check;
                          });
                          _huaweiLoginViewController
                              ?.setAgreementStatus(_check);
                        },
                        child: Container(
                          alignment: Alignment.topCenter,
                          // color: Colors.red,
                          height: ScreenUtil().setWidth(110),
                          padding: EdgeInsets.only(
                              right: ScreenUtil().setWidth(30),
                              left: ScreenUtil().setWidth(102),
                              bottom: ScreenUtil().setWidth(10)),
                          child: Image.asset(
                              _check
                                  ? "assets/mine_radio_sel.png"
                                  : "assets/mine_radio_nor.png",
                              width: ScreenUtil().setWidth(26),
                              height: ScreenUtil().setWidth(26)),
                        )),
                    Expanded(
                      child: Padding(
                        padding:
                            EdgeInsets.only(top: ScreenUtil().setWidth(2)),
                        child: Wrap(
                          crossAxisAlignment: WrapCrossAlignment.center,
                          runSpacing: ScreenUtil().setWidth(2),
                          children: <Widget>[
                            Text(
                              '已阅读并同意',
                              style: TextStyle(
                                  fontSize: ScreenUtil().setSp(24),
                                  color: MyColours.color_999999),
                            ),
                            InkWell(
                              onTap: () {
                                NavigatorUtil.goWebPage(
                                    context, '软件服务协议', "xy");
                              },
                              child: Text(
                                '《软件服务协议》',
                                style: TextStyle(
                                    fontSize: ScreenUtil().setSp(24),
                                    color: MyColours.color_333333),
                              ),
                            ),
                            Text('及',
                                style: TextStyle(
                                    fontSize: ScreenUtil().setSp(24),
                                    color: MyColours.color_999999)),
                            InkWell(
                              onTap: () {
                                NavigatorUtil.goWebPage(
                                    context, '隐私政策', "zc");
                              },
                              child: Text('《隐私政策》',
                                  style: TextStyle(
                                      fontSize: ScreenUtil().setSp(24),
                                      color: MyColours.color_333333)),
                            ),
                            if (Platform.isOhos) ...[
                              Text('和',
                                  style: TextStyle(
                                      fontSize: ScreenUtil().setSp(24),
                                      color: MyColours.color_999999)),
                              InkWell(
                                onTap: () {
                                  NavigatorUtil.goWebUrl(
                                      context,
                                      '华为账号用户认证协议',
                                      'https://privacy.consumer.huawei.com/legal/id/authentication-terms.htm?code=CN&language=zh-CN');
                                },
                                child: Text('《华为账号用户认证协议》',
                                    style: TextStyle(
                                        fontSize: ScreenUtil().setSp(24),
                                        color: MyColours.color_333333)),
                              ),
                            ],
                          ],
                        ),
                      ),
                    ),
                  ],
                ),

                //微信登录
                Offstage(
                    offstage: !App.isInstallWx,
                    child: InkWell(
                      child: Container(
                          width: double.infinity,
                          height: ScreenUtil().setWidth(90),
                          margin: EdgeInsets.only(
                              bottom: ScreenUtil().setWidth(30),
                              right: ScreenUtil().setWidth(80),
                              left: ScreenUtil().setWidth(80)),
                          decoration: BoxDecoration(
                              color: MyColours.color_55AA67,
                              borderRadius: BorderRadius.circular(
                                  ScreenUtil().setWidth(8))),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Image.asset(Utils.getImgPath('icon_wechat_login'),
                                  width: ScreenUtil().setWidth(46)),
                              HEmptyView(20),
                              Text('微信登录',
                                  style: TextStyle(
                                      color: MyColours.color_ffffff,
                                      fontSize: ScreenUtil().setSp(28),
                                      fontWeight: FontWeight.bold)),
                            ],
                          )),
                      onTap: () {
                        if (!_check) {
                          DialogUtil.openAlertDialogLogin(context, 530,
                              onTap: () {
                            if (Navigator.canPop(context)) {
                              Navigator.pop(context);
                            }
                            _wxLogin();
                          });
                          return;
                        }
                        _wxLogin();
                      },
                    )),
                //账号登录
                Consumer<UserModel>(builder:
                    (BuildContext context, UserModel value, Widget? child) {
                  return InkWell(
                      child: Container(
                          width: double.infinity,
                          height: ScreenUtil().setWidth(90),
                          margin: EdgeInsets.only(
                              bottom: ScreenUtil().setWidth(30),
                              right: ScreenUtil().setWidth(80),
                              left: ScreenUtil().setWidth(80)),
                          decoration: BoxDecoration(
                              color: MyColours.color_41444B,
                              borderRadius: BorderRadius.circular(
                                  ScreenUtil().setWidth(8))),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            children: [
                              Text('周到安排商家账号登录',
                                  style: TextStyle(
                                      color: MyColours.color_ffffff,
                                      fontSize: ScreenUtil().setSp(28),
                                      fontWeight: FontWeight.bold)),
                            ],
                          )),
                      onTap: () {
                        if (!_check) {
                          DialogUtil.openAlertDialogLogin(context, 530,
                              onTap: () {
                            if (Navigator.canPop(context)) {
                              Navigator.pop(context);
                            }
                            NavigatorUtil.goAccountLoginPage(context);
                          });
                          return;
                        }
                        NavigatorUtil.goAccountLoginPage(context);
                      });
                }),
                // 华为账号登录
                Platform.isOhos
                    ? Container(
                        width: double.infinity,
                        height: ScreenUtil().setWidth(90),
                        margin: EdgeInsets.only(
                            bottom: ScreenUtil().setWidth(30),
                            right: ScreenUtil().setWidth(80),
                            left: ScreenUtil().setWidth(80)),
                        child: HuaweiLoginView(
                          onViewCreated: _onHuaweiLoginViewCreated,
                        ),
                      )
                    : Text(''),
                // ios登录
                Platform.isAndroid || Platform.isOhos
                    ? Text('')
                    : Consumer<UserModel>(builder:
                        (BuildContext context, UserModel value, Widget? child) {
                        return InkWell(
                            child: Container(
                                width: double.infinity,
                                height: ScreenUtil().setWidth(90),
                                margin: EdgeInsets.only(
                                    bottom: ScreenUtil().setWidth(30),
                                    right: ScreenUtil().setWidth(80),
                                    left: ScreenUtil().setWidth(80)),
                                decoration: BoxDecoration(
                                    color: MyColours.color_ffffff,
                                    border: Border.all(
                                        color: MyColours.color_E4E4E4,
                                        width: ScreenUtil().setWidth(2)),
                                    borderRadius: BorderRadius.circular(
                                        ScreenUtil().setWidth(8))),
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Image.asset(
                                        Utils.getImgPath('icon_apple_login'),
                                        width: ScreenUtil().setWidth(46)),
                                    HEmptyView(20),
                                    Text('通过 Apple 登录',
                                        style: TextStyle(
                                            color: MyColours.color_41444B,
                                            fontSize: ScreenUtil().setSp(28),
                                            fontWeight: FontWeight.bold)),
                                  ],
                                )),
                            onTap: () {
                              if (!_check) {
                                DialogUtil.openAlertDialogLogin(context, 530,
                                    onTap: () {
                                  if (Navigator.canPop(context)) {
                                    Navigator.pop(context);
                                  }
                                  _iosLogin(value);
                                });
                                return;
                              }
                              _iosLogin(value);
                            });
                      }),
                InkWell(
                    onTap: () {
                      Utils.goPhone("400-000-9690");
                    },
                    child: Text('联系客服',
                        style: TextStyle(
                            color: MyColours.color_333333,
                            fontWeight: FontWeight.bold,
                            fontSize: ScreenUtil().setSp(26),
                            decoration: TextDecoration.underline))),
                VEmptyView(30),
              ],
            ),
          ),
        ));
  }
}