4 changed files with 391 additions and 1 deletions
Unified View
Diff Options
-
62lib/controller/mine/auth_controller.dart
-
111lib/pages/mine/auth_center_page.dart
-
1lib/pages/mine/login_page.dart
-
218lib/pages/mine/real_name_page.dart
@ -0,0 +1,62 @@ |
|||||
|
import 'dart:async'; |
||||
|
import 'package:get/get.dart'; |
||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
||||
|
import '../../network/user_api.dart'; |
||||
|
|
||||
|
class AuthController extends GetxController { |
||||
|
final isLoading = false.obs; |
||||
|
final List<AuthCard> dataList = []; |
||||
|
// 是否正在登录中 |
||||
|
final isLoggingIn = false.obs; |
||||
|
// 从GetX依赖注入中获取UserApi实例 |
||||
|
late UserApi _userApi; |
||||
|
|
||||
|
@override |
||||
|
void onInit() { |
||||
|
super.onInit(); |
||||
|
// 从全局依赖中获取UserApi |
||||
|
_userApi = Get.find<UserApi>(); |
||||
|
_loadInitialData(); |
||||
|
} |
||||
|
void _loadInitialData() { |
||||
|
isLoading.value = true; |
||||
|
Future.delayed(Duration(seconds: 1), () { |
||||
|
dataList.assignAll([ |
||||
|
AuthCard( title: '手机绑定', desc: '防止账号丢失', index: 1), |
||||
|
AuthCard( title: '真实头像', desc: '提高交友成功率', index: 2), |
||||
|
AuthCard( title: '实名认证', desc: '提高交友成功率', index: 3), |
||||
|
]); |
||||
|
isLoading.value = false; |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
// 登录方法 |
||||
|
Future<void> login() async { |
||||
|
try { |
||||
|
// 调用登录接口 |
||||
|
final response = await _userApi.login({}); |
||||
|
// 处理响应 |
||||
|
if (response.data.isSuccess) { |
||||
|
|
||||
|
} else { |
||||
|
SmartDialog.showToast(response.data.message); |
||||
|
} |
||||
|
} catch (e) { |
||||
|
SmartDialog.showToast('网络请求失败,请检查网络连接'); |
||||
|
} finally { |
||||
|
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
class AuthCard { |
||||
|
final String title; |
||||
|
final String desc; |
||||
|
final int index; |
||||
|
|
||||
|
AuthCard({ |
||||
|
required this.desc, |
||||
|
required this.title, |
||||
|
required this.index, |
||||
|
}); |
||||
|
} |
||||
@ -0,0 +1,111 @@ |
|||||
|
import 'package:dating_touchme_app/extension/ex_widget.dart'; |
||||
|
import 'package:flutter/cupertino.dart'; |
||||
|
import 'package:flutter/material.dart'; |
||||
|
import 'package:get/get.dart'; |
||||
|
|
||||
|
import '../../controller/mine/auth_controller.dart'; |
||||
|
|
||||
|
class AuthCenterPage extends StatelessWidget { |
||||
|
AuthCenterPage({super.key}); |
||||
|
final AuthController controller = Get.put(AuthController()); |
||||
|
|
||||
|
@override |
||||
|
Widget build(BuildContext context) { |
||||
|
return Scaffold( |
||||
|
backgroundColor: Color(0xffF5F5F5), |
||||
|
appBar: AppBar( |
||||
|
title: Text('认证中心', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), |
||||
|
centerTitle: true, |
||||
|
leading: IconButton( |
||||
|
icon: Icon(Icons.arrow_back_ios, size: 24, color: Colors.grey,), |
||||
|
onPressed: () { |
||||
|
Get.back(); |
||||
|
}, |
||||
|
), |
||||
|
), |
||||
|
body: Obx(() { |
||||
|
if (controller.isLoading.value) { |
||||
|
return const Center(child: CupertinoActivityIndicator(radius: 12,)); |
||||
|
} |
||||
|
return ListView.builder( |
||||
|
padding: const EdgeInsets.only(top: 16, right: 16, left: 16), |
||||
|
itemCount: controller.dataList.length, |
||||
|
itemBuilder: (context, index) { |
||||
|
final record = controller.dataList[index]; |
||||
|
return _buildListItem(record); |
||||
|
}, |
||||
|
); |
||||
|
}) |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
// 构建列表项 |
||||
|
Widget _buildListItem(AuthCard item) { |
||||
|
return Container( |
||||
|
margin: EdgeInsets.only(bottom: 12), |
||||
|
padding: EdgeInsets.all(24), |
||||
|
decoration: BoxDecoration( |
||||
|
color: Colors.white, |
||||
|
borderRadius: BorderRadius.circular(12), |
||||
|
), |
||||
|
child: Row( |
||||
|
crossAxisAlignment: CrossAxisAlignment.center, |
||||
|
children: [ |
||||
|
// 左侧图片 |
||||
|
Container( |
||||
|
width: 40, |
||||
|
height: 40, |
||||
|
decoration: BoxDecoration( |
||||
|
borderRadius: BorderRadius.circular(8), |
||||
|
color: Colors.blue[100], |
||||
|
image: DecorationImage( |
||||
|
image: NetworkImage('https://picsum.photos/40/40?random=$item.index'), |
||||
|
fit: BoxFit.cover, |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
SizedBox(width: 12), |
||||
|
// 右侧内容 |
||||
|
Column( |
||||
|
crossAxisAlignment: CrossAxisAlignment.start, |
||||
|
children: [ |
||||
|
Text( |
||||
|
item.title, |
||||
|
style: TextStyle( |
||||
|
fontSize: 14, |
||||
|
fontWeight: FontWeight.bold, |
||||
|
color: Colors.grey[800], |
||||
|
), |
||||
|
), |
||||
|
SizedBox(height: 2), |
||||
|
Text( |
||||
|
item.desc, |
||||
|
style: TextStyle( |
||||
|
fontSize: 12, |
||||
|
color: Colors.grey[600], |
||||
|
), |
||||
|
maxLines: 1, |
||||
|
overflow: TextOverflow.ellipsis, |
||||
|
), |
||||
|
], |
||||
|
), |
||||
|
Spacer(), |
||||
|
Row( |
||||
|
children: [ |
||||
|
Text('去认证', style: TextStyle(fontSize: 12, color: Colors.grey[500])), |
||||
|
SizedBox(width: 4), |
||||
|
Icon( |
||||
|
Icons.navigate_next, // Material Icons |
||||
|
// size: 128.0, // 设置图标大小 |
||||
|
color: Colors.grey, // 设置图标颜色 |
||||
|
) |
||||
|
], |
||||
|
) |
||||
|
], |
||||
|
), |
||||
|
).onTap((){ |
||||
|
print(item.index); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,218 @@ |
|||||
|
import 'package:flutter/cupertino.dart'; |
||||
|
import 'package:flutter/material.dart'; |
||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; |
||||
|
import 'package:get/get.dart'; |
||||
|
|
||||
|
import '../../controller/mine/auth_controller.dart'; |
||||
|
|
||||
|
class RealNamePage extends StatelessWidget { |
||||
|
RealNamePage({super.key}); |
||||
|
final AuthController controller = Get.put(AuthController()); |
||||
|
// 是否同意协议 |
||||
|
final agreeTerms = Rx<bool>(false); |
||||
|
@override |
||||
|
Widget build(BuildContext context) { |
||||
|
return Scaffold( |
||||
|
backgroundColor: Color(0xffFFFFFF), |
||||
|
appBar: AppBar( |
||||
|
title: Text('实名认证', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), |
||||
|
centerTitle: true, |
||||
|
leading: IconButton( |
||||
|
icon: Icon(Icons.arrow_back_ios, size: 24, color: Colors.grey,), |
||||
|
onPressed: () { |
||||
|
Get.back(); |
||||
|
}, |
||||
|
), |
||||
|
), |
||||
|
body: Column( |
||||
|
children: [ |
||||
|
Container( |
||||
|
height: 48, |
||||
|
decoration: BoxDecoration(color: Color(0xffE7E7E7)), |
||||
|
padding: const EdgeInsets.only(left: 16), |
||||
|
child: Row( |
||||
|
crossAxisAlignment: CrossAxisAlignment.center, // 垂直居中 |
||||
|
children: [ |
||||
|
Text( |
||||
|
'*请填写本人实名信息', |
||||
|
style: TextStyle( |
||||
|
fontSize: 14, |
||||
|
color: Colors.black87, |
||||
|
), |
||||
|
), |
||||
|
], |
||||
|
), |
||||
|
), |
||||
|
Container( |
||||
|
height: 56, // 固定高度确保垂直居中 |
||||
|
decoration: BoxDecoration( |
||||
|
border: Border( |
||||
|
bottom: BorderSide( |
||||
|
color: Colors.grey[400]!, |
||||
|
width: 0.5, |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
child: Row( |
||||
|
crossAxisAlignment: CrossAxisAlignment.center, // 垂直居中 |
||||
|
children: [ |
||||
|
// 左侧标签 - 固定宽度 + 垂直居中 |
||||
|
Container( |
||||
|
width: 100, |
||||
|
alignment: Alignment.centerLeft, |
||||
|
padding: const EdgeInsets.only(left: 16), |
||||
|
child: Text( |
||||
|
'姓名:', |
||||
|
style: TextStyle( |
||||
|
fontSize: 15, |
||||
|
color: Colors.black87, |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
SizedBox(width: 12), |
||||
|
|
||||
|
// 输入框区域 - 使用Expanded填充剩余空间 |
||||
|
Expanded( |
||||
|
child: Container( |
||||
|
alignment: Alignment.centerLeft, // 输入框内容垂直居中 |
||||
|
child: TextField( |
||||
|
decoration: InputDecoration( |
||||
|
hintText: '请输入姓名', |
||||
|
hintStyle: TextStyle(color: Colors.grey[500]), |
||||
|
border: InputBorder.none, // 隐藏默认边框 |
||||
|
contentPadding: EdgeInsets.zero, // 去除默认padding |
||||
|
isDense: true, // 紧凑模式 |
||||
|
), |
||||
|
style: TextStyle( |
||||
|
fontSize: 15, |
||||
|
height: 1.2, // 控制文字垂直位置 |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
], |
||||
|
), |
||||
|
), |
||||
|
// SizedBox(height: 30), |
||||
|
Container( |
||||
|
height: 56, // 固定高度确保垂直居中 |
||||
|
decoration: BoxDecoration( |
||||
|
border: Border( |
||||
|
bottom: BorderSide( |
||||
|
color: Colors.grey[400]!, |
||||
|
width: 0.5, |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
child: Row( |
||||
|
crossAxisAlignment: CrossAxisAlignment.center, // 垂直居中 |
||||
|
children: [ |
||||
|
// 左侧标签 - 固定宽度 + 垂直居中 |
||||
|
Container( |
||||
|
width: 100, |
||||
|
alignment: Alignment.centerLeft, |
||||
|
padding: const EdgeInsets.only(left: 16), |
||||
|
child: Text( |
||||
|
'身份证号:', |
||||
|
style: TextStyle( |
||||
|
fontSize: 15, |
||||
|
color: Colors.black87, |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
SizedBox(width: 12), |
||||
|
|
||||
|
// 输入框区域 - 使用Expanded填充剩余空间 |
||||
|
Expanded( |
||||
|
child: Container( |
||||
|
alignment: Alignment.centerLeft, // 输入框内容垂直居中 |
||||
|
child: TextField( |
||||
|
decoration: InputDecoration( |
||||
|
hintText: '请输入身份证号', |
||||
|
hintStyle: TextStyle(color: Colors.grey[500]), |
||||
|
border: InputBorder.none, // 隐藏默认边框 |
||||
|
contentPadding: EdgeInsets.zero, // 去除默认padding |
||||
|
isDense: true, // 紧凑模式 |
||||
|
), |
||||
|
style: TextStyle( |
||||
|
fontSize: 15, |
||||
|
height: 1.2, // 控制文字垂直位置 |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
], |
||||
|
), |
||||
|
), |
||||
|
SizedBox(height: 24), |
||||
|
// 协议同意复选框 |
||||
|
Row( |
||||
|
crossAxisAlignment: CrossAxisAlignment.start, // 垂直居中 |
||||
|
children: [ |
||||
|
SizedBox(width: 8), |
||||
|
Obx(() => Checkbox( |
||||
|
value: agreeTerms.value, |
||||
|
onChanged: (value) { |
||||
|
agreeTerms.value = value ?? false; |
||||
|
}, |
||||
|
activeColor: Color(0xff7562F9), |
||||
|
side: const BorderSide(color: Colors.grey), |
||||
|
shape: const CircleBorder(), |
||||
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, |
||||
|
)), |
||||
|
ConstrainedBox( |
||||
|
constraints: BoxConstraints(maxWidth: 300), // 限制最大宽度 |
||||
|
child: Text( |
||||
|
'前排吃瓜,这里的瓜包新鲜,这里的人士有料有梗有灼见~,这里的瓜包新鲜,这里的人士有料有梗有灼见~', |
||||
|
style: TextStyle( fontSize: 13, color: Colors.grey ), |
||||
|
), |
||||
|
) |
||||
|
], |
||||
|
), |
||||
|
SizedBox(height: 48), |
||||
|
Container( |
||||
|
padding: const EdgeInsets.only(left: 24, right: 24), |
||||
|
child: ElevatedButton( |
||||
|
onPressed: controller.isLoggingIn.value |
||||
|
? null |
||||
|
: () { |
||||
|
// 登录逻辑 |
||||
|
if (!agreeTerms.value) { |
||||
|
SmartDialog.showToast('请同意用户协议和隐私政策'); |
||||
|
return; |
||||
|
} |
||||
|
// 调用控制器的登录方法 |
||||
|
controller.login(); |
||||
|
}, |
||||
|
style: ElevatedButton.styleFrom( |
||||
|
minimumSize: const Size(double.infinity, 50), |
||||
|
backgroundColor: agreeTerms.value ? const Color(0xff7562F9) : Colors.grey.shade300, |
||||
|
shape: RoundedRectangleBorder( |
||||
|
borderRadius: BorderRadius.circular(25), |
||||
|
), |
||||
|
elevation: 0, |
||||
|
), |
||||
|
child: controller.isLoggingIn.value ? const SizedBox( |
||||
|
width: 20, |
||||
|
height: 20, |
||||
|
child: CircularProgressIndicator( |
||||
|
color: Colors.white, |
||||
|
strokeWidth: 1, |
||||
|
), |
||||
|
) |
||||
|
: const Text( |
||||
|
'立即认证', |
||||
|
style: TextStyle( |
||||
|
fontSize: 16, |
||||
|
fontWeight: FontWeight.bold, |
||||
|
color: Colors.white, |
||||
|
), |
||||
|
), |
||||
|
), |
||||
|
) |
||||
|
], |
||||
|
), |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save