diff --git a/lib/controller/mine/user_controller.dart b/lib/controller/mine/user_controller.dart index 59dc2fd..02929d1 100644 --- a/lib/controller/mine/user_controller.dart +++ b/lib/controller/mine/user_controller.dart @@ -56,7 +56,7 @@ class UserController extends GetxController { if (response.data.isSuccess && response.data.data != null) { // 成功获取基础信息后,调用获取婚姻信息详情接口 - await getMarriageInformationDetail(); + await getMarriageInformationDetail(false); } else { SmartDialog.showToast(response.data.message); } @@ -67,17 +67,18 @@ class UserController extends GetxController { } /// 获取用户婚姻信息详情 - Future getMarriageInformationDetail() async { + Future getMarriageInformationDetail(bool isMain) async { try { final response = await _userApi.getMarriageInformationDetail(); if (response.data.isSuccess) { // 检查data是否为null或者是空对象 - if (response.data.data == null) { + final information = response.data.data; + if (information == null || information.id.isEmpty || information.genderCode.isNaN || information.birthYear == null) { //跳转到完善信息 SmartDialog.showToast('转到完善信息'); // 导航到完善信息页面 Get.offAll(() => UserInfoPage()); - } else { + } else if(!isMain){ Get.offAll(MainPage()); } } else { diff --git a/lib/pages/home/home_page.dart b/lib/pages/home/home_page.dart index f9e86a1..c8e9a7f 100644 --- a/lib/pages/home/home_page.dart +++ b/lib/pages/home/home_page.dart @@ -396,25 +396,20 @@ class _CardHeader extends StatelessWidget { : null, child: ClipRRect( borderRadius: BorderRadius.circular(30), - child: item.avatar != null - ? Image.network( - item.avatar!, - width: 60, - height: 60, - fit: BoxFit.cover, - errorBuilder: (context, error, stackTrace) => Image.asset( - Assets.imagesAvatarsExample, - width: 60, - height: 60, - fit: BoxFit.cover, - ), - ) - : Image.asset( - Assets.imagesAvatarsExample, - width: 60, - height: 60, + child: CachedNetworkImage( + imageUrl: item.avatar, + width: 60, + height: 60, + imageBuilder: (context, imageProvider) => Container( + decoration: BoxDecoration( + image: DecorationImage( + image: imageProvider, fit: BoxFit.cover, ), + ), + ), + errorWidget: (context, url, error) => Image.asset(Assets.imagesAvatarsExample, width: 60, height: 60, fit: BoxFit.cover), + ), ), ), if (isOnline) diff --git a/lib/pages/main/main_page.dart b/lib/pages/main/main_page.dart index 578b411..41b25d8 100644 --- a/lib/pages/main/main_page.dart +++ b/lib/pages/main/main_page.dart @@ -52,7 +52,7 @@ class _MainPageState extends State { Future checkTokenAndFetchMarriageInfo() async { // 调用userController中的getMarriageInformationDetail方法 final userController = Get.find(); - await userController.getMarriageInformationDetail(); + await userController.getMarriageInformationDetail(true); } @override diff --git a/lib/pages/mine/login_controller.dart b/lib/pages/mine/login_controller.dart index c192281..ba34f49 100644 --- a/lib/pages/mine/login_controller.dart +++ b/lib/pages/mine/login_controller.dart @@ -1,174 +1,174 @@ -import 'dart:async'; -import 'package:dating_touchme_app/pages/main/main_page.dart'; -import 'package:get/get.dart'; -import 'package:get_storage/get_storage.dart'; -import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; -import 'package:dating_touchme_app/network/user_api.dart'; -import 'package:dating_touchme_app/pages/mine/user_info_page.dart'; - - -class LoginController extends GetxController { - // 手机号输入 - final phoneNumber = ''.obs; - // 验证码输入 - final verificationCode = ''.obs; - // 是否正在发送验证码 - final isSendingCode = false.obs; - // 倒计时秒数 - final countdownSeconds = 0.obs; - // 是否正在登录中 - final isLoggingIn = false.obs; - - // 从GetX依赖注入中获取UserApi实例 - late UserApi _userApi; - // GetStorage实例,用于存储token等信息 - final storage = GetStorage(); - - @override - void onInit() { - super.onInit(); - // 从全局依赖中获取UserApi - _userApi = Get.find(); - } - - // 获取验证码 - Future getVerificationCode() async { - // 验证手机号格式 - if (phoneNumber.value.isEmpty || phoneNumber.value.length != 11) { - SmartDialog.showToast('请输入正确的手机号'); - return; - } - - isSendingCode.value = true; - - try { - // 构建请求参数 - final params = { - 'purpose': 1, // 认证 - 'verifiableAccount': phoneNumber.value, - 'verifiableAccountType': 1, // 手机 - }; - - // 调用UserApi中的验证码接口 - final response = await _userApi.getVerificationCode(params); - - // 处理响应 - if (response.data.isSuccess) { - // 生产环境移除打印,可考虑使用正式的日志框架 - // print('验证码发送成功'); - // 开始倒计时 - startCountdown(); - } else { - SmartDialog.showToast(response.data.message); - } - } catch (e) { - SmartDialog.showToast('网络请求失败,请重试'); - } finally { - isSendingCode.value = false; - } - } - - // 开始倒计时 - void startCountdown() { - countdownSeconds.value = 60; - Timer.periodic(const Duration(seconds: 1), (timer) { - countdownSeconds.value--; - if (countdownSeconds.value <= 0) { - timer.cancel(); - } - }); - } - - // 清除错误信息 - 由于使用SmartDialog,此方法不再需要 - // void clearErrorMessage() {} - - - // 登录方法 - Future login() async { - // 验证输入 - if (phoneNumber.value.isEmpty || phoneNumber.value.length != 11) { - SmartDialog.showToast('请输入正确的手机号'); - return; - } - - if (verificationCode.value.isEmpty) { - SmartDialog.showToast('请输入验证码'); - return; - } - - isLoggingIn.value = true; - - try { - // 构建登录请求参数 - final params = { - 'account': phoneNumber.value, - 'accountType': 2, // 手机号类型 - 'captcha': verificationCode.value, - }; - - // 调用登录接口 - final response = await _userApi.login(params); - - // 处理响应 - if (response.data.isSuccess) { - // 保存token和用户信息 - if (response.data.data != null) { - final loginData = response.data.data!; - await storage.write('token', loginData.token); - await storage.write('userId', loginData.userId); - // 保存用户信息 - await storage.write('userInfo', loginData.toJson()); - - // 登录成功后获取用户基础信息 - await _getBaseUserInfo(loginData.userId); - } - } else { - SmartDialog.showToast(response.data.message); - } - } catch (e) { - SmartDialog.showToast('网络请求失败,请检查网络连接'); - } finally { - isLoggingIn.value = false; - } - } - - // 获取用户基础信息 - Future _getBaseUserInfo(String userId) async { - try { - final response = await _userApi.getBaseUserInfo(userId); - - if (response.data.isSuccess && response.data.data != null) { - // 成功获取基础信息后,调用获取婚姻信息详情接口 - await _getMarriageInformationDetail(); - } else { - SmartDialog.showToast(response.data.message); - } - } catch (e) { - // 获取用户信息失败不影响登录流程 - SmartDialog.showToast('获取用户信息失败'); - } - } - - // 获取用户婚姻信息详情 - Future _getMarriageInformationDetail() async { - try { - final response = await _userApi.getMarriageInformationDetail(); - if (response.data.isSuccess) { - // 检查data是否为null或者是空对象 - if(response.data.data == null){ - //跳转到完善信息 - SmartDialog.showToast('转到完善信息'); - // 导航到完善信息页面 - Get.offAll(() => UserInfoPage()); - }else{ - Get.offAll(MainPage()); - } - } else { - // 获取婚姻信息失败不影响登录流程 - } - } catch (e) { - // 获取婚姻信息失败不影响登录流程 - print('获取婚姻信息异常: $e'); - } - } -} \ No newline at end of file +// import 'dart:async'; +// import 'package:dating_touchme_app/pages/main/main_page.dart'; +// import 'package:get/get.dart'; +// import 'package:get_storage/get_storage.dart'; +// import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; +// import 'package:dating_touchme_app/network/user_api.dart'; +// import 'package:dating_touchme_app/pages/mine/user_info_page.dart'; +// +// +// class LoginController extends GetxController { +// // 手机号输入 +// final phoneNumber = ''.obs; +// // 验证码输入 +// final verificationCode = ''.obs; +// // 是否正在发送验证码 +// final isSendingCode = false.obs; +// // 倒计时秒数 +// final countdownSeconds = 0.obs; +// // 是否正在登录中 +// final isLoggingIn = false.obs; +// +// // 从GetX依赖注入中获取UserApi实例 +// late UserApi _userApi; +// // GetStorage实例,用于存储token等信息 +// final storage = GetStorage(); +// +// @override +// void onInit() { +// super.onInit(); +// // 从全局依赖中获取UserApi +// _userApi = Get.find(); +// } +// +// // 获取验证码 +// Future getVerificationCode() async { +// // 验证手机号格式 +// if (phoneNumber.value.isEmpty || phoneNumber.value.length != 11) { +// SmartDialog.showToast('请输入正确的手机号'); +// return; +// } +// +// isSendingCode.value = true; +// +// try { +// // 构建请求参数 +// final params = { +// 'purpose': 1, // 认证 +// 'verifiableAccount': phoneNumber.value, +// 'verifiableAccountType': 1, // 手机 +// }; +// +// // 调用UserApi中的验证码接口 +// final response = await _userApi.getVerificationCode(params); +// +// // 处理响应 +// if (response.data.isSuccess) { +// // 生产环境移除打印,可考虑使用正式的日志框架 +// // print('验证码发送成功'); +// // 开始倒计时 +// startCountdown(); +// } else { +// SmartDialog.showToast(response.data.message); +// } +// } catch (e) { +// SmartDialog.showToast('网络请求失败,请重试'); +// } finally { +// isSendingCode.value = false; +// } +// } +// +// // 开始倒计时 +// void startCountdown() { +// countdownSeconds.value = 60; +// Timer.periodic(const Duration(seconds: 1), (timer) { +// countdownSeconds.value--; +// if (countdownSeconds.value <= 0) { +// timer.cancel(); +// } +// }); +// } +// +// // 清除错误信息 - 由于使用SmartDialog,此方法不再需要 +// // void clearErrorMessage() {} +// +// +// // 登录方法 +// Future login() async { +// // 验证输入 +// if (phoneNumber.value.isEmpty || phoneNumber.value.length != 11) { +// SmartDialog.showToast('请输入正确的手机号'); +// return; +// } +// +// if (verificationCode.value.isEmpty) { +// SmartDialog.showToast('请输入验证码'); +// return; +// } +// +// isLoggingIn.value = true; +// +// try { +// // 构建登录请求参数 +// final params = { +// 'account': phoneNumber.value, +// 'accountType': 2, // 手机号类型 +// 'captcha': verificationCode.value, +// }; +// +// // 调用登录接口 +// final response = await _userApi.login(params); +// +// // 处理响应 +// if (response.data.isSuccess) { +// // 保存token和用户信息 +// if (response.data.data != null) { +// final loginData = response.data.data!; +// await storage.write('token', loginData.token); +// await storage.write('userId', loginData.userId); +// // 保存用户信息 +// await storage.write('userInfo', loginData.toJson()); +// +// // 登录成功后获取用户基础信息 +// await _getBaseUserInfo(loginData.userId); +// } +// } else { +// SmartDialog.showToast(response.data.message); +// } +// } catch (e) { +// SmartDialog.showToast('网络请求失败,请检查网络连接'); +// } finally { +// isLoggingIn.value = false; +// } +// } +// +// // 获取用户基础信息 +// Future _getBaseUserInfo(String userId) async { +// try { +// final response = await _userApi.getBaseUserInfo(userId); +// +// if (response.data.isSuccess && response.data.data != null) { +// // 成功获取基础信息后,调用获取婚姻信息详情接口 +// await _getMarriageInformationDetail(); +// } else { +// SmartDialog.showToast(response.data.message); +// } +// } catch (e) { +// // 获取用户信息失败不影响登录流程 +// SmartDialog.showToast('获取用户信息失败'); +// } +// } +// +// // 获取用户婚姻信息详情 +// Future _getMarriageInformationDetail() async { +// try { +// final response = await _userApi.getMarriageInformationDetail(); +// if (response.data.isSuccess) { +// // 检查data是否为null或者是空对象 +// if(response.data.data == null){ +// //跳转到完善信息 +// SmartDialog.showToast('转到完善信息'); +// // 导航到完善信息页面 +// Get.offAll(() => UserInfoPage()); +// }else{ +// Get.offAll(MainPage()); +// } +// } else { +// // 获取婚姻信息失败不影响登录流程 +// } +// } catch (e) { +// // 获取婚姻信息失败不影响登录流程 +// print('获取婚姻信息异常: $e'); +// } +// } +// } \ No newline at end of file