starwork_flutter/lib/views/login/login_controller.dart

116 lines
3.0 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:starwork_flutter/base/base_controller.dart';
import 'package:starwork_flutter/common/constant/cache_keys.dart';
import 'package:starwork_flutter/common/constant/login_type.dart';
import 'package:starwork_flutter/common/utils/shared_preferences_utils.dart';
import 'package:starwork_flutter/routes/app_routes.dart';
class LoginController extends BaseController {
int phoneNumberSize = 11;
TextEditingController phoneController = TextEditingController();
TextEditingController passwordController = TextEditingController();
final isFormValid = false.obs;
final isPasswordVisible = true.obs;
final isPrivacyAgreementValid = 0.obs;
final loginType = LoginType.phoneCodeLogin.obs;
@override
void onInit() {
super.onInit();
// 监听输入变化
phoneController.addListener(_validateForm);
phoneController.text = '18269109817';
}
@override
void onClose() {
phoneController.removeListener(_validateForm);
phoneController.dispose();
super.onClose();
}
void _validateForm() {
isFormValid.value = phoneController.text.length == phoneNumberSize;
}
// 获取手机验证码
void requestPhoneCode() async {
if (isPrivacyAgreementValid.value != 1) {
_showCustomDialog(
title: '欢迎使用星勤'.tr,
content: '1',
onConfirm: () async {
isPrivacyAgreementValid.value = 1;
Get.toNamed(
AppRoutes.inputVerificationCode,
parameters: {
'phone': phoneController.text.trim(),
},
);
},
);
} else {
Get.toNamed(
AppRoutes.inputVerificationCode,
parameters: {
'phone': phoneController.text.trim(),
},
);
}
}
void _showCustomDialog({
required String title,
required String content,
required VoidCallback onConfirm,
}) {
showCustomDialog(
title: title,
content: RichText(
text: TextSpan(
children: [
TextSpan(
text: '请你阅读并同意'.tr,
style: TextStyle(
fontSize: 12.sp,
color: Colors.grey,
),
),
TextSpan(
text: '《用户协议》'.tr,
style: TextStyle(
fontSize: 12.sp,
color: Colors.blue,
),
),
TextSpan(
text: ''.tr,
style: TextStyle(
fontSize: 12.sp,
color: Colors.grey,
),
),
TextSpan(
text: '《隐私政策》'.tr,
style: TextStyle(
fontSize: 12.sp,
color: Colors.blue,
),
),
],
),
),
onConfirm: onConfirm,
confirmText: '同意并继续'.tr,
);
}
}