sign_up_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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: 18.5,
  108. marginLeft: 15,
  109. marginRight: 12,
  110. isFontMedium: true,
  111. ),
  112. //电话输入框
  113. _buildInputLayout(
  114. context,
  115. state,
  116. "phone",
  117. textInputType: TextInputType.number,
  118. textInputAction: TextInputAction.next,
  119. errorText: state.phoneErrorText,
  120. onSubmit: (formKey, value) {
  121. state.formData[formKey]!['focusNode'].unfocus();
  122. FocusScope.of(context).requestFocus(state.formData['password']!['focusNode']);
  123. },
  124. ).expanded(),
  125. ],
  126. ).marginOnly(top: 15),
  127. // 表单 - 重置密码
  128. _buildInputLayout(
  129. context,
  130. state,
  131. "password",
  132. marginTop: 15,
  133. obscureText: !state.pwdVisibility,
  134. errorText: state.passwordErrorText,
  135. textInputAction: TextInputAction.next,
  136. showRightIcon: true,
  137. rightWidget: IconButton(
  138. highlightColor: Colors.transparent,
  139. splashColor: Colors.transparent,
  140. icon: state.pwdVisibility
  141. ? const MyAssetImage(
  142. Assets.authPasswordHide,
  143. width: 22.5,
  144. height: 16.5,
  145. )
  146. : const MyAssetImage(
  147. Assets.authPasswordShow,
  148. width: 22.5,
  149. height: 16.5,
  150. ),
  151. onPressed: () {
  152. viewModel.switchPwdVisibility();
  153. },
  154. ),
  155. onSubmit: (formKey, value) {
  156. state.formData[formKey]!['focusNode'].unfocus();
  157. FocusScope.of(context).requestFocus(state.formData['confirm_password']!['focusNode']);
  158. },
  159. ),
  160. // 表单 - 确认密码
  161. _buildInputLayout(
  162. context,
  163. state,
  164. "confirm_password",
  165. marginTop: 15,
  166. obscureText: !state.confirmPwdVisibility,
  167. errorText: state.confirmPasswordErrorText,
  168. showRightIcon: true,
  169. rightWidget: IconButton(
  170. highlightColor: Colors.transparent,
  171. splashColor: Colors.transparent,
  172. icon: state.confirmPwdVisibility
  173. ? const MyAssetImage(
  174. Assets.authPasswordHide,
  175. width: 22.5,
  176. height: 16.5,
  177. )
  178. : const MyAssetImage(
  179. Assets.authPasswordShow,
  180. width: 22.5,
  181. height: 16.5,
  182. ),
  183. onPressed: () {
  184. viewModel.switchConfirmPwdVisibility();
  185. },
  186. ),
  187. onSubmit: (formKey, value) {
  188. state.formData[formKey]!['focusNode'].unfocus();
  189. viewModel.submitSignUp();
  190. },
  191. ),
  192. MyButton(
  193. onPressed: viewModel.submitSignUp,
  194. text: S.current.next,
  195. textColor: Colors.white,
  196. backgroundColor: context.appColors.btnBgDefault,
  197. fontWeight: FontWeight.w500,
  198. type: ClickType.throttle,
  199. fontSize: 16,
  200. minHeight: 50,
  201. radius: 5,
  202. ).marginOnly(top: 25, bottom: 25),
  203. //同意协议
  204. Row(
  205. mainAxisSize: MainAxisSize.min,
  206. children: [
  207. MyAssetImage(
  208. state.isAgreeTerms ? Assets.baseServiceCheckBoxChecked : Assets.baseServiceCheckBoxUncheck,
  209. width: 15.5,
  210. height: 15.5,
  211. ).onTap(viewModel.switchAgreeTerms, padding: 10),
  212. RichText(
  213. text: TextSpan(
  214. children: [
  215. TextSpan(
  216. text: S.current.agree_to,
  217. style: TextStyle(color: context.appColors.textDarkGray, fontWeight: FontWeight.w500, fontSize: 15), // 灰色文本
  218. ),
  219. const TextSpan(
  220. text: " ",
  221. ),
  222. TextSpan(
  223. text: S.current.terms_of_service,
  224. style: TextStyle(color: context.appColors.textPrimary, fontWeight: FontWeight.w500, fontSize: 15), // 蓝色文本
  225. recognizer: TapGestureRecognizer()..onTap = viewModel.gotoTermsPage,
  226. ),
  227. ],
  228. ),
  229. ),
  230. ],
  231. ).marginOnly(bottom: 35),
  232. ],
  233. ),
  234. ),
  235. ),
  236. );
  237. }
  238. /// 输入框
  239. Widget _buildInputLayout(
  240. BuildContext context,
  241. SignUpState state,
  242. String key, {
  243. double marginTop = 0,
  244. bool? showRightIcon = false, //是否展示右侧的布局
  245. Widget? rightWidget, //右侧的布局
  246. TextInputType textInputType = TextInputType.text,
  247. String? errorText,
  248. bool obscureText = false,
  249. TextInputAction textInputAction = TextInputAction.done,
  250. Function? onSubmit,
  251. }) {
  252. return IgnoreKeyboardDismiss(
  253. child: MyTextField(
  254. key,
  255. fillBackgroundColor: context.appColors.authFiledBG,
  256. state.formData[key]!['value'],
  257. hintText: state.formData[key]!['hintText'],
  258. hintStyle: TextStyle(
  259. color: context.appColors.authFiledHint,
  260. fontSize: 16.0,
  261. fontWeight: FontWeight.w500,
  262. ),
  263. controller: state.formData[key]!['controller'],
  264. focusNode: state.formData[key]!['focusNode'],
  265. margin: EdgeInsets.only(top: marginTop),
  266. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  267. showDivider: false,
  268. height: 44,
  269. style: TextStyle(
  270. color: context.appColors.authFiledText,
  271. fontSize: 16.0,
  272. fontWeight: FontWeight.w500,
  273. ),
  274. inputType: textInputType,
  275. textInputAction: textInputAction,
  276. onSubmit: onSubmit,
  277. cursorColor: context.appColors.authFiledText,
  278. obscureText: obscureText,
  279. errorText: errorText,
  280. showLeftIcon: true,
  281. showRightIcon: showRightIcon,
  282. rightWidget: rightWidget,
  283. ),
  284. );
  285. }
  286. }