Profile_edit_page.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. import 'package:cpt_profile/modules/profile_edit/profile_edit_state.dart';
  2. import 'package:cpt_profile/modules/profile_edit/profile_edit_view_model.dart';
  3. import 'package:cpt_profile/router/page/profile_page_router.dart';
  4. import 'package:cs_resources/generated/assets.dart';
  5. import 'package:cs_resources/generated/l10n.dart';
  6. import 'package:cs_resources/theme/app_colors_theme.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:auto_route/auto_route.dart';
  9. import 'package:hooks_riverpod/hooks_riverpod.dart';
  10. import 'package:router/ext/auto_router_extensions.dart';
  11. import 'package:widgets/ext/ex_widget.dart';
  12. import 'package:widgets/my_appbar.dart';
  13. import 'package:widgets/my_button.dart';
  14. import 'package:widgets/my_load_image.dart';
  15. import 'package:widgets/my_text_field.dart';
  16. import 'package:widgets/my_text_view.dart';
  17. import 'package:widgets/widget_export.dart';
  18. @RoutePage()
  19. class ProfileEditPage extends HookConsumerWidget {
  20. const ProfileEditPage({Key? key}) : super(key: key);
  21. //启动当前页面
  22. static void startInstance({BuildContext? context}) {
  23. if (context != null) {
  24. context.router.push(const ProfileEditPageRoute());
  25. } else {
  26. appRouter.push(const ProfileEditPageRoute());
  27. }
  28. }
  29. @override
  30. Widget build(BuildContext context, WidgetRef ref) {
  31. final viewModel = ref.watch(profileEditViewModelProvider.notifier);
  32. final state = ref.watch(profileEditViewModelProvider);
  33. return Scaffold(
  34. appBar: MyAppBar.appBar(context, S.current.edit_profile,backgroundColor: context.appColors.whiteBG),
  35. backgroundColor: context.appColors.backgroundDefault,
  36. body: SingleChildScrollView(
  37. scrollDirection: Axis.vertical,
  38. physics: const BouncingScrollPhysics(),
  39. child: Container(
  40. margin: const EdgeInsets.symmetric(horizontal: 15),
  41. width: double.infinity,
  42. child: Column(
  43. mainAxisSize: MainAxisSize.max,
  44. crossAxisAlignment: CrossAxisAlignment.start,
  45. children: [
  46. Center(
  47. child: Container(
  48. width: 80,
  49. height: 80,
  50. decoration: BoxDecoration(color: context.appColors.avatarBg, shape: BoxShape.circle),
  51. child: Stack(
  52. children: [
  53. //默认的占位图
  54. Visibility(
  55. visible: true,
  56. child: const Align(
  57. alignment: Alignment.bottomCenter,
  58. child: MyAssetImage(
  59. Assets.profileEditProfileAvatarDefault,
  60. width: 49,
  61. height: 64,
  62. ),
  63. ),
  64. ),
  65. //用户的头像
  66. Visibility(
  67. visible: false,
  68. child: MyLoadImage(
  69. "https://img1.baidu.com/it/u=1656098746,3560654086&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=800",
  70. width: 80,
  71. height: 80,
  72. isCircle: true,
  73. ),
  74. ),
  75. //底部的背景色
  76. const Align(
  77. alignment: Alignment.bottomCenter,
  78. child: MyAssetImage(
  79. Assets.profileEditProfileAvatarBottom,
  80. width: 71,
  81. height: 21.5,
  82. ),
  83. ),
  84. //照相机Icon
  85. const Align(
  86. alignment: Alignment.bottomCenter,
  87. child: MyAssetImage(
  88. Assets.profileEditProfileAdd,
  89. width: 12,
  90. height: 11.5,
  91. ),
  92. ).marginOnly(bottom: 4),
  93. ],
  94. ),
  95. ).onTap((){
  96. viewModel.showAvatarEditDialog(context);
  97. }),
  98. ).marginOnly(top: 23),
  99. // 表单 - 名
  100. MyTextView(
  101. S.current.first_name,
  102. fontSize: 17,
  103. marginTop: 33,
  104. marginBottom: 16,
  105. isFontMedium: true,
  106. textColor: context.appColors.textBlack,
  107. ),
  108. //表单
  109. _buildInputLayout(
  110. context,
  111. state,
  112. "first_name",
  113. textInputType: TextInputType.text,
  114. textInputAction: TextInputAction.next,
  115. onSubmit: (formKey, value) {
  116. state.formData[formKey]!['focusNode'].unfocus();
  117. FocusScope.of(context).requestFocus(state.formData['last_name']!['focusNode']);
  118. },
  119. ),
  120. // 表单 - 姓
  121. MyTextView(
  122. S.current.last_name,
  123. fontSize: 17,
  124. marginTop: 15,
  125. marginBottom: 16,
  126. isFontMedium: true,
  127. textColor: context.appColors.textBlack,
  128. ),
  129. //表单
  130. _buildInputLayout(
  131. context,
  132. state,
  133. "last_name",
  134. textInputType: TextInputType.text,
  135. textInputAction: TextInputAction.next,
  136. onSubmit: (formKey, value) {
  137. state.formData[formKey]!['focusNode'].unfocus();
  138. FocusScope.of(context).requestFocus(state.formData['email']!['focusNode']);
  139. },
  140. ),
  141. // 表单 - 邮箱
  142. MyTextView(
  143. S.current.email,
  144. fontSize: 17,
  145. marginTop: 15,
  146. marginBottom: 16,
  147. isFontMedium: true,
  148. textColor: context.appColors.textBlack,
  149. ),
  150. //表单
  151. _buildInputLayout(
  152. context,
  153. state,
  154. "email",
  155. textInputType: TextInputType.emailAddress,
  156. textInputAction: TextInputAction.next,
  157. onSubmit: (formKey, value) {
  158. state.formData[formKey]!['focusNode'].unfocus();
  159. },
  160. ),
  161. //提交
  162. MyButton(
  163. onPressed: viewModel.submitEdit,
  164. text: S.current.submit,
  165. textColor: Colors.white,
  166. backgroundColor: context.appColors.btnBgDefault,
  167. fontWeight: FontWeight.w500,
  168. type: ClickType.throttle,
  169. fontSize: 16,
  170. minHeight: 50,
  171. radius: 5,
  172. ).marginOnly(top: 50, bottom: 50),
  173. ],
  174. ),
  175. ),
  176. ),
  177. );
  178. }
  179. /// 输入框
  180. Widget _buildInputLayout(
  181. BuildContext context,
  182. ProfileEditState state,
  183. String key, {
  184. double marginTop = 0,
  185. bool? showRightIcon = false, //是否展示右侧的布局
  186. Widget? rightWidget, //右侧的布局
  187. TextInputType textInputType = TextInputType.text,
  188. String? errorText,
  189. bool obscureText = false,
  190. TextInputAction textInputAction = TextInputAction.done,
  191. Function? onSubmit,
  192. }) {
  193. return IgnoreKeyboardDismiss(
  194. child: MyTextField(
  195. key,
  196. fillBackgroundColor: context.appColors.authFiledBG,
  197. state.formData[key]!['value'],
  198. hintText: state.formData[key]!['hintText'],
  199. hintStyle: TextStyle(
  200. color: context.appColors.authFiledHint,
  201. fontSize: 16.0,
  202. fontWeight: FontWeight.w500,
  203. ),
  204. controller: state.formData[key]!['controller'],
  205. focusNode: state.formData[key]!['focusNode'],
  206. margin: EdgeInsets.only(top: marginTop),
  207. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  208. showDivider: false,
  209. height: 44,
  210. style: TextStyle(
  211. color: context.appColors.authFiledText,
  212. fontSize: 16.0,
  213. fontWeight: FontWeight.w500,
  214. ),
  215. inputType: textInputType,
  216. textInputAction: textInputAction,
  217. onSubmit: onSubmit,
  218. cursorColor: context.appColors.authFiledText,
  219. obscureText: obscureText,
  220. errorText: errorText,
  221. showLeftIcon: true,
  222. showRightIcon: showRightIcon,
  223. rightWidget: rightWidget,
  224. ),
  225. );
  226. }
  227. }