import 'package:cpt_profile/modules/change_mobile/change_mobile_state.dart'; import 'package:cs_resources/generated/assets.dart'; import 'package:cs_resources/generated/l10n.dart'; import 'package:cs_resources/theme/app_colors_theme.dart'; import 'package:flutter/material.dart'; import 'package:auto_route/auto_route.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:router/ext/auto_router_extensions.dart'; import 'package:widgets/ext/ex_widget.dart'; import 'package:widgets/my_appbar.dart'; import 'package:widgets/my_button.dart'; import 'package:widgets/my_load_image.dart'; import 'package:widgets/my_text_field.dart'; import 'package:widgets/my_text_view.dart'; import 'package:widgets/widget_export.dart'; import '../../router/page/profile_page_router.dart'; import 'change_mobile_view_model.dart'; @RoutePage() class ChangeMobilePage extends HookConsumerWidget { const ChangeMobilePage({Key? key}) : super(key: key); //启动当前页面 static void startInstance({BuildContext? context}) { if (context != null) { context.router.push(const ChangeMobilePageRoute()); } else { appRouter.push(const ChangeMobilePageRoute()); } } @override Widget build(BuildContext context, WidgetRef ref) { final viewModel = ref.watch(changeMobileViewModelProvider.notifier); final state = ref.watch(changeMobileViewModelProvider); return Scaffold( appBar: MyAppBar.appBar(context, S.current.change_mobile_phone), backgroundColor: context.appColors.backgroundDefault, body: SingleChildScrollView( scrollDirection: Axis.vertical, physics: const BouncingScrollPhysics(), child: Container( margin: const EdgeInsets.symmetric(horizontal: 15), width: double.infinity, child: Column( mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.start, children: [ //旧手机 MyTextView( S.current.old_mobile_phone, fontSize: 16.5, marginTop: 38, marginBottom: 15, isFontMedium: true, textColor: context.appColors.textBlack, ), //旧的电话号码 Row( mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center, children: [ const MyAssetImage( Assets.authCountrySg, width: 45, height: 30, ), MyTextView( "+65", textColor: context.appColors.textBlack, fontSize: 18.5, marginLeft: 15, marginRight: 12, isFontMedium: true, ), //电话输入框 _buildInputLayout( context, state, "old", textInputType: TextInputType.number, textInputAction: TextInputAction.next, onSubmit: (formKey, value) { state.formData[formKey]!['focusNode'].unfocus(); FocusScope.of(context).requestFocus(state.formData['old_code']!['focusNode']); }, ).expanded(), ], ), //旧手机的验证码 MyTextView( S.current.verification_code, fontSize: 16.5, marginTop: 13, marginBottom: 15, isFontMedium: true, textColor: context.appColors.textBlack, ), // 表单 - 旧的电话号码验证码 _buildInputLayout( context, state, "old_code", textInputType: TextInputType.number, textInputAction: TextInputAction.next, errorText: state.oldCodeErrorText, showRightIcon: true, rightWidget: MyTextView( state.isOldCounting ? "${state.oldCountdownTime} s" : S.current.get_code, textAlign: TextAlign.center, textColor: context.appColors.textPrimary, fontSize: 15, paddingRight: 5, isFontMedium: true, onClick: state.isOldCounting ? null : () => viewModel.showVerifyCodedDialog(false), ).paddingOnly(top: 15, bottom: 15), onSubmit: (formKey, value) { state.formData[formKey]!['focusNode'].unfocus(); FocusScope.of(context).requestFocus(state.formData['new']!['focusNode']); }, ), //新电话 MyTextView( S.current.new_mobile_phone, fontSize: 16.5, marginTop: 38, marginBottom: 15, isFontMedium: true, textColor: context.appColors.textBlack, ), //新的电话号码 Row( mainAxisSize: MainAxisSize.max, crossAxisAlignment: CrossAxisAlignment.center, children: [ const MyAssetImage( Assets.authCountrySg, width: 45, height: 30, ), MyTextView( "+65", textColor: context.appColors.textBlack, fontSize: 18.5, marginLeft: 15, marginRight: 12, isFontMedium: true, ), //电话输入框 _buildInputLayout( context, state, "new", textInputType: TextInputType.number, textInputAction: TextInputAction.next, onSubmit: (formKey, value) { state.formData[formKey]!['focusNode'].unfocus(); FocusScope.of(context).requestFocus(state.formData['new_code']!['focusNode']); }, ).expanded(), ], ), //新手机的验证码 MyTextView( S.current.verification_code, fontSize: 16.5, marginTop: 13, marginBottom: 15, isFontMedium: true, textColor: context.appColors.textBlack, ), // 表单 - 新的电话号码验证码 _buildInputLayout( context, state, "new_code", textInputType: TextInputType.number, textInputAction: TextInputAction.done, errorText: state.newCodeErrorText, showRightIcon: true, rightWidget: MyTextView( state.isNewCounting ? "${state.newCountdownTime} s" : S.current.get_code, textAlign: TextAlign.center, textColor: context.appColors.textPrimary, fontSize: 15, paddingRight: 5, isFontMedium: true, onClick: state.isNewCounting ? null : () => viewModel.showVerifyCodedDialog(true), ).paddingOnly(top: 15, bottom: 15), onSubmit: (formKey, value) { state.formData[formKey]!['focusNode'].unfocus(); viewModel.submitChangeMobile(); }, ), //提交按钮 MyButton( onPressed: viewModel.submitChangeMobile, text: S.current.submit, textColor: Colors.white, backgroundColor: context.appColors.btnBgDefault, fontWeight: FontWeight.w500, type: ClickType.throttle, fontSize: 16, minHeight: 50, radius: 5, ).marginOnly(top: 50, bottom: 30), ], ), ), ), ); } /// 输入框 Widget _buildInputLayout( BuildContext context, ChangeMobileState state, String key, { double marginTop = 0, bool? showRightIcon = false, //是否展示右侧的布局 Widget? rightWidget, //右侧的布局 TextInputType textInputType = TextInputType.text, String? errorText, bool obscureText = false, TextInputAction textInputAction = TextInputAction.done, Function? onSubmit, }) { return IgnoreKeyboardDismiss( child: MyTextField( key, fillBackgroundColor: context.appColors.authFiledBG, state.formData[key]!['value'], hintText: state.formData[key]!['hintText'], hintStyle: TextStyle( color: context.appColors.authFiledHint, fontSize: 15.0, fontWeight: FontWeight.w500, ), controller: state.formData[key]!['controller'], focusNode: state.formData[key]!['focusNode'], margin: EdgeInsets.only(top: marginTop), padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3), showDivider: false, height: 44, style: TextStyle( color: context.appColors.authFiledText, fontSize: 15.0, fontWeight: FontWeight.w500, ), inputType: textInputType, textInputAction: textInputAction, onSubmit: onSubmit, cursorColor: context.appColors.authFiledText, obscureText: obscureText, errorText: errorText, showLeftIcon: true, showRightIcon: showRightIcon, rightWidget: rightWidget, ), ); } }