| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253 |
- import 'package:flutter/material.dart';
- import 'package:flutter_riverpod/flutter_riverpod.dart';
- import 'package:go_router/go_router.dart';
- import 'package:tdesign_flutter/tdesign_flutter.dart';
- import '../../core/i18n/app_localizations.dart';
- import '../../core/i18n/locale_provider.dart';
- import '../../core/theme/app_colors.dart';
- import '../../shared/widgets/profile_menu_item.dart';
- import '../shell/nav_bar_config.dart';
- class ProfilePage extends ConsumerWidget {
- const ProfilePage({super.key});
- @override
- Widget build(BuildContext context, WidgetRef ref) {
- final l10n = AppLocalizations.of(context);
- final location = GoRouterState.of(context).uri.toString();
- final currentLocale = ref.watch(localeProvider);
- if (location.startsWith('/profile')) {
- ref
- .read(navBarConfigProvider.notifier)
- .update(
- NavBarConfig(
- title: l10n.get('tabProfile'),
- showBack: true,
- leadingIcon: Icons.close,
- ),
- );
- }
- return SingleChildScrollView(
- physics: const AlwaysScrollableScrollPhysics(),
- child: Column(
- children: [
- const SizedBox(height: 16),
- _buildUserInfoCard(context, l10n),
- const SizedBox(height: 16),
- // 功能列表
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Column(
- children: [
- // ── 语言设置 ──
- ProfileMenuItem(
- icon: Icons.language,
- label: l10n.get('language'),
- trailing: _localeName(currentLocale),
- onTap: () => _showLanguageSheet(context, ref, currentLocale),
- ),
- const SizedBox(height: 8),
- // ── 关于 ──
- ProfileMenuItem(
- icon: Icons.info_outline,
- label: l10n.get('about'),
- onTap: () => _showAboutDialog(context, l10n),
- ),
- ],
- ),
- ),
- const SizedBox(height: 8),
- TDFooter(TDFooterType.text, text: l10n.get('version')),
- ],
- ),
- );
- }
- Widget _buildUserInfoCard(BuildContext context, AppLocalizations l10n) {
- return Container(
- margin: const EdgeInsets.symmetric(horizontal: 16),
- padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
- decoration: BoxDecoration(
- color: AppColors.bgCard,
- borderRadius: BorderRadius.circular(12),
- ),
- child: Row(
- children: [
- // 头像 - 点击更换占位
- GestureDetector(
- onTap: () {
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('头像更换功能(占位)'), duration: Duration(seconds: 2)),
- );
- },
- child: Container(
- width: 64,
- height: 64,
- decoration: const BoxDecoration(
- color: AppColors.primaryLight,
- shape: BoxShape.circle,
- ),
- child: Center(
- child: Text(
- '张',
- style: const TextStyle(
- fontSize: 28,
- fontWeight: FontWeight.w700,
- color: AppColors.primary,
- ),
- ),
- ),
- ),
- ),
- const SizedBox(width: 16),
- // 用户信息
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- l10n.get('userName'),
- style: const TextStyle(
- fontSize: AppFontSizes.title,
- fontWeight: FontWeight.w600,
- color: AppColors.textPrimary,
- ),
- ),
- const SizedBox(height: AppSpacing.xs),
- Text(
- l10n.get('salesDepartment'),
- style: const TextStyle(
- fontSize: AppFontSizes.body,
- color: AppColors.textSecondary,
- ),
- ),
- const SizedBox(height: 2),
- Text(
- '销售经理',
- style: const TextStyle(
- fontSize: 12,
- color: AppColors.textPlaceholder,
- ),
- ),
- ],
- ),
- ),
- // 箭头
- const Icon(
- Icons.chevron_right,
- size: 16,
- color: AppColors.textPlaceholder,
- ),
- ],
- ),
- );
- }
- String _localeName(Locale locale) {
- if (locale.languageCode == 'zh' && locale.countryCode == 'TW') {
- return '繁體中文';
- }
- if (locale.languageCode == 'en') {
- return 'English';
- }
- return '简体中文';
- }
- void _showLanguageSheet(
- BuildContext context,
- WidgetRef ref,
- Locale currentLocale,
- ) {
- final languages = [
- (label: '简体中文', locale: const Locale('zh', 'CN')),
- (label: 'English', locale: const Locale('en')),
- (label: '繁體中文', locale: const Locale('zh', 'TW')),
- ];
- TDActionSheet.showListActionSheet(
- Navigator.of(context, rootNavigator: true).context,
- showCancel: false,
- useSafeArea: false,
- items: languages.map((lang) {
- final isSelected =
- lang.locale.languageCode == currentLocale.languageCode &&
- lang.locale.countryCode == currentLocale.countryCode;
- return TDActionSheetItem(
- label: isSelected ? '${lang.label} ✓' : lang.label,
- textStyle: TextStyle(
- color: isSelected ? AppColors.primary : AppColors.textPrimary,
- fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
- ),
- );
- }).toList(),
- onSelected: (item, index) {
- ref.read(localeProvider.notifier).setLocale(languages[index].locale);
- },
- );
- }
- void _showAboutDialog(BuildContext context, AppLocalizations l10n) {
- showGeneralDialog(
- context: context,
- pageBuilder: (BuildContext buildContext, Animation<double> animation,
- Animation<double> secondaryAnimation) {
- return TDConfirmDialog(
- title: l10n.get('about'),
- titleColor: AppColors.textPrimary,
- contentWidget: Column(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- _aboutRow(l10n.get('version'), 'v1.0.0 (Build 20260601)'),
- const Divider(height: 24),
- GestureDetector(
- onTap: () {
- Navigator.of(buildContext).pop();
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('用户协议(占位)'), duration: Duration(seconds: 2)),
- );
- },
- child: const Text('用户协议',
- style: TextStyle(fontSize: 14, color: AppColors.primary)),
- ),
- const SizedBox(height: 12),
- GestureDetector(
- onTap: () {
- Navigator.of(buildContext).pop();
- ScaffoldMessenger.of(context).showSnackBar(
- const SnackBar(content: Text('隐私政策(占位)'), duration: Duration(seconds: 2)),
- );
- },
- child: const Text('隐私政策',
- style: TextStyle(fontSize: 14, color: AppColors.primary)),
- ),
- ],
- ),
- buttonStyle: TDDialogButtonStyle.text,
- buttonText: l10n.get('close'),
- buttonTextColor: AppColors.primary,
- action: () => Navigator.of(buildContext).pop(),
- );
- },
- );
- }
- Widget _aboutRow(String label, String value) {
- return Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- Text(label,
- style: const TextStyle(
- fontSize: 14, color: AppColors.textSecondary)),
- Flexible(
- child: Text(value,
- textAlign: TextAlign.right,
- softWrap: true,
- style: const TextStyle(
- fontSize: 14, color: AppColors.textPrimary)),
- ),
- ],
- );
- }
- }
|