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, }) { Get.dialog( Dialog( backgroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(14.r), // 圆角 ), child: Column( mainAxisSize: MainAxisSize.min, children: [ Padding( padding: EdgeInsets.only(top: 22.h), child: Text( title, style: TextStyle( fontSize: 18.sp, fontWeight: FontWeight.bold, ), ), ), Padding( padding: EdgeInsets.all(22.w), child: 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, ), ), ], ), ), ), SizedBox(height: 20.h), Container( decoration: const BoxDecoration( border: Border( top: BorderSide( color: Colors.grey, // 右侧边框颜色 width: 0.5, // 右侧边框宽度 ), ), ), child: Row( children: [ Expanded( // 左侧文本占一半 child: GestureDetector( onTap: () { Get.back(); }, child: Container( alignment: Alignment.center, height: 42.h, decoration: const BoxDecoration( border: Border( right: BorderSide( color: Colors.grey, // 右侧边框颜色 width: 0.5, // 右侧边框宽度 ), ), ), child: Text( '取消'.tr, textAlign: TextAlign.center, style: TextStyle(fontSize: 14.sp, color: Colors.grey), ), ), ), ), Expanded( // 右侧文本占一半 child: GestureDetector( onTap: () { Get.back(); onConfirm(); }, child: Container( alignment: Alignment.center, height: 42.h, child: Text( '同意并继续'.tr, textAlign: TextAlign.center, style: TextStyle( fontSize: 14.sp, color: Colors.blue, fontWeight: FontWeight.w600, ), ), ), ), ), ], ), ) ], ), ), ); } }