change_mobile_page.dart 8.7 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:plugin_basic/dialog/country_code_selecter.dart';
  9. import 'package:plugin_basic/provider/user_config/user_config_service.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. import '../../router/page/profile_page_router.dart';
  19. import 'change_mobile_view_model.dart';
  20. @RoutePage()
  21. class ChangeMobilePage extends HookConsumerWidget {
  22. const ChangeMobilePage({Key? key}) : super(key: key);
  23. //启动当前页面
  24. static void startInstance({BuildContext? context}) {
  25. if (context != null) {
  26. context.router.push(const ChangeMobilePageRoute());
  27. } else {
  28. appRouter.push(const ChangeMobilePageRoute());
  29. }
  30. }
  31. @override
  32. Widget build(BuildContext context, WidgetRef ref) {
  33. final viewModel = ref.watch(changeMobileViewModelProvider.notifier);
  34. final state = ref.watch(changeMobileViewModelProvider);
  35. return Scaffold(
  36. appBar: MyAppBar.appBar(context, S.current.change_mobile_phone),
  37. backgroundColor: context.appColors.backgroundDefault,
  38. body: SingleChildScrollView(
  39. scrollDirection: Axis.vertical,
  40. physics: const BouncingScrollPhysics(),
  41. child: Container(
  42. margin: const EdgeInsets.symmetric(horizontal: 15),
  43. width: double.infinity,
  44. child: Column(
  45. mainAxisSize: MainAxisSize.max,
  46. crossAxisAlignment: CrossAxisAlignment.start,
  47. children: [
  48. //旧手机
  49. MyTextView(
  50. S.current.old_mobile_phone,
  51. fontSize: 16.5,
  52. marginTop: 38,
  53. marginBottom: 15,
  54. isFontMedium: true,
  55. textColor: context.appColors.textBlack,
  56. ),
  57. //旧的电话号码
  58. Row(
  59. mainAxisSize: MainAxisSize.max,
  60. crossAxisAlignment: CrossAxisAlignment.center,
  61. children: [
  62. //封装的国家选择控件
  63. CountryCodeSelector(
  64. countryCode: UserConfigService.getState().user?.information?.countryCode ?? "+65",
  65. isEnable: false,
  66. onChanged: (countryCode) {},
  67. ).marginOnly(left: 15),
  68. //电话输入框
  69. _buildInputLayout(
  70. context,
  71. state,
  72. "old",
  73. enable: false,
  74. fillBGColor: Colors.transparent,
  75. textInputType: TextInputType.number,
  76. textInputAction: TextInputAction.done,
  77. onSubmit: (formKey, value) {
  78. state.formData[formKey]!['focusNode'].unfocus();
  79. FocusScope.of(context).requestFocus(state.formData['new']!['focusNode']);
  80. },
  81. ).expanded(),
  82. ],
  83. ).decorated(
  84. color: context.appColors.authFiledBG,
  85. borderRadius: BorderRadius.circular(5.0),
  86. ),
  87. //新电话
  88. MyTextView(
  89. S.current.new_mobile_phone,
  90. fontSize: 16.5,
  91. marginTop: 14.5,
  92. marginBottom: 15,
  93. isFontMedium: true,
  94. textColor: context.appColors.textBlack,
  95. ),
  96. //新的电话号码
  97. Row(
  98. mainAxisSize: MainAxisSize.max,
  99. crossAxisAlignment: CrossAxisAlignment.center,
  100. children: [
  101. //封装的国家选择控件
  102. CountryCodeSelector(
  103. margin: const EdgeInsets.only(left: 0, right: 0, top: 5),
  104. onChanged: (countryCode) {
  105. viewModel.saveNewCountryCode(countryCode);
  106. },
  107. ).marginOnly(left: 15),
  108. //电话输入框
  109. _buildInputLayout(
  110. context,
  111. state,
  112. "new",
  113. fillBGColor: Colors.transparent,
  114. textInputType: TextInputType.number,
  115. textInputAction: TextInputAction.done,
  116. onSubmit: (formKey, value) {
  117. state.formData[formKey]!['focusNode'].unfocus();
  118. FocusScope.of(context).requestFocus(state.formData['new_code']!['focusNode']);
  119. },
  120. ).expanded(),
  121. ],
  122. ).decorated(
  123. color: context.appColors.authFiledBG,
  124. borderRadius: BorderRadius.circular(5.0),
  125. ),
  126. //新手机的验证码
  127. MyTextView(
  128. S.current.verification_code,
  129. fontSize: 16.5,
  130. marginTop: 14,
  131. marginBottom: 15,
  132. isFontMedium: true,
  133. textColor: context.appColors.textBlack,
  134. ),
  135. // 表单 - 新的电话号码验证码
  136. _buildInputLayout(
  137. context,
  138. state,
  139. "new_code",
  140. textInputType: TextInputType.number,
  141. textInputAction: TextInputAction.done,
  142. errorText: state.newCodeErrorText,
  143. showRightIcon: true,
  144. rightWidget: MyTextView(
  145. state.isNewCounting ? "${state.newCountdownTime} s" : S.current.get_code,
  146. textAlign: TextAlign.center,
  147. textColor: context.appColors.textPrimary,
  148. fontSize: 15,
  149. paddingRight: 5,
  150. isFontMedium: true,
  151. onClick: state.isNewCounting ? null : () => viewModel.showVerifyCodedDialog(),
  152. ).paddingOnly(top: 15, bottom: 15),
  153. onSubmit: (formKey, value) {
  154. state.formData[formKey]!['focusNode'].unfocus();
  155. viewModel.submitChangeMobile();
  156. },
  157. ),
  158. //提交按钮
  159. MyButton(
  160. onPressed: viewModel.submitChangeMobile,
  161. text: S.current.submit,
  162. textColor: Colors.white,
  163. backgroundColor: context.appColors.btnBgDefault,
  164. fontWeight: FontWeight.w500,
  165. type: ClickType.throttle,
  166. fontSize: 16,
  167. minHeight: 50,
  168. radius: 5,
  169. ).marginOnly(top: 50, bottom: 30),
  170. ],
  171. ),
  172. ),
  173. ),
  174. );
  175. }
  176. /// 输入框
  177. Widget _buildInputLayout(
  178. BuildContext context,
  179. ChangeMobileState state,
  180. String key, {
  181. double marginTop = 0,
  182. bool? showRightIcon = false, //是否展示右侧的布局
  183. Widget? rightWidget, //右侧的布局
  184. TextInputType textInputType = TextInputType.text,
  185. String? errorText,
  186. bool obscureText = false,
  187. bool enable = true,
  188. Color? fillBGColor,
  189. TextInputAction textInputAction = TextInputAction.done,
  190. Function? onSubmit,
  191. }) {
  192. return IgnoreKeyboardDismiss(
  193. child: MyTextField(
  194. key,
  195. fillBackgroundColor: fillBGColor ?? context.appColors.authFiledBG,
  196. state.formData[key]!['value'],
  197. hintText: state.formData[key]!['hintText'],
  198. hintStyle: TextStyle(
  199. color: context.appColors.authFiledHint,
  200. fontSize: 15.0,
  201. fontWeight: FontWeight.w500,
  202. ),
  203. enabled: enable,
  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: 15.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. }