sign_up_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. import 'package:cpt_auth/modules/sign_up/sign_up_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/gestures.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:auto_route/auto_route.dart';
  8. import 'package:hooks_riverpod/hooks_riverpod.dart';
  9. import 'package:router/ext/auto_router_extensions.dart';
  10. import 'package:widgets/ext/ex_widget.dart';
  11. import 'package:widgets/my_appbar.dart';
  12. import 'package:widgets/my_button.dart';
  13. import 'package:widgets/my_load_image.dart';
  14. import 'package:widgets/my_text_field.dart';
  15. import 'package:widgets/my_text_view.dart';
  16. import 'package:widgets/widget_export.dart';
  17. import '../../router/page/auth_page_router.dart';
  18. import 'sign_up_view_model.dart';
  19. @RoutePage()
  20. class SignUpPage extends HookConsumerWidget {
  21. const SignUpPage({Key? key}) : super(key: key);
  22. //启动当前页面
  23. static void startInstance({BuildContext? context}) {
  24. if (context != null) {
  25. context.router.push(const SignUpPageRoute());
  26. } else {
  27. appRouter.push(const SignUpPageRoute());
  28. }
  29. }
  30. @override
  31. Widget build(BuildContext context, WidgetRef ref) {
  32. final viewModel = ref.read(signUpViewModelProvider.notifier);
  33. final state = ref.watch(signUpViewModelProvider);
  34. return Scaffold(
  35. appBar: MyAppBar.appBar(context, ""),
  36. backgroundColor: context.appColors.backgroundDefault,
  37. body: SingleChildScrollView(
  38. scrollDirection: Axis.vertical,
  39. physics: const BouncingScrollPhysics(),
  40. child: Container(
  41. margin: const EdgeInsets.symmetric(horizontal: 38),
  42. width: double.infinity,
  43. child: Column(
  44. mainAxisSize: MainAxisSize.max,
  45. crossAxisAlignment: CrossAxisAlignment.center,
  46. children: [
  47. //顶部图片
  48. const MyAssetImage(
  49. Assets.authSignUpInputImg,
  50. width: 260,
  51. height: 170,
  52. ).marginOnly(top: 22, bottom: 34),
  53. // 表单 - 名
  54. _buildInputLayout(
  55. context,
  56. state,
  57. "first_name",
  58. textInputType: TextInputType.text,
  59. textInputAction: TextInputAction.next,
  60. errorText: state.firstNameErrorText,
  61. onSubmit: (formKey, value) {
  62. state.formData[formKey]!['focusNode'].unfocus();
  63. FocusScope.of(context).requestFocus(state.formData['last_name']!['focusNode']);
  64. },
  65. ),
  66. // 表单 - 姓
  67. _buildInputLayout(
  68. context,
  69. state,
  70. "last_name",
  71. marginTop: 15,
  72. textInputType: TextInputType.text,
  73. textInputAction: TextInputAction.next,
  74. errorText: state.lastNameErrorText,
  75. onSubmit: (formKey, value) {
  76. state.formData[formKey]!['focusNode'].unfocus();
  77. FocusScope.of(context).requestFocus(state.formData['email']!['focusNode']);
  78. },
  79. ),
  80. // 表单 - 邮箱
  81. _buildInputLayout(
  82. context,
  83. state,
  84. "email",
  85. marginTop: 15,
  86. textInputType: TextInputType.emailAddress,
  87. textInputAction: TextInputAction.next,
  88. errorText: state.emailErrorText,
  89. onSubmit: (formKey, value) {
  90. state.formData[formKey]!['focusNode'].unfocus();
  91. FocusScope.of(context).requestFocus(state.formData['phone']!['focusNode']);
  92. },
  93. ),
  94. // 表单 - 电话
  95. Row(
  96. mainAxisSize: MainAxisSize.max,
  97. crossAxisAlignment: CrossAxisAlignment.center,
  98. children: [
  99. const MyAssetImage(
  100. Assets.authCountrySg,
  101. width: 45,
  102. height: 30,
  103. ),
  104. MyTextView(
  105. "+65",
  106. textColor: context.appColors.textBlack,
  107. fontSize: 20,
  108. marginLeft: 15,
  109. marginRight: 12,
  110. isFontMedium: true,
  111. ),
  112. //电话输入框
  113. _buildInputLayout(
  114. context,
  115. state,
  116. "phone",
  117. marginTop: 15,
  118. textInputType: TextInputType.number,
  119. textInputAction: TextInputAction.next,
  120. errorText: state.phoneErrorText,
  121. onSubmit: (formKey, value) {
  122. state.formData[formKey]!['focusNode'].unfocus();
  123. FocusScope.of(context).requestFocus(state.formData['password']!['focusNode']);
  124. },
  125. ).expanded(),
  126. ],
  127. ),
  128. // 表单 - 重置密码
  129. _buildInputLayout(
  130. context,
  131. state,
  132. "password",
  133. marginTop: 15,
  134. obscureText: !state.pwdVisibility,
  135. errorText: state.passwordErrorText,
  136. textInputAction: TextInputAction.next,
  137. showRightIcon: true,
  138. rightWidget: IconButton(
  139. highlightColor: Colors.transparent,
  140. splashColor: Colors.transparent,
  141. icon: state.pwdVisibility
  142. ? const MyAssetImage(
  143. Assets.authPasswordHide,
  144. width: 22.5,
  145. height: 16.5,
  146. )
  147. : const MyAssetImage(
  148. Assets.authPasswordShow,
  149. width: 22.5,
  150. height: 16.5,
  151. ),
  152. onPressed: () {
  153. viewModel.switchPwdVisibility();
  154. },
  155. ),
  156. onSubmit: (formKey, value) {
  157. state.formData[formKey]!['focusNode'].unfocus();
  158. FocusScope.of(context).requestFocus(state.formData['confirm_password']!['focusNode']);
  159. },
  160. ),
  161. // 表单 - 确认密码
  162. _buildInputLayout(
  163. context,
  164. state,
  165. "confirm_password",
  166. marginTop: 15,
  167. obscureText: !state.confirmPwdVisibility,
  168. errorText: state.confirmPasswordErrorText,
  169. showRightIcon: true,
  170. rightWidget: IconButton(
  171. highlightColor: Colors.transparent,
  172. splashColor: Colors.transparent,
  173. icon: state.confirmPwdVisibility
  174. ? const MyAssetImage(
  175. Assets.authPasswordHide,
  176. width: 22.5,
  177. height: 16.5,
  178. )
  179. : const MyAssetImage(
  180. Assets.authPasswordShow,
  181. width: 22.5,
  182. height: 16.5,
  183. ),
  184. onPressed: () {
  185. viewModel.switchConfirmPwdVisibility();
  186. },
  187. ),
  188. onSubmit: (formKey, value) {
  189. state.formData[formKey]!['focusNode'].unfocus();
  190. viewModel.submitSignUp();
  191. },
  192. ),
  193. MyButton(
  194. onPressed: viewModel.submitSignUp,
  195. text: S.current.next,
  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: 25, bottom: 25),
  204. //同意协议
  205. Row(
  206. mainAxisSize: MainAxisSize.min,
  207. children: [
  208. MyAssetImage(
  209. state.isAgreeTerms ? Assets.baseServiceCheckBoxChecked : Assets.baseServiceCheckBoxUncheck,
  210. width: 15.5,
  211. height: 15.5,
  212. ).onTap(viewModel.switchAgreeTerms, padding: 10),
  213. RichText(
  214. text: TextSpan(
  215. children: [
  216. TextSpan(
  217. text: S.current.agree_to,
  218. style: TextStyle(color: context.appColors.textDarkGray, fontWeight: FontWeight.w500, fontSize: 15), // 灰色文本
  219. ),
  220. const TextSpan(
  221. text: " ",
  222. ),
  223. TextSpan(
  224. text: S.current.terms_of_service,
  225. style: TextStyle(color: context.appColors.textPrimary, fontWeight: FontWeight.w500, fontSize: 15), // 蓝色文本
  226. recognizer: TapGestureRecognizer()..onTap = viewModel.gotoTermsPage,
  227. ),
  228. ],
  229. ),
  230. ),
  231. ],
  232. ).marginOnly(bottom: 35),
  233. ],
  234. ),
  235. ),
  236. ),
  237. );
  238. }
  239. /// 输入框
  240. Widget _buildInputLayout(
  241. BuildContext context,
  242. SignUpState state,
  243. String key, {
  244. double marginTop = 0,
  245. bool? showRightIcon = false, //是否展示右侧的布局
  246. Widget? rightWidget, //右侧的布局
  247. TextInputType textInputType = TextInputType.text,
  248. String? errorText,
  249. bool obscureText = false,
  250. TextInputAction textInputAction = TextInputAction.done,
  251. Function? onSubmit,
  252. }) {
  253. return IgnoreKeyboardDismiss(
  254. child: MyTextField(
  255. key,
  256. fillBackgroundColor: context.appColors.authFiledBG,
  257. state.formData[key]!['value'],
  258. hintText: state.formData[key]!['hintText'],
  259. hintStyle: TextStyle(
  260. color: context.appColors.authFiledHint,
  261. fontSize: 16.0,
  262. fontWeight: FontWeight.w500,
  263. ),
  264. controller: state.formData[key]!['controller'],
  265. focusNode: state.formData[key]!['focusNode'],
  266. margin: EdgeInsets.only(top: marginTop),
  267. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  268. showDivider: false,
  269. height: 44,
  270. style: TextStyle(
  271. color: context.appColors.authFiledText,
  272. fontSize: 16.0,
  273. fontWeight: FontWeight.w500,
  274. ),
  275. inputType: textInputType,
  276. textInputAction: textInputAction,
  277. onSubmit: onSubmit,
  278. cursorColor: context.appColors.authFiledText,
  279. obscureText: obscureText,
  280. errorText: errorText,
  281. showLeftIcon: true,
  282. showRightIcon: showRightIcon,
  283. rightWidget: rightWidget,
  284. ),
  285. );
  286. }
  287. }