import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:qhd_prevention/customWidget/custom_alert_dialog.dart'; import 'package:qhd_prevention/customWidget/custom_button.dart'; import 'package:qhd_prevention/customWidget/toast_util.dart'; import 'package:qhd_prevention/pages/home/scan_page.dart'; import 'package:qhd_prevention/pages/home/userinfo_page.dart'; import 'package:qhd_prevention/pages/mine/face_ecognition_page.dart'; import 'package:qhd_prevention/pages/mine/mine_feedback_page.dart'; import 'package:qhd_prevention/pages/mine/mine_set_pwd_page.dart'; import 'package:qhd_prevention/pages/mine/onboarding_full_page.dart'; import 'package:qhd_prevention/pages/user/full_userinfo_page.dart'; import 'package:qhd_prevention/pages/user/login_page.dart'; import 'package:qhd_prevention/services/SessionService.dart'; import 'package:qhd_prevention/tools/tools.dart'; import 'package:shared_preferences/shared_preferences.dart'; class MinePage extends StatefulWidget { const MinePage({super.key}); @override State createState() => MinePageState(); } class MinePageState extends State { // 设置项状态 bool notificationsEnabled = false; bool passwordChanged = false; bool updateAvailable = false; bool logoutSelected = false; bool faceAuthentication = false; bool scanAuthentication = false; String name = '登录/注册'; String phone = ''; void onRouteConfigLoaded() { if (mounted) { setState(() { // _updateMenuVisibility(); }); } } @override void initState() { // TODO: implement initState super.initState(); name = SessionService.instance.name ?? "登录/注册"; phone = SessionService.instance.phone ?? ""; } @override @override Widget build(BuildContext context) { final double headerHeight = 300.0; final double overlap = 100.0; return SizedBox( height: MediaQuery.of(context).size.height, child: Stack( children: [ Positioned( top: 0, left: 0, right: 0, height: headerHeight, child: _buildHeaderSection(), ), Positioned.fill( child: NotificationListener( onNotification: (overscroll) { overscroll.disallowIndicator(); return false; }, child: ListView( padding: EdgeInsets.only( top: headerHeight - overlap, bottom: 24, left: 0, right: 0, ), children: [ _buildSettingsList(), SizedBox(height: 15), Padding( padding: EdgeInsetsGeometry.symmetric(horizontal: 15), child: CustomButton( text: '退出登录', textStyle: TextStyle(fontSize: 16), backgroundColor: Colors.blue, // borderRadius: 15, onPressed: () { CustomAlertDialog.showConfirm( context, title: '确认退出', content: '确定要退出当前账号吗', onConfirm: () async { // await AuthService.logout(); // ✅ 等待登出完成 // if (!mounted) return; // 清除用户登录状态 await _clearUserSession(); Navigator.pushAndRemoveUntil( context, MaterialPageRoute( builder: (context) => const LoginPage(), ), (Route route) => false, ); }, ); }, ), ), ], ), ), ), ], ), ); } Widget _buildHeaderSection() { return Stack( alignment: const FractionalOffset(0.5, 0), children: [ Padding( padding: EdgeInsets.fromLTRB(0, 0, 0, 10), child: Image.asset( "assets/images/my_bg.png", width: MediaQuery.of(context).size.width, // 获取屏幕宽度 fit: BoxFit.cover, ), ), Positioned( top: 51, child: Text( "我的", style: TextStyle( color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold, ), ), ), // 标语区域 _buildSloganSection(), ], ); } Widget _buildSloganSection() { return Container( margin: EdgeInsets.fromLTRB(0, 100, 0, 0), padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 20), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, // 水平居中 // crossAxisAlignment: CrossAxisAlignment.center, // 垂直居中(可选) children: [ Row( children: [ CircleAvatar( backgroundImage: AssetImage("assets/images/my_bg.png"), radius: 30, ), const SizedBox(width: 16), Text( name, style: TextStyle( fontSize: 18, fontWeight: FontWeight.bold, color: Colors.white, ), ), ], ), const SizedBox(width: 16), ], ), ); } Widget _buildSettingsList() { return Container( margin: const EdgeInsets.fromLTRB(20, 0, 20, 0), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(16), boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.1), spreadRadius: 2, blurRadius: 8, offset: const Offset(0, 4), ), ], ), child: Column( children: [ _buildSettingItem( title: "我的信息", icon: "assets/images/ico9.png", value: notificationsEnabled, num: 0, onChanged: (value) => setState(() => notificationsEnabled = value!), ), _buildSettingItem( title: "修改密码", icon: "assets/images/ico16.png", value: notificationsEnabled, num: 1, onChanged: (value) async { await pushPage(MineSetPwdPage('0'), context); }, ), _buildSettingItem( title: "扫码入职", icon: "assets/images/ico10.png", value: scanAuthentication, num: 2, onChanged: (value) async {}, ), _buildSettingItem( title: "人脸认证", icon: "assets/images/ico11.png", value: faceAuthentication, num: 3, onChanged: (value) => setState(() => faceAuthentication = value!), ), _buildSettingItem( title: "证书信息", icon: "assets/images/ico12.png", value: passwordChanged, num: 4, onChanged: (value) => setState(() => passwordChanged = value!), ), _buildSettingItem( title: "问题反馈", icon: "assets/images/ico13.png", value: passwordChanged, num: 5, onChanged: (value) => setState(() => passwordChanged = value!), ), // const Divider(height: 1, indent: 60), _buildSettingItem( title: "版本更新", icon: "assets/images/ico14.png", value: updateAvailable, num: 6, onChanged: (value) => setState(() => updateAvailable = value!), ), _buildSettingItem( title: "关于我们", icon: "assets/images/ico15.png", value: logoutSelected, num: 7, onChanged: (value) { setState(() => logoutSelected = value!); // if (value == true) { // _showLogoutConfirmation(); // } }, ), _buildSettingItem( title: "账户注销", icon: "assets/images/ico15.png", value: logoutSelected, num: 8, onChanged: (value) { }, ), ], ), ); } Widget _buildSettingItem({ required String title, required String icon, required bool value, required int num, required ValueChanged onChanged, }) { return GestureDetector( onTap: () async { switch (num) { case 0: pushPage(FullUserinfoPage(isEidt: false, isChooseFirm: true,), context); break; case 1: await pushPage(MineSetPwdPage('0'), context); break; case 2: final result = await pushPage( ScanPage(type: ScanType.Onboarding), context, ); if (result == null) { return; } pushPage(OnboardingFullPage(scanData: result), context); break; case 3: pushPage( const FaceRecognitionPage( studentId: '', data: {}, mode: FaceMode.setUpdata, ), context, ); // pushPage(ChangePassPage(), context); break; case 4: // _showLogoutConfirmation(); break; case 5: pushPage(FeedbackPage(), context); break; case 6: break; case 7: break; } }, child: ListTile( leading: Container( width: 20, height: 20, decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(10), ), child: Image.asset(icon, fit: BoxFit.cover), ), title: Text( title, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500), ), trailing: Transform.scale( scale: 1.2, child: Icon(Icons.chevron_right), // Image.asset( // "assets/images/right.png", // fit: BoxFit.cover, // width: 15, // height: 15, // ), ), ), ); } Widget _buildActionButton() { return SizedBox( width: double.infinity, child: ElevatedButton( onPressed: () { // 保存设置逻辑 _saveSettings(); }, style: ElevatedButton.styleFrom( backgroundColor: const Color(0xFF1A237E), foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(vertical: 16), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), elevation: 3, // 注意:elevation应该放在styleFrom内部 ), child: const Text( "保存设置", style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600), ), ), ); } void _saveSettings() { // 这里可以添加保存设置到服务器的逻辑 ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: const Text("设置已保存成功"), backgroundColor: Colors.green[700], duration: const Duration(seconds: 2), behavior: SnackBarBehavior.floating, shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), ), ); } Future _clearUserSession() async { final prefs = await SharedPreferences.getInstance(); await prefs.remove('isLoggedIn'); // 清除登录状态 } } class _StatItem extends StatelessWidget { final String number; final String label; const _StatItem({required this.number, required this.label}); @override Widget build(BuildContext context) { return Column( children: [ // 数字圆圈 Center( child: Text( number, style: const TextStyle( color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold, ), ), ), const SizedBox(height: 8), // 标签 Text( label, style: TextStyle( fontSize: 12, color: Colors.grey[600], fontWeight: FontWeight.w500, ), ), ], ); } }