sign_up_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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:plugin_basic/dialog/country_code_selecter.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/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. //封装的国家选择控件
  100. CountryCodeSelector(
  101. onChanged: (countryCode) {
  102. viewModel.saveCountryCode(countryCode);
  103. },
  104. ).marginOnly(left: 15),
  105. //电话输入框
  106. _buildInputLayout(
  107. context,
  108. state,
  109. "phone",
  110. fillBGColor: Colors.transparent,
  111. textInputType: TextInputType.number,
  112. textInputAction: TextInputAction.done,
  113. errorText: state.phoneErrorText,
  114. onSubmit: (formKey, value) {
  115. state.formData[formKey]!['focusNode'].unfocus();
  116. FocusScope.of(context).requestFocus(state.formData['password']!['focusNode']);
  117. },
  118. ).expanded(),
  119. ],
  120. )
  121. .decorated(
  122. color: context.appColors.authFiledBG,
  123. borderRadius: BorderRadius.circular(5.0),
  124. )
  125. .marginOnly(top: 15),
  126. // 表单 - 重置密码
  127. _buildInputLayout(
  128. context,
  129. state,
  130. "password",
  131. marginTop: 15,
  132. obscureText: !state.pwdVisibility,
  133. errorText: state.passwordErrorText,
  134. textInputAction: TextInputAction.next,
  135. showRightIcon: true,
  136. rightWidget: IconButton(
  137. highlightColor: Colors.transparent,
  138. splashColor: Colors.transparent,
  139. icon: state.pwdVisibility
  140. ? const MyAssetImage(
  141. Assets.authPasswordHide,
  142. width: 22.5,
  143. height: 16.5,
  144. )
  145. : const MyAssetImage(
  146. Assets.authPasswordShow,
  147. width: 22.5,
  148. height: 16.5,
  149. ),
  150. onPressed: () {
  151. viewModel.switchPwdVisibility();
  152. },
  153. ),
  154. onSubmit: (formKey, value) {
  155. state.formData[formKey]!['focusNode'].unfocus();
  156. FocusScope.of(context).requestFocus(state.formData['confirm_password']!['focusNode']);
  157. },
  158. ),
  159. // 表单 - 确认密码
  160. _buildInputLayout(
  161. context,
  162. state,
  163. "confirm_password",
  164. marginTop: 15,
  165. obscureText: !state.confirmPwdVisibility,
  166. errorText: state.confirmPasswordErrorText,
  167. showRightIcon: true,
  168. rightWidget: IconButton(
  169. highlightColor: Colors.transparent,
  170. splashColor: Colors.transparent,
  171. icon: state.confirmPwdVisibility
  172. ? const MyAssetImage(
  173. Assets.authPasswordHide,
  174. width: 22.5,
  175. height: 16.5,
  176. )
  177. : const MyAssetImage(
  178. Assets.authPasswordShow,
  179. width: 22.5,
  180. height: 16.5,
  181. ),
  182. onPressed: () {
  183. viewModel.switchConfirmPwdVisibility();
  184. },
  185. ),
  186. onSubmit: (formKey, value) {
  187. state.formData[formKey]!['focusNode'].unfocus();
  188. viewModel.submitSignUp();
  189. },
  190. ),
  191. MyButton(
  192. onPressed: viewModel.submitSignUp,
  193. text: S.current.next,
  194. textColor: Colors.white,
  195. backgroundColor: context.appColors.btnBgDefault,
  196. fontWeight: FontWeight.w500,
  197. type: ClickType.throttle,
  198. fontSize: 16,
  199. minHeight: 50,
  200. radius: 5,
  201. ).marginOnly(top: 25, bottom: 25),
  202. //同意协议
  203. Row(
  204. mainAxisSize: MainAxisSize.min,
  205. children: [
  206. MyAssetImage(
  207. state.isAgreeTerms ? Assets.baseServiceCheckBoxChecked : Assets.baseServiceCheckBoxUncheck,
  208. width: 15.5,
  209. height: 15.5,
  210. ).onTap(viewModel.switchAgreeTerms, padding: 10),
  211. RichText(
  212. text: TextSpan(
  213. children: [
  214. TextSpan(
  215. text: S.current.agree_to,
  216. style: TextStyle(color: context.appColors.textDarkGray, fontWeight: FontWeight.w500, fontSize: 15), // 灰色文本
  217. ),
  218. const TextSpan(
  219. text: " ",
  220. ),
  221. TextSpan(
  222. text: S.current.terms_of_service,
  223. style: TextStyle(color: context.appColors.textPrimary, fontWeight: FontWeight.w500, fontSize: 15), // 蓝色文本
  224. recognizer: TapGestureRecognizer()..onTap = viewModel.gotoTermsPage,
  225. ),
  226. ],
  227. ),
  228. ),
  229. ],
  230. ).marginOnly(bottom: 35),
  231. ],
  232. ),
  233. ),
  234. ),
  235. );
  236. }
  237. /// 输入框
  238. Widget _buildInputLayout(
  239. BuildContext context,
  240. SignUpState state,
  241. String key, {
  242. double marginTop = 0,
  243. bool? showRightIcon = false, //是否展示右侧的布局
  244. Widget? rightWidget, //右侧的布局
  245. TextInputType textInputType = TextInputType.text,
  246. String? errorText,
  247. Color? fillBGColor,
  248. bool obscureText = false,
  249. TextInputAction textInputAction = TextInputAction.done,
  250. Function? onSubmit,
  251. }) {
  252. return IgnoreKeyboardDismiss(
  253. child: MyTextField(
  254. key,
  255. fillBackgroundColor: fillBGColor ?? 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. }