Browse Source

no message

ios
ZHR007 4 months ago
parent
commit
070b201982
4 changed files with 192 additions and 196 deletions
  1. 9
      lib/controller/mine/user_controller.dart
  2. 29
      lib/pages/home/home_page.dart
  3. 2
      lib/pages/main/main_page.dart
  4. 348
      lib/pages/mine/login_controller.dart

9
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<void> getMarriageInformationDetail() async {
Future<void> 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 {

29
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)

2
lib/pages/main/main_page.dart

@ -52,7 +52,7 @@ class _MainPageState extends State<MainPage> {
Future<void> checkTokenAndFetchMarriageInfo() async {
// userController中的getMarriageInformationDetail方法
final userController = Get.find<UserController>();
await userController.getMarriageInformationDetail();
await userController.getMarriageInformationDetail(true);
}
@override

348
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<UserApi>();
}
//
Future<void> 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<void> 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<void> _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<void> _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');
}
}
}
// 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<UserApi>();
// }
//
// //
// Future<void> 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<void> 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<void> _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<void> _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');
// }
// }
// }
Loading…
Cancel
Save