profile_page.dart 9.4 KB

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