diff --git a/making_school_asignment_app/lib/common/store/app_storage_key.dart b/making_school_asignment_app/lib/common/store/app_storage_key.dart index b9029b3..0e594fa 100644 --- a/making_school_asignment_app/lib/common/store/app_storage_key.dart +++ b/making_school_asignment_app/lib/common/store/app_storage_key.dart @@ -5,7 +5,9 @@ enum AppStorageKey { xToken(value: 'XTOKEN', label: "登录用户的Xtoken,刷新token信息"), userMobile(value: 'USERMOBILE', label: "用户输入过的手机号码"), userInfo(value: 'USERINFO', label: "登录用户的基本信息 及 token过期时间"), - userDetailInfo(value: 'USERDETAILINFO', label: "用户的详细信息"); + userDetailInfo(value: 'USERDETAILINFO', label: "用户的详细信息"), + account(value: 'ACCOUNT', label: "用户名"), + pwd(value: 'PWD', label: "密码"); final String label; final String value; diff --git a/making_school_asignment_app/lib/page/login_page/login_logic.dart b/making_school_asignment_app/lib/page/login_page/login_logic.dart index 4fb79a5..3c5c1e7 100644 --- a/making_school_asignment_app/lib/page/login_page/login_logic.dart +++ b/making_school_asignment_app/lib/page/login_page/login_logic.dart @@ -8,6 +8,8 @@ import 'package:making_school_asignment_app/common/utils/storage.dart'; import 'package:making_school_asignment_app/common/utils/toast_utils.dart'; import 'package:making_school_asignment_app/common/utils/utils.dart'; import 'package:making_school_asignment_app/routes/app_pages.dart'; +import 'package:making_school_asignment_app/common/utils/storage.dart'; +import 'package:making_school_asignment_app/common/store/app_storage_key.dart'; import 'login_state.dart'; @@ -23,8 +25,19 @@ class LoginLogic extends GetxController with RequestToolMixin { @override void onInit() { super.onInit(); - state.userNameController = TextEditingController()..addListener(userNameListener); - state.passwordController = TextEditingController(); + + /* state.userNameController = TextEditingController() + ..addListener(userNameListener); + state.passwordController = TextEditingController();*/ + + String account = StorageService.to.read(AppStorageKey.account.value)?? ''; + String pwd = StorageService.to.read(AppStorageKey.pwd.value) ?? ''; + if (account != '' && pwd != '') { + state.userNameController.text = account; + state.passwordController.text = pwd; + state.keepPwd.value = true; + } + state.pwdFocus = FocusNode(); state.theFocus = FocusNode(); } @@ -77,6 +90,12 @@ class LoginLogic extends GetxController with RequestToolMixin { } UserStore.to.setUserDetailInfo(data); EasyLoading.dismiss(); + + if (state.keepPwd.value) { + StorageService.to.write(AppStorageKey.account.value, userName); + StorageService.to.write(AppStorageKey.pwd.value, userPwd); + } + Get.offAllNamed(Routes.startPage); // if (resultData.code != 200 || userData?.accessToken == null || userData?.accessToken == '') { // return toMsg(resultData.message ?? '登录失败,请重试'); diff --git a/making_school_asignment_app/lib/page/login_page/login_state.dart b/making_school_asignment_app/lib/page/login_page/login_state.dart index 5933131..d493af9 100644 --- a/making_school_asignment_app/lib/page/login_page/login_state.dart +++ b/making_school_asignment_app/lib/page/login_page/login_state.dart @@ -9,8 +9,8 @@ class LoginState { late final FocusNode pwdFocus; // 密码 late final FocusNode theFocus; //文本输入框控制器 - late final TextEditingController userNameController; - late final TextEditingController passwordController; + late TextEditingController userNameController = TextEditingController(); + late TextEditingController passwordController = TextEditingController(); bool hasNameVal = false; late RxBool isShowPwd = true.obs; late RxBool keepPwd = false.obs; diff --git a/making_school_asignment_app/lib/page/login_page/login_view.dart b/making_school_asignment_app/lib/page/login_page/login_view.dart index 27b3c8a..38a9fd7 100644 --- a/making_school_asignment_app/lib/page/login_page/login_view.dart +++ b/making_school_asignment_app/lib/page/login_page/login_view.dart @@ -190,49 +190,51 @@ class _LoginPageState extends State { SizedBox( height: 22.h, ), - /* Row( + Row( children: [ Container( - width: 30.w, - padding: EdgeInsets.only(right: 10.w), + width: 25.w, + padding: EdgeInsets.only(right: 0.w), child: Obx(() { - return Checkbox( - activeColor: Theme.of(context).primaryColor, - checkColor: Colors.white, - value: state.keepPwd.value, - onChanged: (value) { - Get.focusScope?.nextFocus(); - */ /* FocusScope.of(context).requestFocus( - state.pwdFocus); - FocusScope.of(context).requestFocus( - state.theFocus);*/ /* - state.keepPwd.value = value ?? false; - }, + return Transform.scale( + scale: 1.2, + child: Checkbox( + activeColor: Theme.of(context).primaryColor, + checkColor: Colors.white, + value: state.keepPwd.value, + onChanged: (value) { + Get.focusScope?.nextFocus(); + FocusScope.of(context).requestFocus( + state.pwdFocus); + FocusScope.of(context).requestFocus( + state.theFocus); + state.keepPwd.value = value ?? false; + }, + ), ); }), ), InkWell( onTap: () { Utils.hideKeyboard(); - */ /*Get.focusScope?.nextFocus(); - Get.focusScope?.nextFocus();*/ /* - - */ /* FocusScope.of(context).requestFocus( + Get.focusScope?.nextFocus(); + Get.focusScope?.nextFocus(); + FocusScope.of(context).requestFocus( state.pwdFocus); FocusScope.of(context).requestFocus( - state.theFocus);*/ /* + state.theFocus); state.keepPwd.value = !state.keepPwd.value; }, child: Text( '记住密码', style: TextStyle( - fontSize: 14.sp, + fontSize: 11.sp, color: Colors.white, ), ), ), ], - ),*/ + ), InkWell( onTap: () { logic.toLogin(); @@ -293,7 +295,7 @@ class _LoginPageState extends State { onTap: () { Get.toNamed(Routes.agreementPage, arguments: {"type": AGREEMENT_KEY.USER_AGREEMENT.name}); }, - child: quickText('请仔细阅读', size: 11.sp), + child: quickText('请仔细阅读', size: 11.sp,), ), InkWell( onTap: () {