add_card_page.dart 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import 'package:cpt_payment/modules/choose_card/choose_card_page.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_view.dart';
  14. import 'package:widgets/my_text_field.dart';
  15. import 'package:widgets/widget_export.dart';
  16. import '../../router/page/payment_page_router.dart';
  17. import 'add_card_state.dart';
  18. import 'add_card_view_model.dart';
  19. @RoutePage()
  20. class AddCardPage extends HookConsumerWidget {
  21. const AddCardPage({Key? key}) : super(key: key);
  22. //启动当前页面
  23. static void startInstance({BuildContext? context}) {
  24. if (context != null) {
  25. context.router.push(const AddCardPageRoute());
  26. } else {
  27. appRouter.push(const AddCardPageRoute());
  28. }
  29. }
  30. @override
  31. Widget build(BuildContext context, WidgetRef ref) {
  32. final viewModel = ref.read(addCardViewModelProvider.notifier);
  33. final state = ref.watch(addCardViewModelProvider);
  34. return Scaffold(
  35. appBar: MyAppBar.appBar(context, S.current.add_new_card),
  36. backgroundColor: context.appColors.whiteBG,
  37. body: SizedBox(
  38. width: double.infinity,
  39. child: Column(
  40. mainAxisSize: MainAxisSize.max,
  41. crossAxisAlignment: CrossAxisAlignment.start,
  42. children: [
  43. SingleChildScrollView(
  44. scrollDirection: Axis.vertical,
  45. physics: const BouncingScrollPhysics(),
  46. child: Column(
  47. crossAxisAlignment: CrossAxisAlignment.start,
  48. children: [
  49. const Row(
  50. mainAxisAlignment: MainAxisAlignment.spaceAround,
  51. children: [
  52. MyAssetImage(Assets.paymentMasterCardIcon, width: 51, height: 30.5),
  53. MyAssetImage(Assets.paymentVisaIcon, width: 78.5, height: 25.5),
  54. MyAssetImage(Assets.paymentAmericanExpressIcon, width: 47, height: 29),
  55. ],
  56. ).marginOnly(left: 20, right: 20, top: 32, bottom: 32),
  57. //信用卡
  58. MyTextView(
  59. S.current.credit_debit_card,
  60. fontSize: 17,
  61. marginLeft: 15,
  62. marginRight: 15,
  63. textColor: context.appColors.textBlack,
  64. isFontMedium: true,
  65. ),
  66. //持卡人姓名
  67. _buildInputLayout(
  68. context,
  69. state,
  70. "card_name",
  71. margin: const EdgeInsets.only(left: 15, right: 15, top: 16),
  72. leftIcon: Assets.paymentCardName,
  73. textInputType: TextInputType.text,
  74. textInputAction: TextInputAction.next,
  75. onSubmit: (formKey, value) {
  76. state.formData[formKey]!['focusNode'].unfocus();
  77. FocusScope.of(context).requestFocus(state.formData['card_number']!['focusNode']);
  78. },
  79. ),
  80. //卡号
  81. _buildInputLayout(
  82. context,
  83. state,
  84. "card_number",
  85. margin: const EdgeInsets.only(left: 15, right: 15, top: 10, bottom: 21),
  86. leftIcon: Assets.paymentCardNumber,
  87. textInputType: TextInputType.number,
  88. textInputAction: TextInputAction.next,
  89. onSubmit: (formKey, value) {
  90. state.formData[formKey]!['focusNode'].unfocus();
  91. FocusScope.of(context).requestFocus(state.formData['month']!['focusNode']);
  92. },
  93. ),
  94. //月份,年份,验证码
  95. Row(
  96. children: [
  97. //月份
  98. _buildInputLayout(
  99. context,
  100. state,
  101. "month",
  102. margin: const EdgeInsets.only(left: 15),
  103. showLeftIcon: false,
  104. textInputType: TextInputType.number,
  105. textInputAction: TextInputAction.next,
  106. onSubmit: (formKey, value) {
  107. state.formData[formKey]!['focusNode'].unfocus();
  108. FocusScope.of(context).requestFocus(state.formData['year']!['focusNode']);
  109. },
  110. ).expanded(),
  111. //年份
  112. _buildInputLayout(
  113. context,
  114. state,
  115. "year",
  116. margin: const EdgeInsets.only(left: 8.5, right: 8.5),
  117. showLeftIcon: false,
  118. textInputType: TextInputType.number,
  119. textInputAction: TextInputAction.next,
  120. onSubmit: (formKey, value) {
  121. state.formData[formKey]!['focusNode'].unfocus();
  122. FocusScope.of(context).requestFocus(state.formData['cyc']!['focusNode']);
  123. },
  124. ).expanded(),
  125. //验证码
  126. _buildInputLayout(
  127. context,
  128. state,
  129. "cyc",
  130. margin: const EdgeInsets.only(right: 15),
  131. showLeftIcon: false,
  132. textInputType: TextInputType.number,
  133. textInputAction: TextInputAction.next,
  134. onSubmit: (formKey, value) {
  135. state.formData[formKey]!['focusNode'].unfocus();
  136. },
  137. ).expanded(),
  138. ],
  139. )
  140. ],
  141. )).expanded(),
  142. //底部按钮
  143. MyButton(
  144. onPressed: viewModel.addCard,
  145. text: S.current.add_card,
  146. textColor: Colors.white,
  147. backgroundColor: context.appColors.btnBgDefault,
  148. fontWeight: FontWeight.w500,
  149. type: ClickType.throttle,
  150. fontSize: 16,
  151. minHeight: 50,
  152. radius: 0,
  153. ),
  154. ],
  155. ),
  156. ),
  157. );
  158. }
  159. Widget _buildInputLayout(
  160. BuildContext context,
  161. AddCardState state,
  162. String key, {
  163. EdgeInsetsGeometry? margin,
  164. bool showRightIcon = false, //是否展示右侧的布局
  165. bool showLeftIcon = true, //是否展示左侧侧的布局
  166. Widget? rightWidget, //右侧的布局
  167. TextInputType textInputType = TextInputType.text,
  168. String? leftIcon,
  169. String? errorText,
  170. bool obscureText = false,
  171. TextInputAction textInputAction = TextInputAction.done,
  172. Function? onSubmit,
  173. }) {
  174. return IgnoreKeyboardDismiss(
  175. child: MyTextField(
  176. key,
  177. fillBackgroundColor: context.appColors.authFiledBG,
  178. state.formData[key]!['value'],
  179. hintText: state.formData[key]!['hintText'],
  180. hintStyle: TextStyle(
  181. color: context.appColors.authFiledHintDark,
  182. fontSize: 16.0,
  183. fontWeight: FontWeight.w400,
  184. ),
  185. controller: state.formData[key]!['controller'],
  186. focusNode: state.formData[key]!['focusNode'],
  187. margin: margin ?? EdgeInsets.zero,
  188. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  189. showDivider: false,
  190. height: 44,
  191. style: TextStyle(
  192. color: context.appColors.authFiledText,
  193. fontSize: 16.0,
  194. fontWeight: FontWeight.w400,
  195. ),
  196. inputType: textInputType,
  197. textInputAction: textInputAction,
  198. onSubmit: onSubmit,
  199. cursorColor: context.appColors.authFiledText,
  200. obscureText: obscureText,
  201. errorText: errorText,
  202. showLeftIcon: showLeftIcon,
  203. leftWidget: showLeftIcon ? MyAssetImage(leftIcon ?? "", width: 27, height: 27) : const SizedBox(),
  204. showRightIcon: showRightIcon,
  205. rightWidget: rightWidget,
  206. ),
  207. );
  208. }
  209. }