ar_tourism_flutter_unity/lib/pages/mine/authInfo.dart
2025-05-14 17:04:13 +08:00

139 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import '../../components/appbar.dart';
import '../../apis/app.dart';
class AuthInfoPage extends StatefulWidget {
const AuthInfoPage({super.key});
@override
State<AuthInfoPage> createState() => _AuthInfoPageState();
}
class _AuthInfoPageState extends State<AuthInfoPage> {
Map<String, dynamic> authInfo = {};
bool isLoading = true;
String? error;
@override
void initState() {
super.initState();
_loadAuthInfo();
}
Future<void> _loadAuthInfo() async {
try {
final result = await userApi.getAuthInfo();
if (mounted) {
setState(() {
if (result['code'] == 200) {
authInfo = result['data'];
isLoading = false;
} else {
error = result['msg'] ?? '获取认证信息失败';
isLoading = false;
}
});
}
} catch (e) {
if (mounted) {
setState(() {
error = '获取认证信息失败';
isLoading = false;
});
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: const CustomAppBar(
title: '认证信息',
),
body: Container(
decoration: const BoxDecoration(
color: Color(0xff0C0C16),
),
child: isLoading
? const Center(
child: CircularProgressIndicator(
color: Color(0xFF70DEED),
),
)
: error != null
? Center(
child: Text(
error!,
style: const TextStyle(color: Colors.white),
),
)
: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
children: [
_buildInfoItem('真实姓名', authInfo['realName'] ?? ''),
_buildInfoItem(
'证件类型',
_getIdTypeName(authInfo['idType'] ?? '0'),
),
_buildInfoItem(
'证件号码',
_maskIdCard(authInfo['idCard'] ?? ''),
),
],
),
),
),
);
}
String _getIdTypeName(String idType) {
// 根据实际情况添加更多证件类型
switch (idType) {
case '0':
return '居民身份证';
default:
return '其他证件';
}
}
Widget _buildInfoItem(String label, String value) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 16),
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: Color(0xFF2A2C39),
width: 1,
),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
label,
style: const TextStyle(
color: Color(0xFFC1C1C1),
fontSize: 14,
),
),
Text(
value,
style: const TextStyle(
color: Colors.white,
fontSize: 14,
),
),
],
),
);
}
String _maskIdCard(String idCard) {
if (idCard.length >= 18) {
return '${idCard.substring(0, 3)}************${idCard.substring(15)}';
}
return idCard;
}
}