change_mobile_page.dart 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. enable: false,
  79. textInputType: TextInputType.number,
  80. textInputAction: TextInputAction.next,
  81. onSubmit: (formKey, value) {
  82. state.formData[formKey]!['focusNode'].unfocus();
  83. FocusScope.of(context).requestFocus(state.formData['old_code']!['focusNode']);
  84. },
  85. ).expanded(),
  86. ],
  87. ),
  88. //新电话
  89. MyTextView(
  90. S.current.new_mobile_phone,
  91. fontSize: 16.5,
  92. marginTop: 14.5,
  93. marginBottom: 15,
  94. isFontMedium: true,
  95. textColor: context.appColors.textBlack,
  96. ),
  97. //新的电话号码
  98. Row(
  99. mainAxisSize: MainAxisSize.max,
  100. crossAxisAlignment: CrossAxisAlignment.center,
  101. children: [
  102. const MyAssetImage(
  103. Assets.authCountrySg,
  104. width: 45,
  105. height: 30,
  106. ),
  107. MyTextView(
  108. "+65",
  109. textColor: context.appColors.textBlack,
  110. fontSize: 18.5,
  111. marginLeft: 15,
  112. marginRight: 12,
  113. isFontMedium: true,
  114. ),
  115. //电话输入框
  116. _buildInputLayout(
  117. context,
  118. state,
  119. "new",
  120. textInputType: TextInputType.number,
  121. textInputAction: TextInputAction.next,
  122. onSubmit: (formKey, value) {
  123. state.formData[formKey]!['focusNode'].unfocus();
  124. FocusScope.of(context).requestFocus(state.formData['new_code']!['focusNode']);
  125. },
  126. ).expanded(),
  127. ],
  128. ),
  129. //新手机的验证码
  130. MyTextView(
  131. S.current.verification_code,
  132. fontSize: 16.5,
  133. marginTop: 14,
  134. marginBottom: 15,
  135. isFontMedium: true,
  136. textColor: context.appColors.textBlack,
  137. ),
  138. // 表单 - 新的电话号码验证码
  139. _buildInputLayout(
  140. context,
  141. state,
  142. "new_code",
  143. textInputType: TextInputType.number,
  144. textInputAction: TextInputAction.done,
  145. errorText: state.newCodeErrorText,
  146. showRightIcon: true,
  147. rightWidget: MyTextView(
  148. state.isNewCounting ? "${state.newCountdownTime} s" : S.current.get_code,
  149. textAlign: TextAlign.center,
  150. textColor: context.appColors.textPrimary,
  151. fontSize: 15,
  152. paddingRight: 5,
  153. isFontMedium: true,
  154. onClick: state.isNewCounting ? null : () => viewModel.showVerifyCodedDialog(),
  155. ).paddingOnly(top: 15, bottom: 15),
  156. onSubmit: (formKey, value) {
  157. state.formData[formKey]!['focusNode'].unfocus();
  158. viewModel.submitChangeMobile();
  159. },
  160. ),
  161. //提交按钮
  162. MyButton(
  163. onPressed: viewModel.submitChangeMobile,
  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: 30),
  173. ],
  174. ),
  175. ),
  176. ),
  177. );
  178. }
  179. /// 输入框
  180. Widget _buildInputLayout(
  181. BuildContext context,
  182. ChangeMobileState 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. bool enable = true,
  191. TextInputAction textInputAction = TextInputAction.done,
  192. Function? onSubmit,
  193. }) {
  194. return IgnoreKeyboardDismiss(
  195. child: MyTextField(
  196. key,
  197. fillBackgroundColor: context.appColors.authFiledBG,
  198. state.formData[key]!['value'],
  199. hintText: state.formData[key]!['hintText'],
  200. hintStyle: TextStyle(
  201. color: context.appColors.authFiledHint,
  202. fontSize: 15.0,
  203. fontWeight: FontWeight.w500,
  204. ),
  205. enabled: enable,
  206. controller: state.formData[key]!['controller'],
  207. focusNode: state.formData[key]!['focusNode'],
  208. margin: EdgeInsets.only(top: marginTop),
  209. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  210. showDivider: false,
  211. height: 44,
  212. style: TextStyle(
  213. color: context.appColors.authFiledText,
  214. fontSize: 15.0,
  215. fontWeight: FontWeight.w500,
  216. ),
  217. inputType: textInputType,
  218. textInputAction: textInputAction,
  219. onSubmit: onSubmit,
  220. cursorColor: context.appColors.authFiledText,
  221. obscureText: obscureText,
  222. errorText: errorText,
  223. showLeftIcon: true,
  224. showRightIcon: showRightIcon,
  225. rightWidget: rightWidget,
  226. ),
  227. );
  228. }
  229. }