profile.dart 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import 'package:chicken_farm/stores/auth_store.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_riverpod/flutter_riverpod.dart';
  4. import 'package:getwidget/getwidget.dart';
  5. class ProfilePage extends ConsumerWidget {
  6. const ProfilePage({super.key});
  7. @override
  8. Widget build(BuildContext context, WidgetRef ref) {
  9. final authState = ref.watch(authStoreProvider);
  10. final authStore = ref.read(authStoreProvider.notifier);
  11. return Scaffold(
  12. body: Padding(
  13. padding: const EdgeInsets.all(16.0),
  14. child: Column(
  15. crossAxisAlignment: CrossAxisAlignment.start,
  16. children: [
  17. const SizedBox(height: 20),
  18. if (authState.state == AuthState.authenticated &&
  19. authState.user != null) ...[
  20. Card(
  21. child: Padding(
  22. padding: const EdgeInsets.all(16.0),
  23. child: Column(
  24. crossAxisAlignment: CrossAxisAlignment.start,
  25. children: [
  26. ListTile(
  27. leading: const CircleAvatar(
  28. radius: 30,
  29. child: Icon(Icons.person, size: 30),
  30. ),
  31. title: Text(
  32. authState.user!.nickName ?? '未设置昵称',
  33. style: const TextStyle(
  34. fontSize: 20,
  35. fontWeight: FontWeight.bold,
  36. ),
  37. ),
  38. subtitle: Text('用户名: ${authState.user!.userName}'),
  39. ),
  40. const Divider(),
  41. const Text(
  42. '基本信息',
  43. style: TextStyle(fontWeight: FontWeight.bold),
  44. ),
  45. const SizedBox(height: 10),
  46. _buildInfoRow(
  47. '手机号码',
  48. authState.user!.phonenumber ?? '未填写',
  49. ),
  50. _buildInfoRow('邮箱地址', authState.user!.email ?? '未填写'),
  51. _buildInfoRow('部门', authState.user!.orgName ?? '未分配'),
  52. _buildInfoRow(
  53. '角色',
  54. (authState.user!.roles
  55. ?.map((r) => r.roleName)
  56. .join(', ')) ??
  57. '未分配',
  58. ),
  59. ],
  60. ),
  61. ),
  62. ),
  63. const SizedBox(height: 20),
  64. SizedBox(
  65. width: double.infinity,
  66. child: ElevatedButton.icon(
  67. onPressed: () => authStore.logout(),
  68. icon: const Icon(Icons.logout),
  69. label: const Text('退出登录'),
  70. style: ElevatedButton.styleFrom(
  71. padding: const EdgeInsets.symmetric(
  72. horizontal: 30,
  73. vertical: 15,
  74. ),
  75. textStyle: const TextStyle(fontSize: 16),
  76. ),
  77. ),
  78. ),
  79. ] else ...[
  80. const Center(child: Text('加载中...')),
  81. ],
  82. ],
  83. ),
  84. ),
  85. );
  86. }
  87. Widget _buildInfoRow(String label, String value) {
  88. return Padding(
  89. padding: const EdgeInsets.symmetric(vertical: 4.0),
  90. child: Row(
  91. children: [
  92. SizedBox(
  93. width: 80,
  94. child: Text(
  95. '$label:',
  96. style: const TextStyle(fontWeight: FontWeight.w500),
  97. ),
  98. ),
  99. Expanded(child: Text(value)),
  100. ],
  101. ),
  102. );
  103. }
  104. }