change_mobile_page.dart 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import 'package:cpt_profile/modules/change_mobile/change_mobile_state.dart';
  2. import 'package:cs_resources/generated/assets.dart';
  3. import 'package:cs_resources/generated/l10n.dart';
  4. import 'package:cs_resources/theme/app_colors_theme.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:router/ext/auto_router_extensions.dart';
  9. import 'package:widgets/ext/ex_widget.dart';
  10. import 'package:widgets/my_appbar.dart';
  11. import 'package:widgets/my_button.dart';
  12. import 'package:widgets/my_load_image.dart';
  13. import 'package:widgets/my_text_field.dart';
  14. import 'package:widgets/my_text_view.dart';
  15. import 'package:widgets/widget_export.dart';
  16. import '../../router/page/profile_page_router.dart';
  17. import 'change_mobile_view_model.dart';
  18. @RoutePage()
  19. class ChangeMobilePage extends HookConsumerWidget {
  20. const ChangeMobilePage({Key? key}) : super(key: key);
  21. //启动当前页面
  22. static void startInstance({BuildContext? context}) {
  23. if (context != null) {
  24. context.router.push(const ChangeMobilePageRoute());
  25. } else {
  26. appRouter.push(const ChangeMobilePageRoute());
  27. }
  28. }
  29. @override
  30. Widget build(BuildContext context, WidgetRef ref) {
  31. final viewModel = ref.watch(changeMobileViewModelProvider.notifier);
  32. final state = ref.watch(changeMobileViewModelProvider);
  33. return Scaffold(
  34. appBar: MyAppBar.appBar(context, S.current.change_mobile_phone),
  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. //旧手机
  47. MyTextView(
  48. S.current.old_mobile_phone,
  49. fontSize: 16.5,
  50. marginTop: 38,
  51. marginBottom: 15,
  52. isFontMedium: true,
  53. textColor: context.appColors.textBlack,
  54. ),
  55. //旧的电话号码
  56. Row(
  57. mainAxisSize: MainAxisSize.max,
  58. crossAxisAlignment: CrossAxisAlignment.center,
  59. children: [
  60. const MyAssetImage(
  61. Assets.authCountrySg,
  62. width: 45,
  63. height: 30,
  64. ),
  65. MyTextView(
  66. "+65",
  67. textColor: context.appColors.textBlack,
  68. fontSize: 18.5,
  69. marginLeft: 15,
  70. marginRight: 12,
  71. isFontMedium: true,
  72. ),
  73. //电话输入框
  74. _buildInputLayout(
  75. context,
  76. state,
  77. "old",
  78. textInputType: TextInputType.number,
  79. textInputAction: TextInputAction.next,
  80. onSubmit: (formKey, value) {
  81. state.formData[formKey]!['focusNode'].unfocus();
  82. FocusScope.of(context).requestFocus(state.formData['old_code']!['focusNode']);
  83. },
  84. ).expanded(),
  85. ],
  86. ),
  87. //旧手机的验证码
  88. MyTextView(
  89. S.current.verification_code,
  90. fontSize: 16.5,
  91. marginTop: 13,
  92. marginBottom: 15,
  93. isFontMedium: true,
  94. textColor: context.appColors.textBlack,
  95. ),
  96. // 表单 - 旧的电话号码验证码
  97. _buildInputLayout(
  98. context,
  99. state,
  100. "old_code",
  101. textInputType: TextInputType.number,
  102. textInputAction: TextInputAction.next,
  103. errorText: state.oldCodeErrorText,
  104. showRightIcon: true,
  105. rightWidget: MyTextView(
  106. state.isOldCounting ? "${state.oldCountdownTime} s" : S.current.get_code,
  107. textAlign: TextAlign.center,
  108. textColor: context.appColors.textPrimary,
  109. fontSize: 15,
  110. paddingRight: 5,
  111. isFontMedium: true,
  112. onClick: state.isOldCounting ? null : () => viewModel.showVerifyCodedDialog(false),
  113. ).paddingOnly(top: 15, bottom: 15),
  114. onSubmit: (formKey, value) {
  115. state.formData[formKey]!['focusNode'].unfocus();
  116. FocusScope.of(context).requestFocus(state.formData['new']!['focusNode']);
  117. },
  118. ),
  119. //新电话
  120. MyTextView(
  121. S.current.new_mobile_phone,
  122. fontSize: 16.5,
  123. marginTop: 38,
  124. marginBottom: 15,
  125. isFontMedium: true,
  126. textColor: context.appColors.textBlack,
  127. ),
  128. //新的电话号码
  129. Row(
  130. mainAxisSize: MainAxisSize.max,
  131. crossAxisAlignment: CrossAxisAlignment.center,
  132. children: [
  133. const MyAssetImage(
  134. Assets.authCountrySg,
  135. width: 45,
  136. height: 30,
  137. ),
  138. MyTextView(
  139. "+65",
  140. textColor: context.appColors.textBlack,
  141. fontSize: 18.5,
  142. marginLeft: 15,
  143. marginRight: 12,
  144. isFontMedium: true,
  145. ),
  146. //电话输入框
  147. _buildInputLayout(
  148. context,
  149. state,
  150. "new",
  151. textInputType: TextInputType.number,
  152. textInputAction: TextInputAction.next,
  153. onSubmit: (formKey, value) {
  154. state.formData[formKey]!['focusNode'].unfocus();
  155. FocusScope.of(context).requestFocus(state.formData['new_code']!['focusNode']);
  156. },
  157. ).expanded(),
  158. ],
  159. ),
  160. //新手机的验证码
  161. MyTextView(
  162. S.current.verification_code,
  163. fontSize: 16.5,
  164. marginTop: 13,
  165. marginBottom: 15,
  166. isFontMedium: true,
  167. textColor: context.appColors.textBlack,
  168. ),
  169. // 表单 - 新的电话号码验证码
  170. _buildInputLayout(
  171. context,
  172. state,
  173. "new_code",
  174. textInputType: TextInputType.number,
  175. textInputAction: TextInputAction.done,
  176. errorText: state.newCodeErrorText,
  177. showRightIcon: true,
  178. rightWidget: MyTextView(
  179. state.isNewCounting ? "${state.newCountdownTime} s" : S.current.get_code,
  180. textAlign: TextAlign.center,
  181. textColor: context.appColors.textPrimary,
  182. fontSize: 15,
  183. paddingRight: 5,
  184. isFontMedium: true,
  185. onClick: state.isNewCounting ? null : () => viewModel.showVerifyCodedDialog(true),
  186. ).paddingOnly(top: 15, bottom: 15),
  187. onSubmit: (formKey, value) {
  188. state.formData[formKey]!['focusNode'].unfocus();
  189. viewModel.submitChangeMobile();
  190. },
  191. ),
  192. //提交按钮
  193. MyButton(
  194. onPressed: viewModel.submitChangeMobile,
  195. text: S.current.submit,
  196. textColor: Colors.white,
  197. backgroundColor: context.appColors.btnBgDefault,
  198. fontWeight: FontWeight.w500,
  199. type: ClickType.throttle,
  200. fontSize: 16,
  201. minHeight: 50,
  202. radius: 5,
  203. ).marginOnly(top: 50, bottom: 30),
  204. ],
  205. ),
  206. ),
  207. ),
  208. );
  209. }
  210. /// 输入框
  211. Widget _buildInputLayout(
  212. BuildContext context,
  213. ChangeMobileState state,
  214. String key, {
  215. double marginTop = 0,
  216. bool? showRightIcon = false, //是否展示右侧的布局
  217. Widget? rightWidget, //右侧的布局
  218. TextInputType textInputType = TextInputType.text,
  219. String? errorText,
  220. bool obscureText = false,
  221. TextInputAction textInputAction = TextInputAction.done,
  222. Function? onSubmit,
  223. }) {
  224. return IgnoreKeyboardDismiss(
  225. child: MyTextField(
  226. key,
  227. fillBackgroundColor: context.appColors.authFiledBG,
  228. state.formData[key]!['value'],
  229. hintText: state.formData[key]!['hintText'],
  230. hintStyle: TextStyle(
  231. color: context.appColors.authFiledHint,
  232. fontSize: 15.0,
  233. fontWeight: FontWeight.w500,
  234. ),
  235. controller: state.formData[key]!['controller'],
  236. focusNode: state.formData[key]!['focusNode'],
  237. margin: EdgeInsets.only(top: marginTop),
  238. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  239. showDivider: false,
  240. height: 44,
  241. style: TextStyle(
  242. color: context.appColors.authFiledText,
  243. fontSize: 15.0,
  244. fontWeight: FontWeight.w500,
  245. ),
  246. inputType: textInputType,
  247. textInputAction: textInputAction,
  248. onSubmit: onSubmit,
  249. cursorColor: context.appColors.authFiledText,
  250. obscureText: obscureText,
  251. errorText: errorText,
  252. showLeftIcon: true,
  253. showRightIcon: showRightIcon,
  254. rightWidget: rightWidget,
  255. ),
  256. );
  257. }
  258. }