194 lines
6.8 KiB
Dart
194 lines
6.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import '../../../apis/app.dart';
|
|
import '../../../components/CustomAlertDialog.dart';
|
|
import '../../../components/appbar.dart';
|
|
import '../../../providers/auth_provider.dart';
|
|
|
|
class SettingPage extends StatefulWidget {
|
|
const SettingPage({super.key, required this.userInfo});
|
|
final Map userInfo;
|
|
|
|
@override
|
|
State<SettingPage> createState() => _SettingPageState();
|
|
}
|
|
|
|
class _SettingPageState extends State<SettingPage> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
resizeToAvoidBottomInset: false, // 解决点击输入框弹出键盘导致底部像素溢出的问题
|
|
appBar: const CustomAppBar(title: '设置'),
|
|
body: Container(
|
|
width: MediaQuery.of(context).size.width,
|
|
height: MediaQuery.of(context).size.height,
|
|
decoration: const BoxDecoration(
|
|
// color: Color(0xff0C0C16),
|
|
image: DecorationImage(
|
|
image: AssetImage('images/pwd_bg.png'),
|
|
fit: BoxFit.fill,
|
|
),
|
|
),
|
|
child: ListView(
|
|
padding: const EdgeInsets.all(0),
|
|
children: [
|
|
_buildSettingItem(
|
|
title: '我的信息',
|
|
onTap: () {
|
|
// 跳转到我的信息页面
|
|
Navigator.pushNamed(context, '/myInfo',
|
|
arguments: widget.userInfo);
|
|
},
|
|
),
|
|
_buildSettingItem(
|
|
title: '修改密码',
|
|
onTap: () {
|
|
// 跳转到修改密码页面
|
|
Navigator.pushNamed(context, '/checkAuthentication');
|
|
},
|
|
),
|
|
_buildSettingItem(
|
|
title: '关于我们',
|
|
onTap: () {
|
|
// 跳转到关于我们页面
|
|
Navigator.pushNamed(context, '/aboutUs');
|
|
},
|
|
),
|
|
_buildSettingItem(
|
|
title: '注销账号',
|
|
onTap: () {
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (BuildContext context) {
|
|
return CustomAlertDialog(
|
|
title: '是否确认注销账号?',
|
|
content: '如果您注销账号,所有留存的信息及充值记录将被清空无法找回。',
|
|
onConfirm: () async {
|
|
Navigator.of(context).pop(); // 关闭对话框
|
|
|
|
try {
|
|
final result = await userApi.cancelAccount();
|
|
if (result['code'] == 200) {
|
|
// 清除本地存储
|
|
SharedPreferences prefs =
|
|
await SharedPreferences.getInstance();
|
|
await prefs.clear(); // 清除所有存储数据
|
|
|
|
// 清除 token
|
|
if (context.mounted) {
|
|
await Provider.of<AuthProvider>(context,
|
|
listen: false)
|
|
.clearToken();
|
|
|
|
// 使用 pushNamedAndRemoveUntil 清除所有路由历史并跳转到登录页
|
|
Navigator.of(context).pushNamedAndRemoveUntil(
|
|
'/login',
|
|
(route) => false,
|
|
);
|
|
}
|
|
} else {
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text(result['msg'] ?? '注销失败')),
|
|
);
|
|
}
|
|
}
|
|
} catch (e) {
|
|
if (context.mounted) {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('注销失败,请稍后重试')),
|
|
);
|
|
}
|
|
}
|
|
},
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
_buildSettingItem(
|
|
title: '退出登录',
|
|
onTap: () {
|
|
showDialog(
|
|
context: context,
|
|
barrierDismissible: false,
|
|
builder: (BuildContext context) {
|
|
return CustomAlertDialog(
|
|
title: '确认退出当前账号吗?',
|
|
content: '',
|
|
onConfirm: () {
|
|
Navigator.of(context).pop(); // 先关闭对话框
|
|
userApi.getLogout().then((result) async {
|
|
if (result['code'] == 200) {
|
|
print("退出成功");
|
|
SharedPreferences prefs =
|
|
await SharedPreferences.getInstance();
|
|
await prefs.clear(); // 清除所有存储数据
|
|
// 跳转到登录页面
|
|
Navigator.of(context)
|
|
.pushReplacementNamed('/login');
|
|
} else {
|
|
print("发送失败");
|
|
}
|
|
});
|
|
|
|
// 处理退出登录逻辑
|
|
// Navigator.of(context).pop();
|
|
},
|
|
);
|
|
},
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// 创建每一行的设置项
|
|
Widget _buildSettingItem({
|
|
required String title,
|
|
required VoidCallback onTap,
|
|
}) {
|
|
return Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16.0, // 修改左右边距为16
|
|
vertical: 6.0, // 修改上下间距为12
|
|
),
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
child: Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
decoration: const BoxDecoration(
|
|
color: Color(0xFF1F212E),
|
|
borderRadius: BorderRadius.all(Radius.circular(10)),
|
|
),
|
|
height: 60,
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: const TextStyle(
|
|
color: Color(0xffC1C1C1),
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
Image.asset(
|
|
'images/right_arraw.png',
|
|
width: 16,
|
|
height: 16,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|