Browse Source

添加完善信息接口

ios
Jolie 4 months ago
parent
commit
42689c1d68
4 changed files with 87 additions and 27 deletions
  1. 1
      lib/network/api_urls.dart
  2. 5
      lib/network/user_api.dart
  3. 34
      lib/network/user_api.g.dart
  4. 74
      lib/pages/mine/user_info_controller.dart

1
lib/network/api_urls.dart

@ -8,6 +8,7 @@ class ApiUrls {
//
static const String getBaseUserInfo = 'dating-agency-uec/user/get/base-info';
static const String getMarriageInformationDetail = 'dating-agency-service/user/get/dongwo/marriage-information-detail';
static const String registerMarriageInformation = 'dating-agency-service/user/register/marriage-information';
// API端点
}

5
lib/network/user_api.dart

@ -29,4 +29,9 @@ abstract class UserApi {
Future<HttpResponse<BaseResponse<dynamic>>> getVerificationCode(
@Body() Map<String, dynamic> data,
);
@POST(ApiUrls.registerMarriageInformation)
Future<HttpResponse<BaseResponse<dynamic>>> registerMarriageInformation(
@Body() Map<String, dynamic> data,
);
}

34
lib/network/user_api.g.dart

@ -152,6 +152,40 @@ class _UserApi implements UserApi {
return httpResponse;
}
@override
Future<HttpResponse<BaseResponse<dynamic>>> registerMarriageInformation(
Map<String, dynamic> data,
) async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
final _data = <String, dynamic>{};
_data.addAll(data);
final _options = _setStreamType<HttpResponse<BaseResponse<dynamic>>>(
Options(method: 'POST', headers: _headers, extra: _extra)
.compose(
_dio.options,
'dating-agency-service/user/register/marriage-information',
queryParameters: queryParameters,
data: _data,
)
.copyWith(baseUrl: _combineBaseUrls(_dio.options.baseUrl, baseUrl)),
);
final _result = await _dio.fetch<Map<String, dynamic>>(_options);
late BaseResponse<dynamic> _value;
try {
_value = BaseResponse<dynamic>.fromJson(
_result.data!,
(json) => json as dynamic,
);
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;
}
final httpResponse = HttpResponse(_value, _result);
return httpResponse;
}
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
if (T != dynamic &&
!(requestOptions.responseType == ResponseType.bytes ||

74
lib/pages/mine/user_info_controller.dart

@ -1,10 +1,10 @@
import 'dart:io';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:image_picker/image_picker.dart';
import 'package:dating_touchme_app/network/user_api.dart';
import 'package:dating_touchme_app/pages/main_page.dart';
class UserInfoController extends GetxController {
//
@ -20,6 +20,9 @@ class UserInfoController extends GetxController {
// GetStorage实例
final storage = GetStorage();
// UserApi实例
late UserApi _userApi;
//
void selectGender(String selectedGender) {
@ -93,6 +96,13 @@ class UserInfoController extends GetxController {
}
}
@override
void onInit() {
super.onInit();
// UserApi
_userApi = Get.find<UserApi>();
}
//
Future<void> processSelectedImage(File imageFile) async {
try {
@ -150,13 +160,30 @@ class UserInfoController extends GetxController {
//
Map<String, dynamic> _buildSubmitParams() {
// birthday字符串中提取年份
int birthYear = 0;
if (birthday.value.isNotEmpty) {
// birthday格式为YYYY-MM-DD
final parts = birthday.value.split('-');
if (parts.isNotEmpty) {
birthYear = int.tryParse(parts[0]) ?? 0;
}
}
//
Map<String, String> educationCodeMap = {
'大专以下': '0',
'大专': '1',
'本科': '2',
'硕士及以上': '3'
};
return {
'gender': gender.value == 'male' ? 1 : 2, // 1:, 2:
'nickname': nickname.value,
'birthday': birthday.value,
'education': education.value,
if (invitationCode.value.isNotEmpty) 'invitationCode': invitationCode.value,
if (avatarUrl.value.isNotEmpty) 'avatarUrl': avatarUrl.value,
'birthYear': birthYear,
'educationCode': educationCodeMap[education.value] ?? '0',
'genderCode': gender.value == 'male' ? '0' : '1', // 1:, 2:
'matchmakerInvitationCode': invitationCode.value,
'nickName': nickname.value,
};
}
@ -172,23 +199,15 @@ class UserInfoController extends GetxController {
try {
//
final params = _buildSubmitParams();
// UserApi中的完善用户信息接口
// UserApi中添加updateUserInfo方法
// API定义
// API
//
await Future.delayed(const Duration(seconds: 1));
//
print('提交用户信息参数: $params');
//
// final response = await _userApi.updateUserInfo(params);
//
final response = await _userApi.registerMarriageInformation(params);
//
// if (response.data.isSuccess) {
if (response.data.isSuccess) {
//
final currentUserInfo = storage.read('userInfo') ?? {};
if (currentUserInfo is Map<String, dynamic>) {
@ -203,14 +222,15 @@ class UserInfoController extends GetxController {
//
SmartDialog.showToast('信息提交成功!');
//
Future.delayed(const Duration(milliseconds: 1500), () {
// 使
// Get.offAllNamed('/main');
});
// } else {
// Get.snackbar('错误', response.data.message);
// }
//
Future.delayed(const Duration(milliseconds: 1500), () {
// MainPage
Get.offAll(() => MainPage());
});
} else {
SmartDialog.showToast(response.data.message);
}
} catch (e) {
print('提交用户信息失败: $e');
//

Loading…
Cancel
Save