434 lines
17 KiB
Dart
Executable File
434 lines
17 KiB
Dart
Executable File
import 'package:flutter/cupertino.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:star_lock/flavors.dart';
|
||
import 'package:star_lock/login/login/starLock_login_state.dart';
|
||
import 'package:star_lock/tools/appFirstEnterHandle.dart';
|
||
import 'package:star_lock/tools/storage.dart';
|
||
import 'package:star_lock/tools/wechat/customer_tool.dart';
|
||
|
||
import '../../appRouters.dart';
|
||
import '../../app_settings/app_colors.dart';
|
||
import '../../common/XSConstantMacro/XSConstantMacro.dart';
|
||
import '../../tools/submitBtn.dart';
|
||
import '../../tools/tf_loginInput.dart';
|
||
import '../../tools/wechat/wechatManageTool.dart';
|
||
import 'starLock_login_logic.dart';
|
||
|
||
class StarLockLoginXHJPage extends StatefulWidget {
|
||
const StarLockLoginXHJPage({Key? key}) : super(key: key);
|
||
|
||
@override
|
||
State<StarLockLoginXHJPage> createState() => _StarLockLoginPageState();
|
||
}
|
||
|
||
class _StarLockLoginPageState extends State<StarLockLoginXHJPage> {
|
||
late StarLockLoginLogic logic;
|
||
|
||
late StarLockLoginState state;
|
||
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
if (Get.isRegistered<StarLockLoginLogic>()) {
|
||
logic = Get.find<StarLockLoginLogic>();
|
||
} else {
|
||
logic = Get.put(StarLockLoginLogic());
|
||
}
|
||
state = logic.state;
|
||
WidgetsBinding.instance.addPostFrameCallback((_) async {
|
||
AppFirstEnterHandle().getAppFirstEnter(isAgreePrivacy);
|
||
});
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
return Scaffold(
|
||
resizeToAvoidBottomInset: false,
|
||
backgroundColor: const Color(0xFFFFFFFF),
|
||
body: SizedBox(
|
||
width: Get.width,
|
||
child: ListView(
|
||
padding: EdgeInsets.only(
|
||
top: 110.h,
|
||
),
|
||
children: <Widget>[
|
||
Padding(
|
||
padding: EdgeInsets.symmetric(horizontal: 40.w),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
Row(
|
||
children: <Widget>[
|
||
Expanded(
|
||
child: Text(
|
||
'${"欢迎使用".tr}${F.title}',
|
||
style: TextStyle(
|
||
color: AppColors.darkGrayTextColor,
|
||
fontSize: 48.sp,
|
||
),
|
||
),
|
||
),
|
||
if (state.isChina == true)
|
||
IconButton(
|
||
onPressed: () {
|
||
WechatManageTool.getAppInfo(
|
||
CustomerTool.openCustomerService);
|
||
},
|
||
icon: Icon(Icons.support_agent,
|
||
color: AppColors.mainColor, size: 30)),
|
||
],
|
||
),
|
||
SizedBox(height: 30.h),
|
||
GestureDetector(
|
||
onTap: () async {
|
||
final result =
|
||
await Get.toNamed(Routers.selectCountryRegionPage);
|
||
if (result != null) {
|
||
result as Map<String, dynamic>;
|
||
state.countryCode.value = result['code'];
|
||
state.countryKey.value = result['countryName'];
|
||
logic.checkIpAction();
|
||
}
|
||
},
|
||
child: Container(
|
||
color: Colors.transparent,
|
||
child: Row(
|
||
children: <Widget>[
|
||
SizedBox(
|
||
width: 5.w,
|
||
),
|
||
Text(
|
||
'国家/地区'.tr,
|
||
style: TextStyle(
|
||
fontSize: 22.sp,
|
||
color: AppColors.darkGrayTextColor),
|
||
),
|
||
SizedBox(
|
||
width: 40.w,
|
||
),
|
||
Obx(() {
|
||
return Text(
|
||
'${state.countryName} +${state.countryCode.value}',
|
||
style: TextStyle(
|
||
fontSize: 22.sp,
|
||
color: AppColors.mainColor),
|
||
);
|
||
})
|
||
],
|
||
),
|
||
),
|
||
),
|
||
LoginInput(
|
||
controller: state.emailOrPhoneController,
|
||
onchangeAction: (v) {
|
||
logic.checkNext(state.emailOrPhoneController);
|
||
},
|
||
leftWidget: Padding(
|
||
padding: EdgeInsets.only(
|
||
top: 30.w,
|
||
bottom: 20.w,
|
||
),
|
||
),
|
||
rightSlot: IconButton(
|
||
icon: const Icon(Icons.close),
|
||
onPressed: () {},
|
||
),
|
||
label: '请输入手机号或者邮箱'.tr,
|
||
// keyboardType: TextInputType.number,
|
||
inputFormatters: <TextInputFormatter>[
|
||
LengthLimitingTextInputFormatter(30),
|
||
]),
|
||
LoginInput(
|
||
controller: state.pwdController,
|
||
onchangeAction: (v) {
|
||
logic.checkNext(state.pwdController);
|
||
},
|
||
isPwd: true,
|
||
// isSuffixIcon: 2,
|
||
leftWidget: Padding(
|
||
padding: EdgeInsets.only(
|
||
top: 30.w,
|
||
bottom: 20.w,
|
||
),
|
||
),
|
||
label: '请输入密码'.tr,
|
||
inputFormatters: <TextInputFormatter>[
|
||
LengthLimitingTextInputFormatter(20),
|
||
]),
|
||
SizedBox(height: 10.h),
|
||
],
|
||
),
|
||
),
|
||
_buildBottomAgreement(),
|
||
Padding(
|
||
padding: EdgeInsets.symmetric(horizontal: 40.w),
|
||
child: Column(
|
||
crossAxisAlignment: CrossAxisAlignment.start,
|
||
children: <Widget>[
|
||
SizedBox(height: 5.w),
|
||
Obx(() => SubmitBtn(
|
||
btnName: '登录'.tr,
|
||
fontSize: 28.sp,
|
||
borderRadius: 20.w,
|
||
padding: EdgeInsets.only(top: 25.w, bottom: 25.w),
|
||
isDisabled: state.canNext.value,
|
||
onClick: state.canNext.value
|
||
? () {
|
||
if (state.agree.value == false) {
|
||
logic.showToast('请先同意用户协议及隐私政策'.tr);
|
||
return;
|
||
} else {
|
||
logic.login();
|
||
}
|
||
}
|
||
: null)),
|
||
SizedBox(height: 10.h),
|
||
SizedBox(
|
||
width: Get.width,
|
||
child: ElevatedButton(
|
||
onPressed: () async {
|
||
final dynamic data =
|
||
await Get.toNamed(Routers.starLockRegisterPage);
|
||
state.emailOrPhoneController.text =
|
||
data['phoneOrEmailStr'];
|
||
logic.checkNext(state.emailOrPhoneController);
|
||
state.pwdController.text = data['pwd'];
|
||
logic.checkNext(state.pwdController);
|
||
setState(() {});
|
||
},
|
||
style: ElevatedButton.styleFrom(
|
||
backgroundColor: AppColors.mainColor),
|
||
child: Text(
|
||
'注册'.tr,
|
||
style:
|
||
TextStyle(fontSize: 22.sp, color: Colors.white),
|
||
),
|
||
),
|
||
),
|
||
SizedBox(height: 5.w),
|
||
Row(
|
||
mainAxisAlignment: MainAxisAlignment.center,
|
||
children: <Widget>[
|
||
GestureDetector(
|
||
child: SizedBox(
|
||
// width: 150.w,
|
||
height: 50.h,
|
||
// color: Colors.red,
|
||
child: Center(
|
||
child: Text('${'忘记密码'.tr}?',
|
||
style: TextStyle(
|
||
fontSize: 22.sp,
|
||
color: AppColors.mainColor)),
|
||
),
|
||
),
|
||
onTap: () {
|
||
Navigator.pushNamed(
|
||
context, Routers.starLockForgetPasswordPage);
|
||
},
|
||
),
|
||
Expanded(
|
||
child: SizedBox(
|
||
width: 10.sp,
|
||
)),
|
||
Obx(() => Visibility(
|
||
visible: state.isCheckVerifyEnable.value,
|
||
child: GestureDetector(
|
||
child: SizedBox(
|
||
// width: 150.w,
|
||
height: 50.h,
|
||
// color: Colors.red,
|
||
child: Center(
|
||
child: Text('一键登录'.tr,
|
||
style: TextStyle(
|
||
fontSize: 22.sp,
|
||
color: AppColors.mainColor)),
|
||
),
|
||
),
|
||
onTap: () async {
|
||
logic.oneClickLoginAction(context,showErrorMsg: true);
|
||
},
|
||
),
|
||
))
|
||
],
|
||
),
|
||
],
|
||
),
|
||
)
|
||
],
|
||
),
|
||
));
|
||
}
|
||
|
||
Widget loginInput(
|
||
{TextEditingController? controller,
|
||
List<TextInputFormatter>? inputFormatters,
|
||
String? hintText,
|
||
bool? isHaveLeftWidget,
|
||
Widget? leftWidget,
|
||
String? label,
|
||
bool? isPwd,
|
||
BlockStrCallback? onchangeAction}) {
|
||
return Container(
|
||
width: 1.sp,
|
||
color: Colors.transparent,
|
||
child: Column(
|
||
children: <Widget>[
|
||
Row(
|
||
children: <Widget>[
|
||
Container(
|
||
color: Colors.red,
|
||
child: Image.asset(
|
||
'images/icon_login_password.png',
|
||
width: 36.w,
|
||
height: 36.w,
|
||
),
|
||
),
|
||
SizedBox(
|
||
width: 40.w,
|
||
),
|
||
Expanded(
|
||
child: TextField(
|
||
//输入框一行
|
||
maxLines: 1,
|
||
controller: controller,
|
||
onChanged: onchangeAction,
|
||
// autofocus: false,
|
||
inputFormatters: inputFormatters,
|
||
decoration: InputDecoration(
|
||
//输入里面输入文字内边距设置
|
||
contentPadding: const EdgeInsets.only(
|
||
top: 8.0, left: -19.0, right: -15.0, bottom: 8.0),
|
||
labelText: label,
|
||
labelStyle: TextStyle(fontSize: 22.sp),
|
||
hintStyle: TextStyle(fontSize: 22.sp),
|
||
hintText: hintText,
|
||
//不需要输入框下划线
|
||
border: InputBorder.none,
|
||
//左边图标设置
|
||
// icon: isHaveLeftWidget == true
|
||
// ? leftWidget
|
||
// : SizedBox(
|
||
// width: 20.w,
|
||
// height: 40.w,
|
||
// ),
|
||
),
|
||
obscureText: isPwd ?? false,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
Container(
|
||
height: 0.5.h,
|
||
color: Colors.grey,
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Widget _buildBottomAgreement() {
|
||
return Container(
|
||
width: 1.sw,
|
||
padding:
|
||
EdgeInsets.only(left: 40.w, bottom: 30.w, right: 40.w, top: 40.h),
|
||
child: Wrap(
|
||
// mainAxisAlignment: MainAxisAlignment.start,
|
||
children: <Widget>[
|
||
Obx(() => GestureDetector(
|
||
onTap: () {
|
||
state.agree.value = !state.agree.value;
|
||
logic.changeAgreeState();
|
||
},
|
||
child: Container(
|
||
width: 40.w,
|
||
height: 40.w,
|
||
// color: Colors.red,
|
||
padding: EdgeInsets.only(
|
||
left: 5.w,
|
||
right: 10.w,
|
||
),
|
||
child: Image.asset(
|
||
state.agree.value
|
||
? 'images/icon_round_select.png'
|
||
: 'images/icon_round_unSelect.png',
|
||
width: 20.w,
|
||
height: 20.w,
|
||
),
|
||
))),
|
||
SizedBox(
|
||
width: 10.w,
|
||
),
|
||
Text(
|
||
'我已阅读并同意'.tr,
|
||
style: TextStyle(color: const Color(0xff333333), fontSize: 20.sp),
|
||
),
|
||
GestureDetector(
|
||
child: Text('《${'用户协议'.tr}》',
|
||
style: TextStyle(color: AppColors.mainColor, fontSize: 20.sp)),
|
||
onTap: () {
|
||
Get.toNamed(Routers.webviewShowPage, arguments: <String, String>{
|
||
'url': XSConstantMacro.userAgreementURL,
|
||
'title': '用户协议'.tr
|
||
});
|
||
},
|
||
),
|
||
GestureDetector(
|
||
child: Text('《${'隐私政策'.tr}》',
|
||
style: TextStyle(color: AppColors.mainColor, fontSize: 20.sp)),
|
||
onTap: () {
|
||
Get.toNamed(Routers.webviewShowPage, arguments: <String, String>{
|
||
'url': XSConstantMacro.privacyPolicyURL,
|
||
'title': '隐私政策'.tr
|
||
});
|
||
},
|
||
)
|
||
|
||
// Flexible(
|
||
// child: Text.rich(
|
||
// TextSpan(
|
||
// text: '我已阅读并同意'.tr,
|
||
// style:
|
||
// TextStyle(color: const Color(0xff333333), fontSize: 20.sp),
|
||
// children: <InlineSpan>[
|
||
// WidgetSpan(
|
||
// alignment: PlaceholderAlignment.middle,
|
||
// child: GestureDetector(
|
||
// child: Text(
|
||
// '《${'用户协议'.tr}》',
|
||
// style: TextStyle(
|
||
// color: AppColors.mainColor, fontSize: 20.sp)),
|
||
// onTap: () {
|
||
// Get.toNamed(Routers.webviewShowPage,
|
||
// arguments: <String, String>{
|
||
// 'url': XSConstantMacro.userAgreementURL,
|
||
// 'title': '用户协议'.tr
|
||
// });
|
||
// },
|
||
// )),
|
||
// WidgetSpan(
|
||
// alignment: PlaceholderAlignment.middle,
|
||
// child: GestureDetector(
|
||
// child: Text(
|
||
// '《${'隐私政策'.tr}》',
|
||
// style: TextStyle(
|
||
// color: AppColors.mainColor, fontSize: 20.sp)),
|
||
// onTap: () {
|
||
// Get.toNamed(Routers.webviewShowPage,
|
||
// arguments: <String, String>{
|
||
// 'url': XSConstantMacro.privacyPolicyURL,
|
||
// 'title': '隐私政策'.tr
|
||
// });
|
||
// },
|
||
// )),
|
||
// ],
|
||
// )),
|
||
// )
|
||
],
|
||
),
|
||
);
|
||
}
|
||
}
|