profile_page.dart 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_riverpod/flutter_riverpod.dart';
  3. import 'package:go_router/go_router.dart';
  4. import 'package:tdesign_flutter/tdesign_flutter.dart';
  5. import '../../core/i18n/app_localizations.dart';
  6. import '../../core/i18n/locale_provider.dart';
  7. import '../../core/theme/app_colors.dart';
  8. import '../../shared/widgets/profile_menu_item.dart';
  9. import '../shell/nav_bar_config.dart';
  10. class ProfilePage extends ConsumerWidget {
  11. const ProfilePage({super.key});
  12. @override
  13. Widget build(BuildContext context, WidgetRef ref) {
  14. final l10n = AppLocalizations.of(context);
  15. final location = GoRouterState.of(context).uri.toString();
  16. final currentLocale = ref.watch(localeProvider);
  17. if (location.startsWith('/profile')) {
  18. ref
  19. .read(navBarConfigProvider.notifier)
  20. .update(
  21. NavBarConfig(
  22. title: l10n.get('tabProfile'),
  23. showBack: true,
  24. leadingIcon: Icons.close,
  25. ),
  26. );
  27. }
  28. return SingleChildScrollView(
  29. physics: const AlwaysScrollableScrollPhysics(),
  30. child: Column(
  31. children: [
  32. const SizedBox(height: 16),
  33. _buildUserInfoCard(context, l10n),
  34. const SizedBox(height: 16),
  35. // 功能列表
  36. Padding(
  37. padding: const EdgeInsets.symmetric(horizontal: 16),
  38. child: Column(
  39. children: [
  40. // ── 语言设置 ──
  41. ProfileMenuItem(
  42. icon: Icons.language,
  43. label: l10n.get('language'),
  44. trailing: _localeName(currentLocale),
  45. onTap: () => _showLanguageSheet(context, ref, currentLocale),
  46. ),
  47. const SizedBox(height: 8),
  48. // ── 关于 ──
  49. ProfileMenuItem(
  50. icon: Icons.info_outline,
  51. label: l10n.get('about'),
  52. onTap: () => _showAboutDialog(context, l10n),
  53. ),
  54. ],
  55. ),
  56. ),
  57. const SizedBox(height: 8),
  58. TDFooter(TDFooterType.text, text: l10n.get('version')),
  59. ],
  60. ),
  61. );
  62. }
  63. Widget _buildUserInfoCard(BuildContext context, AppLocalizations l10n) {
  64. return Container(
  65. margin: const EdgeInsets.symmetric(horizontal: 16),
  66. padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
  67. decoration: BoxDecoration(
  68. color: AppColors.bgCard,
  69. borderRadius: BorderRadius.circular(12),
  70. ),
  71. child: Row(
  72. children: [
  73. // 头像 - 点击更换占位
  74. GestureDetector(
  75. onTap: () {
  76. ScaffoldMessenger.of(context).showSnackBar(
  77. const SnackBar(content: Text('头像更换功能(占位)'), duration: Duration(seconds: 2)),
  78. );
  79. },
  80. child: Container(
  81. width: 64,
  82. height: 64,
  83. decoration: const BoxDecoration(
  84. color: AppColors.primaryLight,
  85. shape: BoxShape.circle,
  86. ),
  87. child: Center(
  88. child: Text(
  89. '张',
  90. style: const TextStyle(
  91. fontSize: 28,
  92. fontWeight: FontWeight.w700,
  93. color: AppColors.primary,
  94. ),
  95. ),
  96. ),
  97. ),
  98. ),
  99. const SizedBox(width: 16),
  100. // 用户信息
  101. Expanded(
  102. child: Column(
  103. crossAxisAlignment: CrossAxisAlignment.start,
  104. children: [
  105. Text(
  106. l10n.get('userName'),
  107. style: const TextStyle(
  108. fontSize: AppFontSizes.title,
  109. fontWeight: FontWeight.w600,
  110. color: AppColors.textPrimary,
  111. ),
  112. ),
  113. const SizedBox(height: AppSpacing.xs),
  114. Text(
  115. l10n.get('salesDepartment'),
  116. style: const TextStyle(
  117. fontSize: AppFontSizes.body,
  118. color: AppColors.textSecondary,
  119. ),
  120. ),
  121. const SizedBox(height: 2),
  122. Text(
  123. '销售经理',
  124. style: const TextStyle(
  125. fontSize: 12,
  126. color: AppColors.textPlaceholder,
  127. ),
  128. ),
  129. ],
  130. ),
  131. ),
  132. // 箭头
  133. const Icon(
  134. Icons.chevron_right,
  135. size: 16,
  136. color: AppColors.textPlaceholder,
  137. ),
  138. ],
  139. ),
  140. );
  141. }
  142. String _localeName(Locale locale) {
  143. if (locale.languageCode == 'zh' && locale.countryCode == 'TW') {
  144. return '繁體中文';
  145. }
  146. if (locale.languageCode == 'en') {
  147. return 'English';
  148. }
  149. return '简体中文';
  150. }
  151. void _showLanguageSheet(
  152. BuildContext context,
  153. WidgetRef ref,
  154. Locale currentLocale,
  155. ) {
  156. final languages = [
  157. (label: '简体中文', locale: const Locale('zh', 'CN')),
  158. (label: 'English', locale: const Locale('en')),
  159. (label: '繁體中文', locale: const Locale('zh', 'TW')),
  160. ];
  161. TDActionSheet.showListActionSheet(
  162. Navigator.of(context, rootNavigator: true).context,
  163. showCancel: false,
  164. useSafeArea: false,
  165. items: languages.map((lang) {
  166. final isSelected =
  167. lang.locale.languageCode == currentLocale.languageCode &&
  168. lang.locale.countryCode == currentLocale.countryCode;
  169. return TDActionSheetItem(
  170. label: isSelected ? '${lang.label} ✓' : lang.label,
  171. textStyle: TextStyle(
  172. color: isSelected ? AppColors.primary : AppColors.textPrimary,
  173. fontWeight: isSelected ? FontWeight.w600 : FontWeight.normal,
  174. ),
  175. );
  176. }).toList(),
  177. onSelected: (item, index) {
  178. ref.read(localeProvider.notifier).setLocale(languages[index].locale);
  179. },
  180. );
  181. }
  182. void _showAboutDialog(BuildContext context, AppLocalizations l10n) {
  183. showGeneralDialog(
  184. context: context,
  185. pageBuilder: (BuildContext buildContext, Animation<double> animation,
  186. Animation<double> secondaryAnimation) {
  187. return TDConfirmDialog(
  188. title: l10n.get('about'),
  189. titleColor: AppColors.textPrimary,
  190. contentWidget: Column(
  191. mainAxisSize: MainAxisSize.min,
  192. crossAxisAlignment: CrossAxisAlignment.start,
  193. children: [
  194. _aboutRow(l10n.get('version'), 'v1.0.0 (Build 20260601)'),
  195. const Divider(height: 24),
  196. GestureDetector(
  197. onTap: () {
  198. Navigator.of(buildContext).pop();
  199. ScaffoldMessenger.of(context).showSnackBar(
  200. const SnackBar(content: Text('用户协议(占位)'), duration: Duration(seconds: 2)),
  201. );
  202. },
  203. child: const Text('用户协议',
  204. style: TextStyle(fontSize: 14, color: AppColors.primary)),
  205. ),
  206. const SizedBox(height: 12),
  207. GestureDetector(
  208. onTap: () {
  209. Navigator.of(buildContext).pop();
  210. ScaffoldMessenger.of(context).showSnackBar(
  211. const SnackBar(content: Text('隐私政策(占位)'), duration: Duration(seconds: 2)),
  212. );
  213. },
  214. child: const Text('隐私政策',
  215. style: TextStyle(fontSize: 14, color: AppColors.primary)),
  216. ),
  217. ],
  218. ),
  219. buttonStyle: TDDialogButtonStyle.text,
  220. buttonText: l10n.get('close'),
  221. buttonTextColor: AppColors.primary,
  222. action: () => Navigator.of(buildContext).pop(),
  223. );
  224. },
  225. );
  226. }
  227. Widget _aboutRow(String label, String value) {
  228. return Row(
  229. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  230. children: [
  231. Text(label,
  232. style: const TextStyle(
  233. fontSize: 14, color: AppColors.textSecondary)),
  234. Flexible(
  235. child: Text(value,
  236. textAlign: TextAlign.right,
  237. softWrap: true,
  238. style: const TextStyle(
  239. fontSize: 14, color: AppColors.textPrimary)),
  240. ),
  241. ],
  242. );
  243. }
  244. }