init
This commit is contained in:
501
client/lib/features/profile/screens/change_password_screen.dart
Normal file
501
client/lib/features/profile/screens/change_password_screen.dart
Normal file
@@ -0,0 +1,501 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_text_styles.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
import '../../../core/widgets/custom_button.dart';
|
||||
import '../../../core/widgets/custom_text_field.dart';
|
||||
import '../../auth/providers/auth_provider.dart';
|
||||
|
||||
/// 修改密码屏幕
|
||||
class ChangePasswordScreen extends StatefulWidget {
|
||||
const ChangePasswordScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ChangePasswordScreen> createState() => _ChangePasswordScreenState();
|
||||
}
|
||||
|
||||
class _ChangePasswordScreenState extends State<ChangePasswordScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _currentPasswordController = TextEditingController();
|
||||
final _newPasswordController = TextEditingController();
|
||||
final _confirmPasswordController = TextEditingController();
|
||||
|
||||
bool _isLoading = false;
|
||||
bool _obscureCurrentPassword = true;
|
||||
bool _obscureNewPassword = true;
|
||||
bool _obscureConfirmPassword = true;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_currentPasswordController.dispose();
|
||||
_newPasswordController.dispose();
|
||||
_confirmPasswordController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: _buildAppBar(),
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 标题和说明
|
||||
_buildHeader(),
|
||||
const SizedBox(height: AppDimensions.spacingXl),
|
||||
|
||||
// 密码输入表单
|
||||
_buildPasswordForm(),
|
||||
const SizedBox(height: AppDimensions.spacingXl),
|
||||
|
||||
// 密码强度提示
|
||||
_buildPasswordStrengthTips(),
|
||||
const SizedBox(height: AppDimensions.spacingXl),
|
||||
|
||||
// 提交按钮
|
||||
_buildSubmitButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建应用栏
|
||||
PreferredSizeWidget _buildAppBar() {
|
||||
return AppBar(
|
||||
backgroundColor: AppColors.surface,
|
||||
foregroundColor: AppColors.onSurface,
|
||||
elevation: 0,
|
||||
title: Text(
|
||||
'修改密码',
|
||||
style: AppTextStyles.titleLarge.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建头部
|
||||
Widget _buildHeader() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
border: Border.all(
|
||||
color: AppColors.primary.withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.security,
|
||||
color: AppColors.primary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'安全提示',
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingXs),
|
||||
|
||||
Text(
|
||||
'为了您的账户安全,建议定期更换密码,并使用包含字母、数字和特殊字符的强密码。',
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建密码表单
|
||||
Widget _buildPasswordForm() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.shadow.withOpacity(0.05),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// 当前密码
|
||||
CustomTextField(
|
||||
controller: _currentPasswordController,
|
||||
labelText: '当前密码',
|
||||
hintText: '请输入当前密码',
|
||||
obscureText: _obscureCurrentPassword,
|
||||
prefixIcon: Icons.lock_outline,
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscureCurrentPassword ? Icons.visibility : Icons.visibility_off,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscureCurrentPassword = !_obscureCurrentPassword;
|
||||
});
|
||||
},
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入当前密码';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
// 新密码
|
||||
CustomTextField(
|
||||
controller: _newPasswordController,
|
||||
labelText: '新密码',
|
||||
hintText: '请输入新密码',
|
||||
obscureText: _obscureNewPassword,
|
||||
prefixIcon: Icons.lock,
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscureNewPassword ? Icons.visibility : Icons.visibility_off,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscureNewPassword = !_obscureNewPassword;
|
||||
});
|
||||
},
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入新密码';
|
||||
}
|
||||
if (value.length < 8) {
|
||||
return '密码长度至少8位';
|
||||
}
|
||||
if (!RegExp(r'^(?=.*[a-zA-Z])(?=.*\d)').hasMatch(value)) {
|
||||
return '密码必须包含字母和数字';
|
||||
}
|
||||
if (value == _currentPasswordController.text) {
|
||||
return '新密码不能与当前密码相同';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
onChanged: (value) {
|
||||
setState(() {}); // 触发密码强度更新
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
// 确认新密码
|
||||
CustomTextField(
|
||||
controller: _confirmPasswordController,
|
||||
labelText: '确认新密码',
|
||||
hintText: '请再次输入新密码',
|
||||
obscureText: _obscureConfirmPassword,
|
||||
prefixIcon: Icons.lock_clock,
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(
|
||||
_obscureConfirmPassword ? Icons.visibility : Icons.visibility_off,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscureConfirmPassword = !_obscureConfirmPassword;
|
||||
});
|
||||
},
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请确认新密码';
|
||||
}
|
||||
if (value != _newPasswordController.text) {
|
||||
return '两次输入的密码不一致';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
|
||||
// 密码强度指示器
|
||||
if (_newPasswordController.text.isNotEmpty) ...[
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
_buildPasswordStrengthIndicator(),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建密码强度指示器
|
||||
Widget _buildPasswordStrengthIndicator() {
|
||||
final password = _newPasswordController.text;
|
||||
final strength = _calculatePasswordStrength(password);
|
||||
|
||||
Color strengthColor;
|
||||
String strengthText;
|
||||
|
||||
switch (strength) {
|
||||
case 0:
|
||||
case 1:
|
||||
strengthColor = AppColors.error;
|
||||
strengthText = '弱';
|
||||
break;
|
||||
case 2:
|
||||
strengthColor = AppColors.warning;
|
||||
strengthText = '中';
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
strengthColor = AppColors.success;
|
||||
strengthText = '强';
|
||||
break;
|
||||
default:
|
||||
strengthColor = AppColors.onSurfaceVariant;
|
||||
strengthText = '未知';
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
'密码强度',
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
strengthText,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: strengthColor,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingXs),
|
||||
|
||||
// 强度条
|
||||
Row(
|
||||
children: List.generate(4, (index) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
height: 4,
|
||||
margin: EdgeInsets.only(
|
||||
right: index < 3 ? AppDimensions.spacingXs : 0,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: index < strength
|
||||
? strengthColor
|
||||
: AppColors.onSurfaceVariant.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建密码强度提示
|
||||
Widget _buildPasswordStrengthTips() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
border: Border.all(
|
||||
color: AppColors.onSurfaceVariant.withOpacity(0.2),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'密码要求',
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingSm),
|
||||
|
||||
..._getPasswordRequirements().map((requirement) {
|
||||
final isValid = _checkPasswordRequirement(
|
||||
_newPasswordController.text,
|
||||
requirement['type'],
|
||||
);
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: AppDimensions.spacingXs),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
isValid ? Icons.check_circle : Icons.radio_button_unchecked,
|
||||
color: isValid ? AppColors.success : AppColors.onSurfaceVariant,
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
|
||||
Expanded(
|
||||
child: Text(
|
||||
requirement['text'],
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: isValid ? AppColors.success : AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建提交按钮
|
||||
Widget _buildSubmitButton() {
|
||||
return CustomButton(
|
||||
text: '修改密码',
|
||||
onPressed: _isLoading ? null : _changePassword,
|
||||
isLoading: _isLoading,
|
||||
width: double.infinity,
|
||||
);
|
||||
}
|
||||
|
||||
/// 计算密码强度
|
||||
int _calculatePasswordStrength(String password) {
|
||||
if (password.isEmpty) return 0;
|
||||
|
||||
int strength = 0;
|
||||
|
||||
// 长度检查
|
||||
if (password.length >= 8) strength++;
|
||||
|
||||
// 包含小写字母
|
||||
if (RegExp(r'[a-z]').hasMatch(password)) strength++;
|
||||
|
||||
// 包含大写字母或数字
|
||||
if (RegExp(r'[A-Z0-9]').hasMatch(password)) strength++;
|
||||
|
||||
// 包含特殊字符
|
||||
if (RegExp(r'[!@#$%^&*(),.?":{}|<>]').hasMatch(password)) strength++;
|
||||
|
||||
return strength;
|
||||
}
|
||||
|
||||
/// 获取密码要求列表
|
||||
List<Map<String, dynamic>> _getPasswordRequirements() {
|
||||
return [
|
||||
{'type': 'length', 'text': '至少8个字符'},
|
||||
{'type': 'letter', 'text': '包含字母'},
|
||||
{'type': 'number', 'text': '包含数字'},
|
||||
{'type': 'special', 'text': '包含特殊字符(推荐)'},
|
||||
];
|
||||
}
|
||||
|
||||
/// 检查密码要求
|
||||
bool _checkPasswordRequirement(String password, String type) {
|
||||
switch (type) {
|
||||
case 'length':
|
||||
return password.length >= 8;
|
||||
case 'letter':
|
||||
return RegExp(r'[a-zA-Z]').hasMatch(password);
|
||||
case 'number':
|
||||
return RegExp(r'\d').hasMatch(password);
|
||||
case 'special':
|
||||
return RegExp(r'[!@#$%^&*(),.?":{}|<>]').hasMatch(password);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 修改密码
|
||||
Future<void> _changePassword() async {
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final authProvider = Provider.of<AuthNotifier>(context, listen: false);
|
||||
|
||||
await authProvider.changePassword(
|
||||
currentPassword: _currentPasswordController.text,
|
||||
newPassword: _newPasswordController.text,
|
||||
);
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('密码修改成功'),
|
||||
backgroundColor: AppColors.success,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Navigator.pop(context);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('密码修改失败: $e'),
|
||||
backgroundColor: AppColors.error,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
708
client/lib/features/profile/screens/help_feedback_screen.dart
Normal file
708
client/lib/features/profile/screens/help_feedback_screen.dart
Normal file
@@ -0,0 +1,708 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../shared/widgets/custom_app_bar.dart';
|
||||
|
||||
/// 帮助与反馈页面
|
||||
class HelpFeedbackScreen extends StatefulWidget {
|
||||
const HelpFeedbackScreen({super.key});
|
||||
|
||||
@override
|
||||
State<HelpFeedbackScreen> createState() => _HelpFeedbackScreenState();
|
||||
}
|
||||
|
||||
class _HelpFeedbackScreenState extends State<HelpFeedbackScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
final TextEditingController _feedbackController = TextEditingController();
|
||||
String _selectedFeedbackType = '功能建议';
|
||||
String _contactEmail = '';
|
||||
bool _isSubmitting = false;
|
||||
|
||||
final List<String> _feedbackTypes = [
|
||||
'功能建议',
|
||||
'问题反馈',
|
||||
'内容错误',
|
||||
'性能问题',
|
||||
'其他'
|
||||
];
|
||||
|
||||
final List<Map<String, dynamic>> _faqList = [
|
||||
{
|
||||
'question': '如何开始学习?',
|
||||
'answer': '点击首页的"开始学习"按钮,选择适合您的学习模式。我们提供单词学习、语法练习、听力训练等多种学习方式。',
|
||||
'category': '学习指导'
|
||||
},
|
||||
{
|
||||
'question': '如何设置学习目标?',
|
||||
'answer': '进入个人中心 > 设置 > 学习设置,您可以设置每日单词目标和学习时长目标。系统会根据您的目标提供个性化的学习计划。',
|
||||
'category': '学习指导'
|
||||
},
|
||||
{
|
||||
'question': '如何查看学习进度?',
|
||||
'answer': '在个人中心可以查看详细的学习统计,包括学习天数、掌握单词数、学习时长等数据。',
|
||||
'category': '学习指导'
|
||||
},
|
||||
{
|
||||
'question': '忘记密码怎么办?',
|
||||
'answer': '在登录页面点击"忘记密码",输入您的邮箱地址,我们会发送重置密码的链接到您的邮箱。',
|
||||
'category': '账户问题'
|
||||
},
|
||||
{
|
||||
'question': '如何修改个人信息?',
|
||||
'answer': '进入个人中心 > 个人信息,您可以修改头像、用户名、邮箱等个人信息。',
|
||||
'category': '账户问题'
|
||||
},
|
||||
{
|
||||
'question': '如何开启/关闭通知?',
|
||||
'answer': '进入个人中心 > 设置 > 通知设置,您可以自定义各种通知的开启状态和提醒时间。',
|
||||
'category': '设置问题'
|
||||
},
|
||||
{
|
||||
'question': '音频播放不了怎么办?',
|
||||
'answer': '请检查网络连接和设备音量设置。如果问题持续存在,可以尝试重启应用或清除缓存。',
|
||||
'category': '技术问题'
|
||||
},
|
||||
{
|
||||
'question': '应用运行缓慢怎么办?',
|
||||
'answer': '建议清除应用缓存,关闭其他后台应用,确保设备有足够的存储空间。如果问题持续,请联系客服。',
|
||||
'category': '技术问题'
|
||||
},
|
||||
{
|
||||
'question': '学习数据会丢失吗?',
|
||||
'answer': '您的学习数据会自动同步到云端,即使更换设备也不会丢失。建议保持网络连接以确保数据及时同步。',
|
||||
'category': '数据安全'
|
||||
},
|
||||
{
|
||||
'question': '如何导出学习记录?',
|
||||
'answer': '目前暂不支持导出功能,但您可以在学习统计页面查看详细的学习数据和进度图表。',
|
||||
'category': '数据安全'
|
||||
},
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 2, vsync: this);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
_feedbackController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surface,
|
||||
appBar: CustomAppBar(
|
||||
title: '帮助与反馈',
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: AppColors.primary,
|
||||
unselectedLabelColor: AppColors.onSurfaceVariant,
|
||||
indicatorColor: AppColors.primary,
|
||||
tabs: const [
|
||||
Tab(text: '常见问题'),
|
||||
Tab(text: '意见反馈'),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildFAQTab(),
|
||||
_buildFeedbackTab(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建常见问题标签页
|
||||
Widget _buildFAQTab() {
|
||||
final categories = _faqList.map((faq) => faq['category'] as String).toSet().toList();
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
// 搜索框
|
||||
Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TextField(
|
||||
decoration: InputDecoration(
|
||||
hintText: '搜索问题...',
|
||||
prefixIcon: Icon(Icons.search, color: AppColors.onSurfaceVariant),
|
||||
border: InputBorder.none,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
onChanged: (value) {
|
||||
// TODO: 实现搜索功能
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// 快速入口
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'快速入口',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildQuickActionCard(
|
||||
icon: Icons.school,
|
||||
title: '学习指南',
|
||||
subtitle: '新手入门教程',
|
||||
onTap: () => _showLearningGuide(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _buildQuickActionCard(
|
||||
icon: Icons.contact_support,
|
||||
title: '在线客服',
|
||||
subtitle: '实时帮助支持',
|
||||
onTap: () => _contactCustomerService(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 分类问题列表
|
||||
...categories.map((category) => _buildFAQCategory(category)),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建意见反馈标签页
|
||||
Widget _buildFeedbackTab() {
|
||||
return SingleChildScrollView(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 反馈类型选择
|
||||
Text(
|
||||
'反馈类型',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: DropdownButtonFormField<String>(
|
||||
value: _selectedFeedbackType,
|
||||
decoration: const InputDecoration(
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
items: _feedbackTypes.map((type) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: type,
|
||||
child: Text(type),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedFeedbackType = value!;
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 反馈内容
|
||||
Text(
|
||||
'反馈内容',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TextField(
|
||||
controller: _feedbackController,
|
||||
maxLines: 6,
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请详细描述您遇到的问题或建议...',
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.all(16),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 联系邮箱
|
||||
Text(
|
||||
'联系邮箱(可选)',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TextField(
|
||||
onChanged: (value) {
|
||||
_contactEmail = value;
|
||||
},
|
||||
decoration: const InputDecoration(
|
||||
hintText: '请输入您的邮箱地址',
|
||||
border: InputBorder.none,
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 提交按钮
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: _isSubmitting ? null : _submitFeedback,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: _isSubmitting
|
||||
? const SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'提交反馈',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 提示信息
|
||||
Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
color: AppColors.primary,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'我们会认真对待每一条反馈,并在24小时内回复您的问题。',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建快速操作卡片
|
||||
Widget _buildQuickActionCard({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: AppColors.primary,
|
||||
size: 32,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
subtitle,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建FAQ分类
|
||||
Widget _buildFAQCategory(String category) {
|
||||
final categoryFAQs = _faqList.where((faq) => faq['category'] == category).toList();
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 10,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Text(
|
||||
category,
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
...categoryFAQs.map((faq) => _buildFAQItem(faq)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建FAQ项目
|
||||
Widget _buildFAQItem(Map<String, dynamic> faq) {
|
||||
return ExpansionTile(
|
||||
title: Text(
|
||||
faq['question'],
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
child: Text(
|
||||
faq['answer'],
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示学习指南
|
||||
void _showLearningGuide() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('学习指南'),
|
||||
content: const SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'1. 注册并完善个人信息',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text('创建账户后,请完善您的英语水平、学习目标等信息,以便为您提供个性化的学习内容。'),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'2. 设置学习目标',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text('在设置中制定每日学习目标,包括单词数量和学习时长,系统会帮助您跟踪进度。'),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'3. 选择学习模式',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text('根据您的需求选择单词学习、语法练习、听力训练等不同的学习模式。'),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'4. 坚持每日学习',
|
||||
style: TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text('保持每日学习习惯,利用碎片时间进行学习,积少成多提升英语水平。'),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('知道了'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 联系客服
|
||||
void _contactCustomerService() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return AlertDialog(
|
||||
title: const Text('联系客服'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('您可以通过以下方式联系我们:'),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.email, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
const Text('邮箱:'),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Clipboard.setData(const ClipboardData(text: 'support@aienglish.com'));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('邮箱地址已复制')),
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
'support@aienglish.com',
|
||||
style: TextStyle(
|
||||
color: AppColors.primary,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.phone, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
const Text('电话:'),
|
||||
GestureDetector(
|
||||
onTap: () {
|
||||
Clipboard.setData(const ClipboardData(text: '400-123-4567'));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('电话号码已复制')),
|
||||
);
|
||||
},
|
||||
child: Text(
|
||||
'400-123-4567',
|
||||
style: TextStyle(
|
||||
color: AppColors.primary,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Row(
|
||||
children: [
|
||||
Icon(Icons.access_time, size: 20),
|
||||
SizedBox(width: 8),
|
||||
Text('服务时间:9:00-18:00(工作日)'),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 提交反馈
|
||||
Future<void> _submitFeedback() async {
|
||||
if (_feedbackController.text.trim().isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('请输入反馈内容'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
try {
|
||||
// TODO: 实现提交反馈的API调用
|
||||
await Future.delayed(const Duration(seconds: 2)); // 模拟网络请求
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('反馈提交成功,感谢您的建议!'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
|
||||
// 清空表单
|
||||
_feedbackController.clear();
|
||||
_contactEmail = '';
|
||||
setState(() {
|
||||
_selectedFeedbackType = '功能建议';
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('提交失败:$e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
811
client/lib/features/profile/screens/profile_detail_screen.dart
Normal file
811
client/lib/features/profile/screens/profile_detail_screen.dart
Normal file
@@ -0,0 +1,811 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'dart:io';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_text_styles.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
import '../../../core/widgets/custom_button.dart';
|
||||
import '../../../core/widgets/custom_text_field.dart';
|
||||
import '../../../core/models/user_model.dart';
|
||||
import '../../auth/providers/auth_provider.dart';
|
||||
import '../widgets/profile_avatar.dart';
|
||||
import '../widgets/profile_info_card.dart';
|
||||
import '../widgets/learning_preferences_card.dart';
|
||||
|
||||
/// 个人资料详情屏幕
|
||||
class ProfileDetailScreen extends StatefulWidget {
|
||||
const ProfileDetailScreen({super.key});
|
||||
|
||||
@override
|
||||
State<ProfileDetailScreen> createState() => _ProfileDetailScreenState();
|
||||
}
|
||||
|
||||
class _ProfileDetailScreenState extends State<ProfileDetailScreen>
|
||||
with TickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _usernameController = TextEditingController();
|
||||
final _emailController = TextEditingController();
|
||||
final _phoneController = TextEditingController();
|
||||
final _bioController = TextEditingController();
|
||||
|
||||
bool _isEditing = false;
|
||||
bool _isLoading = false;
|
||||
File? _selectedImage;
|
||||
|
||||
// 学习偏好设置
|
||||
int _dailyWordGoal = 20;
|
||||
int _dailyStudyMinutes = 30;
|
||||
EnglishLevel _englishLevel = EnglishLevel.intermediate;
|
||||
bool _notificationsEnabled = true;
|
||||
bool _soundEnabled = true;
|
||||
bool _vibrationEnabled = true;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 3, vsync: this);
|
||||
_loadUserData();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
_usernameController.dispose();
|
||||
_emailController.dispose();
|
||||
_phoneController.dispose();
|
||||
_bioController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// 加载用户数据
|
||||
void _loadUserData() {
|
||||
final authProvider = Provider.of<AuthNotifier>(context, listen: false);
|
||||
final user = authProvider.state.user;
|
||||
|
||||
if (user != null) {
|
||||
_usernameController.text = user.username;
|
||||
_emailController.text = user.email;
|
||||
_phoneController.text = user.profile?.phone ?? '';
|
||||
_bioController.text = user.profile?.bio ?? '';
|
||||
|
||||
if (user.profile?.settings != null) {
|
||||
_dailyWordGoal = user.profile!.settings!.dailyWordGoal;
|
||||
_dailyStudyMinutes = user.profile!.settings!.dailyStudyMinutes;
|
||||
_notificationsEnabled = user.profile!.settings!.notificationsEnabled;
|
||||
_soundEnabled = user.profile!.settings!.soundEnabled;
|
||||
_vibrationEnabled = user.profile!.settings!.vibrationEnabled;
|
||||
}
|
||||
|
||||
if (user.profile?.englishLevel != null) {
|
||||
_englishLevel = user.profile!.englishLevel!;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: _buildAppBar(),
|
||||
body: Column(
|
||||
children: [
|
||||
// Tab栏
|
||||
Container(
|
||||
color: AppColors.surface,
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: AppColors.primary,
|
||||
unselectedLabelColor: AppColors.onSurfaceVariant,
|
||||
indicatorColor: AppColors.primary,
|
||||
indicatorWeight: 3,
|
||||
labelStyle: AppTextStyles.titleSmall.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
unselectedLabelStyle: AppTextStyles.titleSmall,
|
||||
tabs: const [
|
||||
Tab(text: '基本信息'),
|
||||
Tab(text: '学习偏好'),
|
||||
Tab(text: '账户设置'),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Tab内容
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildBasicInfoTab(),
|
||||
_buildLearningPreferencesTab(),
|
||||
_buildAccountSettingsTab(),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建应用栏
|
||||
PreferredSizeWidget _buildAppBar() {
|
||||
return AppBar(
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: AppColors.onPrimary,
|
||||
title: Text(
|
||||
'个人资料',
|
||||
style: AppTextStyles.titleLarge.copyWith(
|
||||
color: AppColors.onPrimary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
if (_isEditing)
|
||||
TextButton(
|
||||
onPressed: _isLoading ? null : _saveProfile,
|
||||
child: _isLoading
|
||||
? SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(AppColors.onPrimary),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
'保存',
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.onPrimary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
IconButton(
|
||||
onPressed: () => setState(() => _isEditing = true),
|
||||
icon: Icon(
|
||||
Icons.edit,
|
||||
color: AppColors.onPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建基本信息标签页
|
||||
Widget _buildBasicInfoTab() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 头像部分
|
||||
_buildAvatarSection(),
|
||||
const SizedBox(height: AppDimensions.spacingLg),
|
||||
|
||||
// 基本信息表单
|
||||
ProfileInfoCard(
|
||||
title: '基本信息',
|
||||
child: Column(
|
||||
children: [
|
||||
CustomTextField(
|
||||
controller: _usernameController,
|
||||
labelText: '用户名',
|
||||
enabled: _isEditing,
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return '请输入用户名';
|
||||
}
|
||||
if (value.length < 2) {
|
||||
return '用户名至少2个字符';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
CustomTextField(
|
||||
controller: _emailController,
|
||||
labelText: '邮箱',
|
||||
enabled: false, // 邮箱不允许修改
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
CustomTextField(
|
||||
controller: _phoneController,
|
||||
labelText: '手机号',
|
||||
enabled: _isEditing,
|
||||
keyboardType: TextInputType.phone,
|
||||
validator: (value) {
|
||||
if (value != null && value.isNotEmpty) {
|
||||
if (!RegExp(r'^1[3-9]\d{9}$').hasMatch(value)) {
|
||||
return '请输入正确的手机号';
|
||||
}
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
CustomTextField(
|
||||
controller: _bioController,
|
||||
labelText: '个人简介',
|
||||
enabled: _isEditing,
|
||||
maxLines: 3,
|
||||
maxLength: 200,
|
||||
validator: (value) {
|
||||
if (value != null && value.length > 200) {
|
||||
return '个人简介不能超过200个字符';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建学习偏好标签页
|
||||
Widget _buildLearningPreferencesTab() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
child: Column(
|
||||
children: [
|
||||
LearningPreferencesCard(
|
||||
title: '学习目标',
|
||||
child: Column(
|
||||
children: [
|
||||
_buildSliderSetting(
|
||||
title: '每日单词目标',
|
||||
value: _dailyWordGoal.toDouble(),
|
||||
min: 5,
|
||||
max: 100,
|
||||
divisions: 19,
|
||||
unit: '个',
|
||||
onChanged: _isEditing
|
||||
? (value) => setState(() => _dailyWordGoal = value.round())
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
_buildSliderSetting(
|
||||
title: '每日学习时长',
|
||||
value: _dailyStudyMinutes.toDouble(),
|
||||
min: 10,
|
||||
max: 120,
|
||||
divisions: 22,
|
||||
unit: '分钟',
|
||||
onChanged: _isEditing
|
||||
? (value) => setState(() => _dailyStudyMinutes = value.round())
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
LearningPreferencesCard(
|
||||
title: '英语水平',
|
||||
child: _buildEnglishLevelSelector(),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
LearningPreferencesCard(
|
||||
title: '通知设置',
|
||||
child: Column(
|
||||
children: [
|
||||
_buildSwitchSetting(
|
||||
title: '学习提醒',
|
||||
subtitle: '每日学习时间提醒',
|
||||
value: _notificationsEnabled,
|
||||
onChanged: _isEditing
|
||||
? (value) => setState(() => _notificationsEnabled = value)
|
||||
: null,
|
||||
),
|
||||
_buildSwitchSetting(
|
||||
title: '音效',
|
||||
subtitle: '操作反馈音效',
|
||||
value: _soundEnabled,
|
||||
onChanged: _isEditing
|
||||
? (value) => setState(() => _soundEnabled = value)
|
||||
: null,
|
||||
),
|
||||
_buildSwitchSetting(
|
||||
title: '震动反馈',
|
||||
subtitle: '操作震动反馈',
|
||||
value: _vibrationEnabled,
|
||||
onChanged: _isEditing
|
||||
? (value) => setState(() => _vibrationEnabled = value)
|
||||
: null,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建账户设置标签页
|
||||
Widget _buildAccountSettingsTab() {
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
child: Column(
|
||||
children: [
|
||||
ProfileInfoCard(
|
||||
title: '安全设置',
|
||||
child: Column(
|
||||
children: [
|
||||
_buildSettingItem(
|
||||
icon: Icons.lock_outline,
|
||||
title: '修改密码',
|
||||
subtitle: '定期修改密码保护账户安全',
|
||||
onTap: () => Navigator.pushNamed(context, '/change-password'),
|
||||
),
|
||||
const Divider(),
|
||||
_buildSettingItem(
|
||||
icon: Icons.security,
|
||||
title: '两步验证',
|
||||
subtitle: '增强账户安全性',
|
||||
onTap: () => _showComingSoon('两步验证'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
ProfileInfoCard(
|
||||
title: '数据管理',
|
||||
child: Column(
|
||||
children: [
|
||||
_buildSettingItem(
|
||||
icon: Icons.download,
|
||||
title: '导出数据',
|
||||
subtitle: '导出学习记录和个人数据',
|
||||
onTap: () => _showComingSoon('数据导出'),
|
||||
),
|
||||
const Divider(),
|
||||
_buildSettingItem(
|
||||
icon: Icons.delete_outline,
|
||||
title: '清除缓存',
|
||||
subtitle: '清除应用缓存数据',
|
||||
onTap: _clearCache,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
ProfileInfoCard(
|
||||
title: '账户操作',
|
||||
child: Column(
|
||||
children: [
|
||||
_buildSettingItem(
|
||||
icon: Icons.logout,
|
||||
title: '退出登录',
|
||||
subtitle: '退出当前账户',
|
||||
onTap: _logout,
|
||||
textColor: AppColors.warning,
|
||||
),
|
||||
const Divider(),
|
||||
_buildSettingItem(
|
||||
icon: Icons.delete_forever,
|
||||
title: '注销账户',
|
||||
subtitle: '永久删除账户和所有数据',
|
||||
onTap: () => _showDeleteAccountDialog(),
|
||||
textColor: AppColors.error,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建头像部分
|
||||
Widget _buildAvatarSection() {
|
||||
return Consumer<AuthNotifier>(builder: (context, authProvider, child) {
|
||||
final user = authProvider.state.user;
|
||||
|
||||
return Center(
|
||||
child: Column(
|
||||
children: [
|
||||
ProfileAvatar(
|
||||
imageUrl: user?.profile?.avatar,
|
||||
selectedImage: _selectedImage,
|
||||
size: 100,
|
||||
isEditing: _isEditing,
|
||||
onImageSelected: _selectImage,
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
Text(
|
||||
user?.username ?? '用户',
|
||||
style: AppTextStyles.headlineSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingXs),
|
||||
|
||||
Text(
|
||||
user?.email ?? '',
|
||||
style: AppTextStyles.bodyMedium.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// 构建滑块设置
|
||||
Widget _buildSliderSetting({
|
||||
required String title,
|
||||
required double value,
|
||||
required double min,
|
||||
required double max,
|
||||
required int divisions,
|
||||
required String unit,
|
||||
ValueChanged<double>? onChanged,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${value.round()} $unit',
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingSm),
|
||||
|
||||
Slider(
|
||||
value: value,
|
||||
min: min,
|
||||
max: max,
|
||||
divisions: divisions,
|
||||
activeColor: AppColors.primary,
|
||||
inactiveColor: AppColors.primary.withOpacity(0.3),
|
||||
onChanged: onChanged,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建开关设置
|
||||
Widget _buildSwitchSetting({
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required bool value,
|
||||
ValueChanged<bool>? onChanged,
|
||||
}) {
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
title,
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
subtitle,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
trailing: Switch(
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
activeColor: AppColors.primary,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建英语水平选择器
|
||||
Widget _buildEnglishLevelSelector() {
|
||||
return Column(
|
||||
children: EnglishLevel.values.map((level) {
|
||||
return RadioListTile<EnglishLevel>(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text(
|
||||
_getEnglishLevelText(level),
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
_getEnglishLevelDescription(level),
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
value: level,
|
||||
groupValue: _englishLevel,
|
||||
onChanged: _isEditing
|
||||
? (value) => setState(() => _englishLevel = value!)
|
||||
: null,
|
||||
activeColor: AppColors.primary,
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建设置项
|
||||
Widget _buildSettingItem({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required VoidCallback onTap,
|
||||
Color? textColor,
|
||||
}) {
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(
|
||||
icon,
|
||||
color: textColor ?? AppColors.onSurface,
|
||||
),
|
||||
title: Text(
|
||||
title,
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: textColor ?? AppColors.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
subtitle,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
trailing: Icon(
|
||||
Icons.chevron_right,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
onTap: onTap,
|
||||
);
|
||||
}
|
||||
|
||||
/// 选择图片
|
||||
Future<void> _selectImage() async {
|
||||
final picker = ImagePicker();
|
||||
final pickedFile = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
maxWidth: 512,
|
||||
maxHeight: 512,
|
||||
imageQuality: 80,
|
||||
);
|
||||
|
||||
if (pickedFile != null) {
|
||||
setState(() {
|
||||
_selectedImage = File(pickedFile.path);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// 保存个人资料
|
||||
Future<void> _saveProfile() async {
|
||||
if (!_formKey.currentState!.validate()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() => _isLoading = true);
|
||||
|
||||
try {
|
||||
final authProvider = Provider.of<AuthNotifier>(context, listen: false);
|
||||
|
||||
// TODO: 如果有选择新头像,先上传头像
|
||||
String? avatarUrl;
|
||||
if (_selectedImage != null) {
|
||||
// avatarUrl = await _uploadAvatar(_selectedImage!);
|
||||
}
|
||||
|
||||
await authProvider.updateProfile(
|
||||
username: _usernameController.text,
|
||||
phone: _phoneController.text,
|
||||
avatar: avatarUrl,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
_isEditing = false;
|
||||
_selectedImage = null;
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('个人资料更新成功'),
|
||||
backgroundColor: AppColors.success,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('更新失败: $e'),
|
||||
backgroundColor: AppColors.error,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() => _isLoading = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 清除缓存
|
||||
Future<void> _clearCache() async {
|
||||
// TODO: 实现清除缓存功能
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('缓存已清除'),
|
||||
backgroundColor: AppColors.success,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 退出登录
|
||||
Future<void> _logout() async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('确认退出'),
|
||||
content: const Text('确定要退出登录吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text(
|
||||
'退出',
|
||||
style: TextStyle(color: AppColors.warning),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true) {
|
||||
final authProvider = Provider.of<AuthNotifier>(context, listen: false);
|
||||
await authProvider.logout();
|
||||
|
||||
if (mounted) {
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/login',
|
||||
(route) => false,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 显示注销账户对话框
|
||||
Future<void> _showDeleteAccountDialog() async {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(
|
||||
'注销账户',
|
||||
style: TextStyle(color: AppColors.error),
|
||||
),
|
||||
content: const Text(
|
||||
'注销账户将永久删除您的所有数据,包括学习记录、个人信息等。此操作不可恢复,请谨慎操作。',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
child: Text(
|
||||
'确认注销',
|
||||
style: TextStyle(color: AppColors.error),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true) {
|
||||
// TODO: 实现注销账户功能
|
||||
_showComingSoon('账户注销');
|
||||
}
|
||||
}
|
||||
|
||||
/// 显示即将上线提示
|
||||
void _showComingSoon(String feature) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('$feature功能即将上线'),
|
||||
backgroundColor: AppColors.info,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 获取英语水平文本
|
||||
String _getEnglishLevelText(EnglishLevel level) {
|
||||
switch (level) {
|
||||
case EnglishLevel.beginner:
|
||||
return '初级 (Beginner)';
|
||||
case EnglishLevel.elementary:
|
||||
return '基础 (Elementary)';
|
||||
case EnglishLevel.intermediate:
|
||||
return '中级 (Intermediate)';
|
||||
case EnglishLevel.upperIntermediate:
|
||||
return '中高级 (Upper Intermediate)';
|
||||
case EnglishLevel.advanced:
|
||||
return '高级 (Advanced)';
|
||||
case EnglishLevel.proficient:
|
||||
return '精通 (Proficient)';
|
||||
case EnglishLevel.expert:
|
||||
return '专家 (Expert)';
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取英语水平描述
|
||||
String _getEnglishLevelDescription(EnglishLevel level) {
|
||||
switch (level) {
|
||||
case EnglishLevel.beginner:
|
||||
return '基础词汇和语法,适合英语入门学习者';
|
||||
case EnglishLevel.elementary:
|
||||
return '掌握基本词汇,能进行简单交流';
|
||||
case EnglishLevel.intermediate:
|
||||
return '中等词汇量,能进行日常对话和阅读';
|
||||
case EnglishLevel.upperIntermediate:
|
||||
return '较好的词汇量,能处理复杂话题';
|
||||
case EnglishLevel.advanced:
|
||||
return '丰富词汇量,能流利交流和理解复杂内容';
|
||||
case EnglishLevel.proficient:
|
||||
return '熟练掌握英语,能应对各种语言场景';
|
||||
case EnglishLevel.expert:
|
||||
return '接近母语水平,能处理专业和学术内容';
|
||||
}
|
||||
}
|
||||
}
|
||||
708
client/lib/features/profile/screens/profile_edit_screen.dart
Normal file
708
client/lib/features/profile/screens/profile_edit_screen.dart
Normal file
@@ -0,0 +1,708 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../shared/widgets/custom_app_bar.dart';
|
||||
import '../../../core/widgets/custom_text_field.dart';
|
||||
import '../../../core/widgets/custom_button.dart';
|
||||
import '../../../core/providers/app_state_provider.dart';
|
||||
import '../../../shared/models/user_model.dart';
|
||||
|
||||
/// 个人信息编辑页面
|
||||
class ProfileEditScreen extends ConsumerStatefulWidget {
|
||||
const ProfileEditScreen({super.key});
|
||||
|
||||
@override
|
||||
ConsumerState<ProfileEditScreen> createState() => _ProfileEditScreenState();
|
||||
}
|
||||
|
||||
class _ProfileEditScreenState extends ConsumerState<ProfileEditScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _usernameController = TextEditingController();
|
||||
final _emailController = TextEditingController();
|
||||
final _phoneController = TextEditingController();
|
||||
final _bioController = TextEditingController();
|
||||
final _realNameController = TextEditingController();
|
||||
final _locationController = TextEditingController();
|
||||
final _occupationController = TextEditingController();
|
||||
|
||||
String? _selectedGender;
|
||||
DateTime? _selectedBirthday;
|
||||
String? _selectedEducation;
|
||||
String? _selectedEnglishLevel;
|
||||
String? _selectedTargetLevel;
|
||||
String? _selectedLearningGoal;
|
||||
List<String> _interests = [];
|
||||
String? _avatarPath;
|
||||
bool _isLoading = false;
|
||||
|
||||
final List<String> _genderOptions = ['male', 'female', 'other'];
|
||||
final List<String> _educationOptions = ['高中', '专科', '本科', '硕士', '博士'];
|
||||
final List<String> _englishLevelOptions = ['beginner', 'elementary', 'intermediate', 'upperIntermediate', 'advanced'];
|
||||
final List<String> _learningGoalOptions = ['dailyCommunication', 'businessEnglish', 'academicEnglish', 'examPreparation', 'travelEnglish'];
|
||||
final List<String> _interestOptions = ['编程', '英语学习', '阅读', '音乐', '电影', '旅行', '运动', '摄影', '绘画', '游戏'];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadUserData();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_usernameController.dispose();
|
||||
_emailController.dispose();
|
||||
_phoneController.dispose();
|
||||
_bioController.dispose();
|
||||
_realNameController.dispose();
|
||||
_locationController.dispose();
|
||||
_occupationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _loadUserData() {
|
||||
final authProviderNotifier = ref.read(authProvider);
|
||||
final user = authProviderNotifier.user;
|
||||
if (user != null) {
|
||||
_usernameController.text = user.username ?? '';
|
||||
_emailController.text = user.email ?? '';
|
||||
_phoneController.text = user.phone ?? '';
|
||||
_bioController.text = user.bio ?? '';
|
||||
_selectedGender = user.gender;
|
||||
_selectedBirthday = user.birthday;
|
||||
_selectedEnglishLevel = user.learningLevel;
|
||||
_avatarPath = user.avatar;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _pickImage() async {
|
||||
final ImagePicker picker = ImagePicker();
|
||||
final XFile? image = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
maxWidth: 512,
|
||||
maxHeight: 512,
|
||||
imageQuality: 80,
|
||||
);
|
||||
|
||||
if (image != null) {
|
||||
setState(() {
|
||||
_avatarPath = image.path;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _selectBirthday() async {
|
||||
final DateTime? picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _selectedBirthday ?? DateTime(1990),
|
||||
firstDate: DateTime(1900),
|
||||
lastDate: DateTime.now(),
|
||||
builder: (context, child) {
|
||||
return Theme(
|
||||
data: Theme.of(context).copyWith(
|
||||
colorScheme: ColorScheme.light(
|
||||
primary: AppColors.primary,
|
||||
onPrimary: AppColors.onPrimary,
|
||||
surface: AppColors.surface,
|
||||
onSurface: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
child: child!,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (picked != null) {
|
||||
setState(() {
|
||||
_selectedBirthday = picked;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _showInterestsDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) {
|
||||
List<String> tempInterests = List.from(_interests);
|
||||
return StatefulBuilder(
|
||||
builder: (context, setDialogState) {
|
||||
return AlertDialog(
|
||||
title: const Text('选择兴趣爱好'),
|
||||
content: SizedBox(
|
||||
width: double.maxFinite,
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: _interestOptions.length,
|
||||
itemBuilder: (context, index) {
|
||||
final interest = _interestOptions[index];
|
||||
final isSelected = tempInterests.contains(interest);
|
||||
return CheckboxListTile(
|
||||
title: Text(interest),
|
||||
value: isSelected,
|
||||
onChanged: (bool? value) {
|
||||
setDialogState(() {
|
||||
if (value == true) {
|
||||
tempInterests.add(interest);
|
||||
} else {
|
||||
tempInterests.remove(interest);
|
||||
}
|
||||
});
|
||||
},
|
||||
activeColor: AppColors.primary,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_interests = tempInterests;
|
||||
});
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _saveProfile() async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
final authProviderNotifier = ref.read(authProvider);
|
||||
final success = await authProviderNotifier.updateProfile(
|
||||
nickname: _usernameController.text.trim(),
|
||||
avatar: _avatarPath,
|
||||
phone: _phoneController.text.trim(),
|
||||
birthday: _selectedBirthday,
|
||||
gender: _selectedGender,
|
||||
bio: _bioController.text.trim(),
|
||||
learningLevel: _selectedEnglishLevel,
|
||||
targetLanguage: 'english',
|
||||
nativeLanguage: 'chinese',
|
||||
dailyGoal: 30,
|
||||
);
|
||||
|
||||
if (success) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('个人信息更新成功'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
} else {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('更新失败,请重试'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('更新失败: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String _getGenderDisplayName(String gender) {
|
||||
switch (gender) {
|
||||
case 'male':
|
||||
return '男';
|
||||
case 'female':
|
||||
return '女';
|
||||
case 'other':
|
||||
return '其他';
|
||||
default:
|
||||
return gender;
|
||||
}
|
||||
}
|
||||
|
||||
String _getEnglishLevelDisplayName(String level) {
|
||||
switch (level) {
|
||||
case 'beginner':
|
||||
return '初学者';
|
||||
case 'elementary':
|
||||
return '基础';
|
||||
case 'intermediate':
|
||||
return '中级';
|
||||
case 'upperIntermediate':
|
||||
return '中高级';
|
||||
case 'advanced':
|
||||
return '高级';
|
||||
default:
|
||||
return level;
|
||||
}
|
||||
}
|
||||
|
||||
String _getLearningGoalDisplayName(String goal) {
|
||||
switch (goal) {
|
||||
case 'dailyCommunication':
|
||||
return '日常交流';
|
||||
case 'businessEnglish':
|
||||
return '商务英语';
|
||||
case 'academicEnglish':
|
||||
return '学术英语';
|
||||
case 'examPreparation':
|
||||
return '考试准备';
|
||||
case 'travelEnglish':
|
||||
return '旅游英语';
|
||||
default:
|
||||
return goal;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surface,
|
||||
appBar: CustomAppBar(
|
||||
title: '编辑个人信息',
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: _isLoading ? null : _saveProfile,
|
||||
child: Text(
|
||||
'保存',
|
||||
style: TextStyle(
|
||||
color: _isLoading ? AppColors.onSurfaceVariant : AppColors.primary,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
Form(
|
||||
key: _formKey,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 头像部分
|
||||
Center(
|
||||
child: GestureDetector(
|
||||
onTap: _pickImage,
|
||||
child: Container(
|
||||
width: 100,
|
||||
height: 100,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: AppColors.primary,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: CircleAvatar(
|
||||
radius: 48,
|
||||
backgroundColor: AppColors.surface,
|
||||
backgroundImage: _avatarPath != null
|
||||
? (_avatarPath!.startsWith('http')
|
||||
? NetworkImage(_avatarPath!)
|
||||
: FileImage(XFile(_avatarPath!).path as dynamic))
|
||||
: null,
|
||||
child: _avatarPath == null
|
||||
? Icon(
|
||||
Icons.camera_alt,
|
||||
size: 30,
|
||||
color: AppColors.primary,
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Center(
|
||||
child: Text(
|
||||
'点击更换头像',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 基本信息
|
||||
_buildSectionTitle('基本信息'),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
CustomTextField(
|
||||
controller: _usernameController,
|
||||
labelText: '用户名',
|
||||
hintText: '请输入用户名',
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return '请输入用户名';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
CustomTextField(
|
||||
controller: _realNameController,
|
||||
labelText: '真实姓名',
|
||||
hintText: '请输入真实姓名',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
CustomTextField(
|
||||
controller: _emailController,
|
||||
labelText: '邮箱',
|
||||
hintText: '请输入邮箱地址',
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
enabled: false, // 邮箱通常不允许修改
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
CustomTextField(
|
||||
controller: _phoneController,
|
||||
labelText: '手机号',
|
||||
hintText: '请输入手机号',
|
||||
keyboardType: TextInputType.phone,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 性别选择
|
||||
_buildDropdownField(
|
||||
label: '性别',
|
||||
value: _selectedGender,
|
||||
items: _genderOptions,
|
||||
displayNameBuilder: _getGenderDisplayName,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedGender = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 生日选择
|
||||
_buildDateField(
|
||||
label: '生日',
|
||||
value: _selectedBirthday,
|
||||
onTap: _selectBirthday,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
CustomTextField(
|
||||
controller: _locationController,
|
||||
labelText: '所在地',
|
||||
hintText: '请输入所在地',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
CustomTextField(
|
||||
controller: _occupationController,
|
||||
labelText: '职业',
|
||||
hintText: '请输入职业',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 教育背景
|
||||
_buildDropdownField(
|
||||
label: '教育背景',
|
||||
value: _selectedEducation,
|
||||
items: _educationOptions,
|
||||
displayNameBuilder: (value) => value,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedEducation = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 学习信息
|
||||
_buildSectionTitle('学习信息'),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 当前英语水平
|
||||
_buildDropdownField(
|
||||
label: '当前英语水平',
|
||||
value: _selectedEnglishLevel,
|
||||
items: _englishLevelOptions,
|
||||
displayNameBuilder: _getEnglishLevelDisplayName,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedEnglishLevel = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 目标英语水平
|
||||
_buildDropdownField(
|
||||
label: '目标英语水平',
|
||||
value: _selectedTargetLevel,
|
||||
items: _englishLevelOptions,
|
||||
displayNameBuilder: _getEnglishLevelDisplayName,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedTargetLevel = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 学习目标
|
||||
_buildDropdownField(
|
||||
label: '学习目标',
|
||||
value: _selectedLearningGoal,
|
||||
items: _learningGoalOptions,
|
||||
displayNameBuilder: _getLearningGoalDisplayName,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedLearningGoal = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 兴趣爱好
|
||||
_buildInterestsField(),
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 个人简介
|
||||
_buildSectionTitle('个人简介'),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
CustomTextField(
|
||||
controller: _bioController,
|
||||
labelText: '个人简介',
|
||||
hintText: '介绍一下自己吧...',
|
||||
maxLines: 4,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
|
||||
// 保存按钮
|
||||
CustomButton(
|
||||
text: '保存修改',
|
||||
onPressed: _saveProfile,
|
||||
isLoading: _isLoading,
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_isLoading)
|
||||
Container(
|
||||
color: Colors.black.withOpacity(0.3),
|
||||
child: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionTitle(String title) {
|
||||
return Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDropdownField({
|
||||
required String label,
|
||||
required String? value,
|
||||
required List<String> items,
|
||||
required String Function(String) displayNameBuilder,
|
||||
required void Function(String?) onChanged,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColors.outline),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: value,
|
||||
hint: Text('请选择$label'),
|
||||
isExpanded: true,
|
||||
items: items.map((item) {
|
||||
return DropdownMenuItem<String>(
|
||||
value: item,
|
||||
child: Text(displayNameBuilder(item)),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: onChanged,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDateField({
|
||||
required String label,
|
||||
required DateTime? value,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColors.outline),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
value != null
|
||||
? '${value.year}-${value.month.toString().padLeft(2, '0')}-${value.day.toString().padLeft(2, '0')}'
|
||||
: '请选择$label',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: value != null ? AppColors.onSurface : AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.calendar_today,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInterestsField() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'兴趣爱好',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
GestureDetector(
|
||||
onTap: _showInterestsDialog,
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 16),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: AppColors.outline),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: _interests.isEmpty
|
||||
? Text(
|
||||
'请选择兴趣爱好',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
)
|
||||
: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: _interests.map((interest) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Text(
|
||||
interest,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.arrow_forward_ios,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
86
client/lib/features/profile/screens/profile_home_screen.dart
Normal file
86
client/lib/features/profile/screens/profile_home_screen.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/routes/app_routes.dart';
|
||||
import '../../auth/providers/auth_provider.dart';
|
||||
|
||||
class ProfileHomeScreen extends ConsumerWidget {
|
||||
const ProfileHomeScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final authState = ref.watch(authProvider);
|
||||
final user = authState.user;
|
||||
final isAuthenticated = authState.isAuthenticated;
|
||||
|
||||
if (!isAuthenticated || user == null) {
|
||||
return _buildLoginPrompt(context);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surface,
|
||||
appBar: AppBar(
|
||||
title: const Text('个人中心'),
|
||||
backgroundColor: AppColors.primary,
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 50,
|
||||
backgroundColor: AppColors.primary,
|
||||
child: Text(
|
||||
user.username?.substring(0, 1).toUpperCase() ?? 'U',
|
||||
style: const TextStyle(fontSize: 32, color: Colors.white),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
user.username ?? '用户',
|
||||
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
user.email ?? '',
|
||||
style: const TextStyle(fontSize: 16, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await ref.read(authProvider.notifier).logout();
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pushReplacementNamed(Routes.login);
|
||||
}
|
||||
},
|
||||
child: const Text('退出登录'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoginPrompt(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surface,
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.person_outline, size: 80, color: Colors.grey),
|
||||
const SizedBox(height: 16),
|
||||
const Text('请先登录', style: TextStyle(fontSize: 20)),
|
||||
const SizedBox(height: 32),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(Routes.login);
|
||||
},
|
||||
child: const Text('去登录'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/routes/app_routes.dart';
|
||||
import '../../auth/providers/auth_provider.dart';
|
||||
|
||||
class ProfileHomeScreen extends ConsumerWidget {
|
||||
const ProfileHomeScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final authState = ref.watch(authProvider);
|
||||
final user = authState.user;
|
||||
final isAuthenticated = authState.isAuthenticated;
|
||||
|
||||
if (!isAuthenticated || user == null) {
|
||||
return _buildLoginPrompt(context);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surface,
|
||||
appBar: AppBar(
|
||||
title: const Text('个人中心'),
|
||||
backgroundColor: AppColors.primary,
|
||||
),
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 50,
|
||||
backgroundColor: AppColors.primary,
|
||||
child: Text(
|
||||
user.username?.substring(0, 1).toUpperCase() ?? 'U',
|
||||
style: const TextStyle(fontSize: 32, color: Colors.white),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
user.username ?? '用户',
|
||||
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
user.email ?? '',
|
||||
style: const TextStyle(fontSize: 16, color: Colors.grey),
|
||||
),
|
||||
const SizedBox(height: 32),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
await ref.read(authProvider.notifier).logout();
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pushReplacementNamed(Routes.login);
|
||||
}
|
||||
},
|
||||
child: const Text('退出登录'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLoginPrompt(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surface,
|
||||
body: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.person_outline, size: 80, color: Colors.grey),
|
||||
const SizedBox(height: 16),
|
||||
const Text('请先登录', style: TextStyle(fontSize: 20)),
|
||||
const SizedBox(height: 32),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pushNamed(Routes.login);
|
||||
},
|
||||
child: const Text('去登录'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
731
client/lib/features/profile/screens/settings_screen.dart
Normal file
731
client/lib/features/profile/screens/settings_screen.dart
Normal file
@@ -0,0 +1,731 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_text_styles.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
import '../../../core/models/user_model.dart';
|
||||
import '../../auth/providers/auth_provider.dart';
|
||||
import 'change_password_screen.dart';
|
||||
|
||||
/// 设置屏幕
|
||||
class SettingsScreen extends StatefulWidget {
|
||||
const SettingsScreen({super.key});
|
||||
|
||||
@override
|
||||
State<SettingsScreen> createState() => _SettingsScreenState();
|
||||
}
|
||||
|
||||
class _SettingsScreenState extends State<SettingsScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: _buildAppBar(),
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
// 通知设置
|
||||
_buildNotificationSettings(),
|
||||
const SizedBox(height: AppDimensions.spacingSm),
|
||||
|
||||
// 学习设置
|
||||
_buildLearningSettings(),
|
||||
const SizedBox(height: AppDimensions.spacingSm),
|
||||
|
||||
// 账户设置
|
||||
_buildAccountSettings(),
|
||||
const SizedBox(height: AppDimensions.spacingSm),
|
||||
|
||||
// 其他设置
|
||||
_buildOtherSettings(),
|
||||
const SizedBox(height: AppDimensions.spacingXl),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建应用栏
|
||||
PreferredSizeWidget _buildAppBar() {
|
||||
return AppBar(
|
||||
backgroundColor: AppColors.surface,
|
||||
foregroundColor: AppColors.onSurface,
|
||||
elevation: 0,
|
||||
title: Text(
|
||||
'设置',
|
||||
style: AppTextStyles.titleLarge.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建通知设置
|
||||
Widget _buildNotificationSettings() {
|
||||
return Consumer<AuthNotifier>(
|
||||
builder: (context, authNotifier, child) {
|
||||
final user = authNotifier.state.user;
|
||||
final settings = user?.profile?.settings ?? const UserSettings();
|
||||
|
||||
return _buildSettingsSection(
|
||||
title: '通知设置',
|
||||
icon: Icons.notifications_outlined,
|
||||
children: [
|
||||
_buildSwitchTile(
|
||||
title: '推送通知',
|
||||
subtitle: '接收学习提醒和重要消息',
|
||||
value: settings.notificationsEnabled,
|
||||
onChanged: (value) {
|
||||
_updateSettings(settings.copyWith(
|
||||
notificationsEnabled: value,
|
||||
));
|
||||
},
|
||||
),
|
||||
_buildSwitchTile(
|
||||
title: '声音提醒',
|
||||
subtitle: '播放通知声音',
|
||||
value: settings.soundEnabled,
|
||||
onChanged: (value) {
|
||||
_updateSettings(settings.copyWith(
|
||||
soundEnabled: value,
|
||||
));
|
||||
},
|
||||
),
|
||||
_buildSwitchTile(
|
||||
title: '振动提醒',
|
||||
subtitle: '接收通知时振动',
|
||||
value: settings.vibrationEnabled,
|
||||
onChanged: (value) {
|
||||
_updateSettings(settings.copyWith(
|
||||
vibrationEnabled: value,
|
||||
));
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建学习设置
|
||||
Widget _buildLearningSettings() {
|
||||
return Consumer<AuthNotifier>(
|
||||
builder: (context, authNotifier, child) {
|
||||
final user = authNotifier.state.user;
|
||||
final settings = user?.profile?.settings ?? const UserSettings();
|
||||
|
||||
return _buildSettingsSection(
|
||||
title: '学习设置',
|
||||
icon: Icons.school_outlined,
|
||||
children: [
|
||||
_buildListTile(
|
||||
title: '每日单词目标',
|
||||
subtitle: '${settings.dailyWordGoal} 个单词',
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showDailyGoalDialog('word', settings.dailyWordGoal),
|
||||
),
|
||||
_buildListTile(
|
||||
title: '每日学习时长',
|
||||
subtitle: '${settings.dailyStudyMinutes} 分钟',
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showDailyGoalDialog('time', settings.dailyStudyMinutes),
|
||||
),
|
||||
_buildSwitchTile(
|
||||
title: '自动播放音频',
|
||||
subtitle: '学习时自动播放单词发音',
|
||||
value: settings.autoPlayAudio,
|
||||
onChanged: (value) {
|
||||
_updateSettings(settings.copyWith(
|
||||
autoPlayAudio: value,
|
||||
));
|
||||
},
|
||||
),
|
||||
_buildListTile(
|
||||
title: '音频播放速度',
|
||||
subtitle: '${settings.audioSpeed}x',
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showAudioSpeedDialog(settings.audioSpeed),
|
||||
),
|
||||
_buildSwitchTile(
|
||||
title: '显示中文翻译',
|
||||
subtitle: '学习时显示单词翻译',
|
||||
value: settings.showTranslation,
|
||||
onChanged: (value) {
|
||||
_updateSettings(settings.copyWith(
|
||||
showTranslation: value,
|
||||
));
|
||||
},
|
||||
),
|
||||
_buildSwitchTile(
|
||||
title: '显示音标',
|
||||
subtitle: '学习时显示单词音标',
|
||||
value: settings.showPronunciation,
|
||||
onChanged: (value) {
|
||||
_updateSettings(settings.copyWith(
|
||||
showPronunciation: value,
|
||||
));
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建账户设置
|
||||
Widget _buildAccountSettings() {
|
||||
return _buildSettingsSection(
|
||||
title: '账户设置',
|
||||
icon: Icons.account_circle_outlined,
|
||||
children: [
|
||||
_buildListTile(
|
||||
title: '修改密码',
|
||||
subtitle: '更改登录密码',
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => const ChangePasswordScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
_buildListTile(
|
||||
title: '清除缓存',
|
||||
subtitle: '清除本地缓存数据',
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: _showClearCacheDialog,
|
||||
),
|
||||
_buildListTile(
|
||||
title: '退出登录',
|
||||
subtitle: '退出当前账户',
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: _showLogoutDialog,
|
||||
),
|
||||
_buildListTile(
|
||||
title: '注销账户',
|
||||
subtitle: '永久删除账户和数据',
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
textColor: AppColors.error,
|
||||
onTap: _showDeleteAccountDialog,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建其他设置
|
||||
Widget _buildOtherSettings() {
|
||||
return Consumer<AuthNotifier>(
|
||||
builder: (context, authNotifier, child) {
|
||||
final user = authNotifier.state.user;
|
||||
final settings = user?.profile?.settings ?? const UserSettings();
|
||||
|
||||
return _buildSettingsSection(
|
||||
title: '其他设置',
|
||||
icon: Icons.settings_outlined,
|
||||
children: [
|
||||
_buildListTile(
|
||||
title: '语言设置',
|
||||
subtitle: _getLanguageDisplayName(settings.language),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showLanguageDialog(settings.language),
|
||||
),
|
||||
_buildListTile(
|
||||
title: '主题设置',
|
||||
subtitle: _getThemeDisplayName(settings.theme),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showThemeDialog(settings.theme),
|
||||
),
|
||||
_buildListTile(
|
||||
title: '关于我们',
|
||||
subtitle: '版本信息和帮助',
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: _showAboutDialog,
|
||||
),
|
||||
_buildListTile(
|
||||
title: '用户协议',
|
||||
subtitle: '查看用户服务协议',
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showWebView('用户协议', 'https://example.com/terms'),
|
||||
),
|
||||
_buildListTile(
|
||||
title: '隐私政策',
|
||||
subtitle: '查看隐私保护政策',
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () => _showWebView('隐私政策', 'https://example.com/privacy'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建设置分组
|
||||
Widget _buildSettingsSection({
|
||||
required String title,
|
||||
required IconData icon,
|
||||
required List<Widget> children,
|
||||
}) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.spacingMd,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.shadow.withOpacity(0.05),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 分组标题
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
color: AppColors.primary,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
Text(
|
||||
title,
|
||||
style: AppTextStyles.titleSmall.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 分组内容
|
||||
...children,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建列表项
|
||||
Widget _buildListTile({
|
||||
required String title,
|
||||
required String subtitle,
|
||||
Widget? trailing,
|
||||
VoidCallback? onTap,
|
||||
Color? textColor,
|
||||
}) {
|
||||
return ListTile(
|
||||
title: Text(
|
||||
title,
|
||||
style: AppTextStyles.bodyLarge.copyWith(
|
||||
color: textColor ?? AppColors.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
subtitle,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
trailing: trailing,
|
||||
onTap: onTap,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.spacingMd,
|
||||
vertical: AppDimensions.spacingXs,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建开关项
|
||||
Widget _buildSwitchTile({
|
||||
required String title,
|
||||
required String subtitle,
|
||||
required bool value,
|
||||
required ValueChanged<bool> onChanged,
|
||||
}) {
|
||||
return SwitchListTile(
|
||||
title: Text(
|
||||
title,
|
||||
style: AppTextStyles.bodyLarge.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
subtitle: Text(
|
||||
subtitle,
|
||||
style: AppTextStyles.bodySmall.copyWith(
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
value: value,
|
||||
onChanged: onChanged,
|
||||
activeColor: AppColors.primary,
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: AppDimensions.spacingMd,
|
||||
vertical: AppDimensions.spacingXs,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 更新设置
|
||||
Future<void> _updateSettings(UserSettings settings) async {
|
||||
try {
|
||||
final authNotifier = Provider.of<AuthNotifier>(context, listen: false);
|
||||
final currentUser = authNotifier.state.user;
|
||||
|
||||
if (currentUser != null) {
|
||||
// 将设置转换为Map格式传递给updateProfile
|
||||
final settingsMap = {
|
||||
'notificationsEnabled': settings.notificationsEnabled,
|
||||
'soundEnabled': settings.soundEnabled,
|
||||
'vibrationEnabled': settings.vibrationEnabled,
|
||||
'language': settings.language,
|
||||
'theme': settings.theme,
|
||||
'dailyGoal': settings.dailyGoal,
|
||||
'dailyWordGoal': settings.dailyWordGoal,
|
||||
'dailyStudyMinutes': settings.dailyStudyMinutes,
|
||||
'reminderTimes': settings.reminderTimes,
|
||||
'autoPlayAudio': settings.autoPlayAudio,
|
||||
'audioSpeed': settings.audioSpeed,
|
||||
'showTranslation': settings.showTranslation,
|
||||
'showPronunciation': settings.showPronunciation,
|
||||
};
|
||||
|
||||
await authNotifier.updateProfile(
|
||||
username: currentUser.username,
|
||||
email: currentUser.email,
|
||||
phone: currentUser.profile?.phone,
|
||||
avatar: currentUser.profile?.avatar,
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('设置更新失败: $e'),
|
||||
backgroundColor: AppColors.error,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 显示每日目标设置对话框
|
||||
void _showDailyGoalDialog(String type, int currentValue) {
|
||||
final controller = TextEditingController(text: currentValue.toString());
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(type == 'word' ? '设置每日单词目标' : '设置每日学习时长'),
|
||||
content: TextField(
|
||||
controller: controller,
|
||||
keyboardType: TextInputType.number,
|
||||
decoration: InputDecoration(
|
||||
labelText: type == 'word' ? '单词数量' : '分钟数',
|
||||
suffixText: type == 'word' ? '个' : '分钟',
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
final value = int.tryParse(controller.text) ?? currentValue;
|
||||
if (value > 0) {
|
||||
final authNotifier = Provider.of<AuthNotifier>(context, listen: false);
|
||||
final user = authNotifier.state.user;
|
||||
final settings = user?.profile?.settings ?? UserSettings();
|
||||
|
||||
if (type == 'word') {
|
||||
_updateSettings(settings.copyWith(dailyWordGoal: value));
|
||||
} else {
|
||||
_updateSettings(settings.copyWith(dailyStudyMinutes: value));
|
||||
}
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示音频速度设置对话框
|
||||
void _showAudioSpeedDialog(double currentSpeed) {
|
||||
final speeds = [0.5, 0.75, 1.0, 1.25, 1.5, 2.0];
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('设置音频播放速度'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: speeds.map((speed) {
|
||||
return RadioListTile<double>(
|
||||
title: Text('${speed}x'),
|
||||
value: speed,
|
||||
groupValue: currentSpeed,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
final authNotifier = Provider.of<AuthNotifier>(context, listen: false);
|
||||
final user = authNotifier.state.user;
|
||||
final settings = user?.profile?.settings ?? const UserSettings();
|
||||
|
||||
_updateSettings(settings.copyWith(audioSpeed: value));
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示语言设置对话框
|
||||
void _showLanguageDialog(String currentLanguage) {
|
||||
final languages = {
|
||||
'zh': '中文',
|
||||
'en': 'English',
|
||||
};
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('选择语言'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: languages.entries.map((entry) {
|
||||
return RadioListTile<String>(
|
||||
title: Text(entry.value),
|
||||
value: entry.key,
|
||||
groupValue: currentLanguage,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
final authNotifier = Provider.of<AuthNotifier>(context, listen: false);
|
||||
final user = authNotifier.state.user;
|
||||
final settings = user?.profile?.settings ?? const UserSettings();
|
||||
|
||||
_updateSettings(settings.copyWith(language: value));
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示主题设置对话框
|
||||
void _showThemeDialog(String currentTheme) {
|
||||
final themes = {
|
||||
'light': '浅色主题',
|
||||
'dark': '深色主题',
|
||||
'system': '跟随系统',
|
||||
};
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('选择主题'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: themes.entries.map((entry) {
|
||||
return RadioListTile<String>(
|
||||
title: Text(entry.value),
|
||||
value: entry.key,
|
||||
groupValue: currentTheme,
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
final authNotifier = Provider.of<AuthNotifier>(context, listen: false);
|
||||
final user = authNotifier.state.user;
|
||||
final settings = user?.profile?.settings ?? const UserSettings();
|
||||
|
||||
_updateSettings(settings.copyWith(theme: value));
|
||||
}
|
||||
Navigator.pop(context);
|
||||
},
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示清除缓存对话框
|
||||
void _showClearCacheDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('清除缓存'),
|
||||
content: const Text('确定要清除所有缓存数据吗?这将删除已下载的音频、图片等文件。'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// TODO: 实现清除缓存逻辑
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('缓存已清除')),
|
||||
);
|
||||
},
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示退出登录对话框
|
||||
void _showLogoutDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('退出登录'),
|
||||
content: const Text('确定要退出当前账户吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final authNotifier = Provider.of<AuthNotifier>(context, listen: false);
|
||||
await authNotifier.logout();
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
Navigator.pushNamedAndRemoveUntil(
|
||||
context,
|
||||
'/login',
|
||||
(route) => false,
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text('确定'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示注销账户对话框
|
||||
void _showDeleteAccountDialog() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(
|
||||
'注销账户',
|
||||
style: TextStyle(color: AppColors.error),
|
||||
),
|
||||
content: const Text(
|
||||
'警告:此操作将永久删除您的账户和所有数据,且无法恢复。确定要继续吗?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
// TODO: 实现注销账户逻辑
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: const Text('账户注销功能暂未开放'),
|
||||
backgroundColor: AppColors.warning,
|
||||
),
|
||||
);
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: AppColors.error,
|
||||
),
|
||||
child: const Text('确定注销'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示关于对话框
|
||||
void _showAboutDialog() {
|
||||
showAboutDialog(
|
||||
context: context,
|
||||
applicationName: 'AI英语学习',
|
||||
applicationVersion: '1.0.0',
|
||||
applicationIcon: Container(
|
||||
width: 64,
|
||||
height: 64,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.school,
|
||||
color: AppColors.onPrimary,
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
children: [
|
||||
const Text('一款基于AI技术的智能英语学习应用'),
|
||||
const SizedBox(height: 16),
|
||||
const Text('© 2024 AI英语学习团队'),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示网页视图
|
||||
void _showWebView(String title, String url) {
|
||||
// TODO: 实现网页视图
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('即将打开: $title'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 获取语言显示名称
|
||||
String _getLanguageDisplayName(String language) {
|
||||
switch (language) {
|
||||
case 'zh':
|
||||
return '中文';
|
||||
case 'en':
|
||||
return 'English';
|
||||
default:
|
||||
return '中文';
|
||||
}
|
||||
}
|
||||
|
||||
/// 获取主题显示名称
|
||||
String _getThemeDisplayName(String theme) {
|
||||
switch (theme) {
|
||||
case 'light':
|
||||
return '浅色主题';
|
||||
case 'dark':
|
||||
return '深色主题';
|
||||
case 'system':
|
||||
return '跟随系统';
|
||||
default:
|
||||
return '浅色主题';
|
||||
}
|
||||
}
|
||||
}
|
||||
576
client/lib/features/profile/widgets/about_dialog.dart
Normal file
576
client/lib/features/profile/widgets/about_dialog.dart
Normal file
@@ -0,0 +1,576 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
|
||||
/// 关于应用对话框
|
||||
class AboutAppDialog extends StatefulWidget {
|
||||
const AboutAppDialog({super.key});
|
||||
|
||||
@override
|
||||
State<AboutAppDialog> createState() => _AboutAppDialogState();
|
||||
}
|
||||
|
||||
class _AboutAppDialogState extends State<AboutAppDialog> {
|
||||
PackageInfo? _packageInfo;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_loadPackageInfo();
|
||||
}
|
||||
|
||||
Future<void> _loadPackageInfo() async {
|
||||
try {
|
||||
final packageInfo = await PackageInfo.fromPlatform();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_packageInfo = packageInfo;
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
// 如果获取包信息失败,使用默认值
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_packageInfo = PackageInfo(
|
||||
appName: 'AI英语学习',
|
||||
packageName: 'com.example.ai_english_learning',
|
||||
version: '1.0.0',
|
||||
buildNumber: '1',
|
||||
buildSignature: '',
|
||||
installerStore: null,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(24),
|
||||
constraints: const BoxConstraints(maxWidth: 400),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 应用图标和名称
|
||||
_buildAppHeader(),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 版本信息
|
||||
_buildVersionInfo(),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 应用描述
|
||||
_buildAppDescription(),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 开发团队信息
|
||||
_buildTeamInfo(),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 联系方式
|
||||
_buildContactInfo(),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 法律信息
|
||||
_buildLegalInfo(),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 关闭按钮
|
||||
_buildCloseButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建应用头部
|
||||
Widget _buildAppHeader() {
|
||||
return Column(
|
||||
children: [
|
||||
// 应用图标
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColors.primary,
|
||||
AppColors.primary.withOpacity(0.8),
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.school,
|
||||
color: Colors.white,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// 应用名称
|
||||
Text(
|
||||
_packageInfo?.appName ?? 'AI英语学习',
|
||||
style: TextStyle(
|
||||
fontSize: 24,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// 应用标语
|
||||
Text(
|
||||
'智能化英语学习助手',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建版本信息
|
||||
Widget _buildVersionInfo() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: AppColors.outline.withOpacity(0.2),
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildInfoRow(
|
||||
'版本号',
|
||||
_packageInfo?.version ?? '1.0.0',
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildInfoRow(
|
||||
'构建号',
|
||||
_packageInfo?.buildNumber ?? '1',
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
_buildInfoRow(
|
||||
'发布日期',
|
||||
'2024年1月',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建应用描述
|
||||
Widget _buildAppDescription() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'应用介绍',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'AI英语学习是一款基于人工智能技术的英语学习应用,提供个性化的学习方案,包括单词记忆、语法练习、听力训练、口语练习等功能,帮助用户高效提升英语水平。',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建团队信息
|
||||
Widget _buildTeamInfo() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'开发团队',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildTeamMember('产品经理', 'Alice Wang'),
|
||||
_buildTeamMember('技术负责人', 'Bob Chen'),
|
||||
_buildTeamMember('UI/UX设计师', 'Carol Li'),
|
||||
_buildTeamMember('前端开发', 'David Zhang'),
|
||||
_buildTeamMember('后端开发', 'Eva Liu'),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建团队成员信息
|
||||
Widget _buildTeamMember(String role, String name) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
role,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建联系信息
|
||||
Widget _buildContactInfo() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'联系我们',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildContactItem(
|
||||
Icons.email,
|
||||
'邮箱',
|
||||
'support@aienglish.com',
|
||||
() => _copyToClipboard('support@aienglish.com', '邮箱地址已复制'),
|
||||
),
|
||||
_buildContactItem(
|
||||
Icons.language,
|
||||
'官网',
|
||||
'www.aienglish.com',
|
||||
() => _copyToClipboard('www.aienglish.com', '网址已复制'),
|
||||
),
|
||||
_buildContactItem(
|
||||
Icons.phone,
|
||||
'客服电话',
|
||||
'400-123-4567',
|
||||
() => _copyToClipboard('400-123-4567', '电话号码已复制'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建联系项目
|
||||
Widget _buildContactItem(
|
||||
IconData icon,
|
||||
String label,
|
||||
String value,
|
||||
VoidCallback onTap,
|
||||
) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 4),
|
||||
child: GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
icon,
|
||||
size: 16,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'$label: ',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.primary,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
),
|
||||
),
|
||||
Icon(
|
||||
Icons.copy,
|
||||
size: 16,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建法律信息
|
||||
Widget _buildLegalInfo() {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'法律信息',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_buildLegalLink('用户协议', () => _showLegalDocument('用户协议')),
|
||||
_buildLegalLink('隐私政策', () => _showLegalDocument('隐私政策')),
|
||||
_buildLegalLink('开源许可', () => _showLicenses()),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'© 2024 AI英语学习团队. 保留所有权利.',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建法律链接
|
||||
Widget _buildLegalLink(String text, VoidCallback onTap) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Text(
|
||||
text,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.primary,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建信息行
|
||||
Widget _buildInfoRow(String label, String value) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.onSurface,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建关闭按钮
|
||||
Widget _buildCloseButton() {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'关闭',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 复制到剪贴板
|
||||
void _copyToClipboard(String text, String message) {
|
||||
Clipboard.setData(ClipboardData(text: text));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示法律文档
|
||||
void _showLegalDocument(String title) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(title),
|
||||
content: SingleChildScrollView(
|
||||
child: Text(
|
||||
title == '用户协议'
|
||||
? _getUserAgreementText()
|
||||
: _getPrivacyPolicyText(),
|
||||
style: const TextStyle(fontSize: 14, height: 1.5),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('关闭'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 显示开源许可
|
||||
void _showLicenses() {
|
||||
showLicensePage(
|
||||
context: context,
|
||||
applicationName: _packageInfo?.appName ?? 'AI英语学习',
|
||||
applicationVersion: _packageInfo?.version ?? '1.0.0',
|
||||
applicationIcon: Container(
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
AppColors.primary,
|
||||
AppColors.primary.withOpacity(0.8),
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.school,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 获取用户协议文本
|
||||
String _getUserAgreementText() {
|
||||
return '''
|
||||
欢迎使用AI英语学习应用!
|
||||
|
||||
1. 服务条款
|
||||
本应用为用户提供英语学习服务,包括但不限于单词学习、语法练习、听力训练等功能。
|
||||
|
||||
2. 用户责任
|
||||
用户应当合法使用本应用,不得进行任何违法违规行为。
|
||||
|
||||
3. 隐私保护
|
||||
我们重视用户隐私,详细信息请查看隐私政策。
|
||||
|
||||
4. 知识产权
|
||||
本应用的所有内容均受知识产权法保护。
|
||||
|
||||
5. 免责声明
|
||||
本应用仅供学习参考,不承担任何学习效果保证责任。
|
||||
|
||||
6. 协议修改
|
||||
我们保留随时修改本协议的权利,修改后的协议将在应用内公布。
|
||||
|
||||
如有疑问,请联系客服:support@aienglish.com
|
||||
''';
|
||||
}
|
||||
|
||||
/// 获取隐私政策文本
|
||||
String _getPrivacyPolicyText() {
|
||||
return '''
|
||||
AI英语学习隐私政策
|
||||
|
||||
1. 信息收集
|
||||
我们可能收集以下信息:
|
||||
- 账户信息(用户名、邮箱等)
|
||||
- 学习数据(学习进度、成绩等)
|
||||
- 设备信息(设备型号、操作系统等)
|
||||
|
||||
2. 信息使用
|
||||
收集的信息用于:
|
||||
- 提供个性化学习服务
|
||||
- 改进应用功能
|
||||
- 发送重要通知
|
||||
|
||||
3. 信息保护
|
||||
我们采用行业标准的安全措施保护用户信息。
|
||||
|
||||
4. 信息共享
|
||||
除法律要求外,我们不会与第三方共享用户个人信息。
|
||||
|
||||
5. Cookie使用
|
||||
我们可能使用Cookie来改善用户体验。
|
||||
|
||||
6. 政策更新
|
||||
本隐私政策可能会定期更新,请关注最新版本。
|
||||
|
||||
联系我们:support@aienglish.com
|
||||
''';
|
||||
}
|
||||
}
|
||||
|
||||
/// 显示关于应用对话框的便捷方法
|
||||
void showAboutAppDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => const AboutAppDialog(),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_text_styles.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
|
||||
/// 学习偏好卡片组件
|
||||
class LearningPreferencesCard extends StatelessWidget {
|
||||
final String title;
|
||||
final Widget child;
|
||||
final EdgeInsetsGeometry? padding;
|
||||
final VoidCallback? onTap;
|
||||
final IconData? icon;
|
||||
|
||||
const LearningPreferencesCard({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.child,
|
||||
this.padding,
|
||||
this.onTap,
|
||||
this.icon,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
border: Border.all(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
width: 1,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.shadow.withOpacity(0.05),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
child: Padding(
|
||||
padding: padding ?? const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 标题行
|
||||
Row(
|
||||
children: [
|
||||
if (icon != null) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.all(AppDimensions.spacingSm),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusSm),
|
||||
),
|
||||
child: Icon(
|
||||
icon,
|
||||
color: AppColors.primary,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: AppDimensions.spacingSm),
|
||||
],
|
||||
|
||||
Expanded(
|
||||
child: Text(
|
||||
title,
|
||||
style: AppTextStyles.titleMedium.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (onTap != null)
|
||||
Icon(
|
||||
Icons.chevron_right,
|
||||
color: AppColors.onSurfaceVariant,
|
||||
size: 20,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
// 内容
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
144
client/lib/features/profile/widgets/profile_avatar.dart
Normal file
144
client/lib/features/profile/widgets/profile_avatar.dart
Normal file
@@ -0,0 +1,144 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:io';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
|
||||
/// 个人资料头像组件
|
||||
class ProfileAvatar extends StatelessWidget {
|
||||
final String? imageUrl;
|
||||
final File? selectedImage;
|
||||
final double size;
|
||||
final bool isEditing;
|
||||
final VoidCallback? onImageSelected;
|
||||
|
||||
const ProfileAvatar({
|
||||
super.key,
|
||||
this.imageUrl,
|
||||
this.selectedImage,
|
||||
this.size = 80,
|
||||
this.isEditing = false,
|
||||
this.onImageSelected,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
children: [
|
||||
// 头像
|
||||
Container(
|
||||
width: size,
|
||||
height: size,
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: AppColors.primary.withOpacity(0.3),
|
||||
width: 2,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.shadow.withOpacity(0.1),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipOval(
|
||||
child: _buildAvatarImage(),
|
||||
),
|
||||
),
|
||||
|
||||
// 编辑按钮
|
||||
if (isEditing)
|
||||
Positioned(
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: GestureDetector(
|
||||
onTap: onImageSelected,
|
||||
child: Container(
|
||||
width: size * 0.3,
|
||||
height: size * 0.3,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primary,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: AppColors.surface,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.camera_alt,
|
||||
color: AppColors.onPrimary,
|
||||
size: size * 0.15,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建头像图片
|
||||
Widget _buildAvatarImage() {
|
||||
// 优先显示选中的图片
|
||||
if (selectedImage != null) {
|
||||
return Image.file(
|
||||
selectedImage!,
|
||||
fit: BoxFit.cover,
|
||||
width: size,
|
||||
height: size,
|
||||
);
|
||||
}
|
||||
|
||||
// 显示网络图片
|
||||
if (imageUrl != null && imageUrl!.isNotEmpty) {
|
||||
return Image.network(
|
||||
imageUrl!,
|
||||
fit: BoxFit.cover,
|
||||
width: size,
|
||||
height: size,
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return _buildDefaultAvatar();
|
||||
},
|
||||
loadingBuilder: (context, child, loadingProgress) {
|
||||
if (loadingProgress == null) return child;
|
||||
return Center(
|
||||
child: CircularProgressIndicator(
|
||||
value: loadingProgress.expectedTotalBytes != null
|
||||
? loadingProgress.cumulativeBytesLoaded /
|
||||
loadingProgress.expectedTotalBytes!
|
||||
: null,
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(AppColors.primary),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// 默认头像
|
||||
return _buildDefaultAvatar();
|
||||
}
|
||||
|
||||
/// 构建默认头像
|
||||
Widget _buildDefaultAvatar() {
|
||||
return Container(
|
||||
width: size,
|
||||
height: size,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
AppColors.primary.withOpacity(0.8),
|
||||
AppColors.primary,
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Icon(
|
||||
Icons.person,
|
||||
color: AppColors.onPrimary,
|
||||
size: size * 0.5,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
65
client/lib/features/profile/widgets/profile_info_card.dart
Normal file
65
client/lib/features/profile/widgets/profile_info_card.dart
Normal file
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../../core/theme/app_colors.dart';
|
||||
import '../../../core/theme/app_text_styles.dart';
|
||||
import '../../../core/theme/app_dimensions.dart';
|
||||
|
||||
/// 个人信息卡片组件
|
||||
class ProfileInfoCard extends StatelessWidget {
|
||||
final String title;
|
||||
final Widget child;
|
||||
final EdgeInsetsGeometry? padding;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
const ProfileInfoCard({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.child,
|
||||
this.padding,
|
||||
this.onTap,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surface,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: AppColors.shadow.withOpacity(0.05),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(AppDimensions.radiusMd),
|
||||
child: Padding(
|
||||
padding: padding ?? const EdgeInsets.all(AppDimensions.spacingMd),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 标题
|
||||
Text(
|
||||
title,
|
||||
style: AppTextStyles.titleMedium.copyWith(
|
||||
color: AppColors.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: AppDimensions.spacingMd),
|
||||
|
||||
// 内容
|
||||
child,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user