select_unit_page.dart 9.4 KB

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