me_page.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. import 'package:cs_resources/generated/assets.dart';
  2. import 'package:cs_resources/generated/l10n.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:cs_resources/theme/theme_config.dart';
  5. import 'package:flutter/material.dart';
  6. import 'package:auto_route/auto_route.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:plugin_basic/provider/user_config/user_config_service.dart';
  9. import 'package:widgets/ext/ex_widget.dart';
  10. import 'package:widgets/my_appbar.dart';
  11. import 'package:widgets/my_load_image.dart';
  12. import 'package:widgets/my_text_view.dart';
  13. import 'package:widgets/shatter/setting_item_container.dart';
  14. import 'package:widgets/widget_export.dart';
  15. import 'me_view_model.dart';
  16. @RoutePage()
  17. class MePage extends HookConsumerWidget {
  18. const MePage({Key? key}) : super(key: key);
  19. @override
  20. Widget build(BuildContext context, WidgetRef ref) {
  21. final viewModel = ref.watch(meViewModelProvider.notifier);
  22. final userConfig = UserConfigService.getState(ref: ref);
  23. return Scaffold(
  24. appBar: MyAppBar.appBar(
  25. context,
  26. "",
  27. showBackButton: false,
  28. backgroundColor: context.appColors.btnBgDefault,
  29. systemUiOverlayStyle: MediaQuery.of(context).platformBrightness == Brightness.dark
  30. ? ThemeConfig.systemUiOverlayStyleDarkTheme
  31. : ThemeConfig.systemUiOverlayStyleLightThemeWhite,
  32. ),
  33. backgroundColor: context.appColors.backgroundDark,
  34. body: EasyRefresh(
  35. controller: viewModel.refreshController,
  36. header: const MaterialHeader(),
  37. onRefresh: viewModel.onRefresh,
  38. child: SingleChildScrollView(
  39. scrollDirection: Axis.vertical,
  40. child: SizedBox(
  41. width: double.infinity,
  42. child: Column(
  43. mainAxisSize: MainAxisSize.max,
  44. crossAxisAlignment: CrossAxisAlignment.center,
  45. children: [
  46. //顶部信息
  47. _buildTopProfile(context, ref),
  48. //关注与粉丝
  49. _buildFollower(context, ref),
  50. //我的发布
  51. SettingItemContainer(
  52. title: S.current.my_post,
  53. iconPath: Assets.mainMeMyPostIcon,
  54. isShowMoreIcon: true,
  55. rightWidget: MyTextView(
  56. userConfig.user?.postsCount ?? "0",
  57. textColor: context.appColors.textPrimary,
  58. fontSize: 20,
  59. isFontMedium: true,
  60. ),
  61. ).onTap(viewModel.gotoMyPostPage).marginOnly(top: 10),
  62. //家庭
  63. SettingItemContainer(
  64. title: S.current.household,
  65. iconPath: Assets.mainMeHouseholdIcon,
  66. isShowMoreIcon: true,
  67. rightWidget: MyTextView(
  68. userConfig.user?.households?.length.toString() ?? "0",
  69. textColor: context.appColors.textPrimary,
  70. fontSize: 20,
  71. isFontMedium: true,
  72. ),
  73. ).onTap(viewModel.gotoMyHouseholdPage),
  74. //房产
  75. SettingItemContainer(
  76. title: S.current.estate,
  77. iconPath: Assets.mainMeEstateIcon,
  78. isShowMoreIcon: true,
  79. rightWidget: MyTextView(
  80. userConfig.user?.estates?.fold(0, (sum, estate) {
  81. return sum + (estate.accounts?.length ?? 0);
  82. }).toString() ?? "0",
  83. textColor: context.appColors.textPrimary,
  84. fontSize: 20,
  85. isFontMedium: true,
  86. ),
  87. ).onTap(viewModel.gotoMyEstatePage),
  88. //设置
  89. SettingItemContainer(
  90. title: S.current.settings,
  91. iconPath: Assets.mainMeSettingIcon,
  92. isShowMoreIcon: true,
  93. ).onTap(viewModel.gotoSettingPage),
  94. ],
  95. ),
  96. ),
  97. ),
  98. ),
  99. );
  100. }
  101. //编辑顶部的关注与粉丝数量
  102. Widget _buildFollower(BuildContext context, WidgetRef ref) {
  103. final viewModel = ref.watch(meViewModelProvider.notifier);
  104. final userConfig = UserConfigService.getState(ref: ref);
  105. return Container(
  106. color: context.appColors.whiteSecondBG,
  107. width: double.infinity,
  108. height: 50,
  109. child: Row(
  110. children: [
  111. //关注
  112. Row(
  113. mainAxisSize: MainAxisSize.min,
  114. mainAxisAlignment: MainAxisAlignment.center,
  115. crossAxisAlignment: CrossAxisAlignment.center,
  116. children: [
  117. MyTextView(
  118. S.current.following,
  119. isFontBold: true,
  120. fontSize: 16,
  121. textColor: context.appColors.textBlack,
  122. ),
  123. MyTextView(
  124. "(${userConfig.user?.followsCount ?? "0"})",
  125. isFontBold: true,
  126. fontSize: 16,
  127. textColor: context.appColors.textPrimary,
  128. ),
  129. ],
  130. ).onTap(viewModel.gotoFollowingPage).expanded(),
  131. Container(
  132. width: 0.5,
  133. height: 50,
  134. color: context.appColors.dividerDefault,
  135. ),
  136. //粉丝
  137. Row(
  138. mainAxisSize: MainAxisSize.min,
  139. mainAxisAlignment: MainAxisAlignment.center,
  140. crossAxisAlignment: CrossAxisAlignment.center,
  141. children: [
  142. MyTextView(
  143. S.current.followers,
  144. isFontBold: true,
  145. fontSize: 16,
  146. textColor: context.appColors.textBlack,
  147. ),
  148. MyTextView(
  149. "(${userConfig.user?.flowersCount ?? "0"})",
  150. isFontBold: true,
  151. fontSize: 16,
  152. textColor: context.appColors.textPrimary,
  153. ),
  154. ],
  155. ).onTap(viewModel.gotoFollowerPage).expanded(),
  156. ],
  157. ),
  158. );
  159. }
  160. // 编辑顶部的个人信息
  161. Widget _buildTopProfile(BuildContext context, WidgetRef ref) {
  162. final viewModel = ref.watch(meViewModelProvider.notifier);
  163. final userConfig = UserConfigService.getState(ref: ref);
  164. return Container(
  165. color: context.appColors.btnBgDefault,
  166. width: double.infinity,
  167. padding: const EdgeInsets.only(left: 26, right: 20, top: 5),
  168. height: 120,
  169. child: Row(
  170. mainAxisSize: MainAxisSize.max,
  171. crossAxisAlignment: CrossAxisAlignment.start,
  172. children: [
  173. MyLoadImage(
  174. userConfig.user?.avatar,
  175. width: 80,
  176. height: 80,
  177. isCircle: true,
  178. ),
  179. Column(
  180. mainAxisSize: MainAxisSize.min,
  181. mainAxisAlignment: MainAxisAlignment.start,
  182. crossAxisAlignment: CrossAxisAlignment.start,
  183. children: [
  184. Row(
  185. children: [
  186. MyTextView(
  187. userConfig.user?.name ?? "-",
  188. textColor: Colors.white,
  189. fontSize: 18,
  190. isFontMedium: true,
  191. ).expanded(),
  192. const MyAssetImage(
  193. Assets.mainMeEditIcon,
  194. width: 20.5,
  195. height: 20,
  196. ).onTap(viewModel.gotoEditProfilePage, padding: 5),
  197. ],
  198. ),
  199. //电话
  200. MyTextView(
  201. "+${userConfig.user?.phone ?? "-"}",
  202. textColor: Colors.white,
  203. fontSize: 15,
  204. isFontRegular: true,
  205. ),
  206. //住宅
  207. MyTextView(
  208. userConfig.user?.defaultUnit?.address ?? "-",
  209. marginTop: 12,
  210. textColor: Colors.white,
  211. fontSize: 15,
  212. isFontRegular: true,
  213. ),
  214. ],
  215. ).marginOnly(left: 11).expanded(),
  216. ],
  217. ),
  218. );
  219. }
  220. }