me_page.dart 7.6 KB

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