select_unit_page.dart 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import 'package:cs_resources/generated/assets.dart';
  2. import 'package:cs_resources/generated/l10n.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:auto_route/auto_route.dart';
  6. import 'package:flutter_hooks/flutter_hooks.dart';
  7. import 'package:hooks_riverpod/hooks_riverpod.dart';
  8. import 'package:router/ext/auto_router_extensions.dart';
  9. import 'package:shared/utils/log_utils.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 'select_unit_state.dart';
  19. import 'select_unit_view_model.dart';
  20. @RoutePage()
  21. class SelectUnitPage extends HookConsumerWidget {
  22. SelectUnitPage({Key? key}) : super(key: key);
  23. //启动当前页面
  24. static void startInstance({BuildContext? context}) {
  25. if (context != null) {
  26. context.router.push(SelectUnitPageRoute());
  27. } else {
  28. appRouter.push(SelectUnitPageRoute());
  29. }
  30. }
  31. @override
  32. Widget build(BuildContext context, WidgetRef ref) {
  33. final viewModel = ref.watch(selectUnitViewModelProvider.notifier);
  34. final state = ref.watch(selectUnitViewModelProvider);
  35. return Scaffold(
  36. appBar: MyAppBar.appBar(context, S.current.yy_home_accounts),
  37. backgroundColor: context.appColors.backgroundDefault,
  38. body: Container(
  39. padding: const EdgeInsets.symmetric(horizontal: 20),
  40. width: double.infinity,
  41. child: Column(
  42. mainAxisSize: MainAxisSize.max,
  43. crossAxisAlignment: CrossAxisAlignment.center,
  44. children: [
  45. SingleChildScrollView(
  46. scrollDirection: Axis.vertical,
  47. physics: const BouncingScrollPhysics(),
  48. child: Column(
  49. crossAxisAlignment: CrossAxisAlignment.center,
  50. children: [
  51. //顶部图片
  52. const MyAssetImage(
  53. Assets.authSignUpUnitImg,
  54. width: 266.5,
  55. height: 162,
  56. ).marginOnly(top: 28, bottom: 18),
  57. Row(
  58. mainAxisSize: MainAxisSize.min,
  59. children: [
  60. //街区
  61. Column(
  62. crossAxisAlignment: CrossAxisAlignment.start,
  63. children: [
  64. MyTextView(
  65. S.current.block,
  66. marginBottom: 9,
  67. textColor: context.appColors.textBlack,
  68. fontSize: 16,
  69. isFontMedium: true,
  70. ),
  71. // 表单 - 街区
  72. _buildInputLayout(
  73. context,
  74. state,
  75. "block",
  76. textInputAction: TextInputAction.next,
  77. onSubmit: (formKey, value) {
  78. state.formData[formKey]!['focusNode'].unfocus();
  79. FocusScope.of(context).requestFocus(state.formData['unit']!['focusNode']);
  80. },
  81. ).constrained(width: 88),
  82. ],
  83. ),
  84. MyTextView(
  85. "#",
  86. marginTop: 20,
  87. marginLeft: 8.5,
  88. marginRight: 8.5,
  89. textColor: context.appColors.textBlack,
  90. fontSize: 16,
  91. isFontMedium: true,
  92. ),
  93. //单元
  94. Column(
  95. crossAxisAlignment: CrossAxisAlignment.start,
  96. children: [
  97. MyTextView(
  98. S.current.unit_number,
  99. marginBottom: 9,
  100. textColor: context.appColors.textBlack,
  101. fontSize: 16,
  102. isFontMedium: true,
  103. ),
  104. Row(
  105. children: [
  106. // 表单 - 单元
  107. _buildInputLayout(
  108. context,
  109. state,
  110. "unit",
  111. textInputAction: TextInputAction.next,
  112. onSubmit: (formKey, value) {
  113. state.formData[formKey]!['focusNode'].unfocus();
  114. FocusScope.of(context).requestFocus(state.formData['room']!['focusNode']);
  115. },
  116. ).constrained(width: 83),
  117. MyTextView(
  118. "-",
  119. textColor: context.appColors.textBlack,
  120. marginLeft: 4,
  121. marginRight: 4,
  122. isFontMedium: true,
  123. ),
  124. // 表单 - 房号
  125. _buildInputLayout(
  126. context,
  127. state,
  128. "room",
  129. textInputAction: TextInputAction.done,
  130. onSubmit: (formKey, value) {
  131. state.formData[formKey]!['focusNode'].unfocus();
  132. },
  133. ).constrained(width: 83),
  134. ],
  135. ),
  136. ],
  137. ),
  138. ],
  139. ),
  140. MyTextView(
  141. S.current.block_desc,
  142. fontSize: 15,
  143. marginTop: 25,
  144. textAlign: TextAlign.center,
  145. isFontMedium: true,
  146. textColor: context.appColors.textBlack,
  147. ),
  148. MyTextView(
  149. S.current.block_example,
  150. fontSize: 15,
  151. marginTop: 20,
  152. textAlign: TextAlign.center,
  153. isFontMedium: true,
  154. textColor: context.appColors.textBlack,
  155. ),
  156. MyTextView(
  157. S.current.block_example_desc,
  158. fontSize: 15,
  159. marginTop: 20,
  160. textAlign: TextAlign.center,
  161. isFontMedium: true,
  162. textColor: context.appColors.textBlack,
  163. ),
  164. ],
  165. )).expanded(),
  166. MyButton(
  167. onPressed: viewModel.submitUnit,
  168. text: S.current.next,
  169. textColor: Colors.white,
  170. backgroundColor: context.appColors.btnBgDefault,
  171. fontWeight: FontWeight.w500,
  172. type: ClickType.throttle,
  173. fontSize: 16,
  174. minHeight: 50,
  175. radius: 5,
  176. ).marginOnly(top: 50, bottom: 50, left: 18, right: 18),
  177. ],
  178. ),
  179. ),
  180. );
  181. }
  182. /// 输入框
  183. Widget _buildInputLayout(
  184. BuildContext context,
  185. SelectUnitState state,
  186. String key, {
  187. double marginTop = 0,
  188. bool? showRightIcon = false, //是否展示右侧的布局
  189. Widget? rightWidget, //右侧的布局
  190. TextInputType textInputType = TextInputType.number,
  191. String? errorText,
  192. bool obscureText = false,
  193. TextInputAction textInputAction = TextInputAction.done,
  194. Function? onSubmit,
  195. }) {
  196. return IgnoreKeyboardDismiss(
  197. child: MyTextField(
  198. key,
  199. fillBackgroundColor: context.appColors.authFiledBG,
  200. state.formData[key]!['value'],
  201. hintText: state.formData[key]!['hintText'],
  202. hintStyle: TextStyle(
  203. color: context.appColors.authFiledHint,
  204. fontSize: 16.0,
  205. fontWeight: FontWeight.w500,
  206. ),
  207. controller: state.formData[key]!['controller'],
  208. focusNode: state.formData[key]!['focusNode'],
  209. margin: EdgeInsets.only(top: marginTop),
  210. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  211. showDivider: false,
  212. height: 44,
  213. style: TextStyle(
  214. color: context.appColors.authFiledText,
  215. fontSize: 16.0,
  216. fontWeight: FontWeight.w500,
  217. ),
  218. inputType: textInputType,
  219. textInputAction: textInputAction,
  220. onSubmit: onSubmit,
  221. cursorColor: context.appColors.authFiledText,
  222. obscureText: obscureText,
  223. errorText: errorText,
  224. showLeftIcon: true,
  225. showRightIcon: showRightIcon,
  226. rightWidget: rightWidget,
  227. ),
  228. );
  229. }
  230. }