guest_vehicle_page.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. import 'package:cs_resources/generated/l10n.dart';
  2. import 'package:cs_resources/theme/app_colors_theme.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:auto_route/auto_route.dart';
  5. import 'package:flutter_hooks/flutter_hooks.dart';
  6. import 'package:hooks_riverpod/hooks_riverpod.dart';
  7. import 'package:plugin_platform/engine/toast/toast_engine.dart';
  8. import 'package:router/ext/auto_router_extensions.dart';
  9. import 'package:widgets/ext/ex_widget.dart';
  10. import 'package:widgets/my_appbar.dart';
  11. import 'package:widgets/my_button.dart';
  12. import 'package:widgets/my_text_field.dart';
  13. import 'package:widgets/my_text_view.dart';
  14. import 'package:widgets/shatter/form_require_text.dart';
  15. import 'package:widgets/shatter/picker_container.dart';
  16. import 'package:widgets/widget_export.dart';
  17. import '../../router/page/form_page_router.dart';
  18. import 'vm/apply_view_model.dart';
  19. @RoutePage()
  20. class GuestVehiclePage extends HookConsumerWidget {
  21. const GuestVehiclePage({Key? key}) : super(key: key);
  22. //启动当前页面
  23. static void startInstance({BuildContext? context}) {
  24. if (context != null) {
  25. context.router.push(const GuestVehiclePageRoute());
  26. } else {
  27. appRouter.push(const GuestVehiclePageRoute());
  28. }
  29. }
  30. @override
  31. Widget build(BuildContext context, WidgetRef ref) {
  32. final viewModel = ref.watch(applyViewModelProvider.notifier);
  33. final state = ref.watch(applyViewModelProvider);
  34. // 使用 useState 来持久化 TextEditingController 和 FocusNode
  35. final TextEditingController vehicleNumController = useTextEditingController();
  36. final TextEditingController vehicleInfoController = useTextEditingController();
  37. final TextEditingController guestNameController = useTextEditingController();
  38. final TextEditingController guestPhoneController = useTextEditingController();
  39. final FocusNode vehicleNumFocusNode = useFocusNode();
  40. final FocusNode vehicleInfoFocusNode = useFocusNode();
  41. final FocusNode guestNameFocusNode = useFocusNode();
  42. final FocusNode guestPhoneFocusNode = useFocusNode();
  43. useEffect(() {
  44. //赋值State的值
  45. Future.microtask(() {});
  46. return () {
  47. // 释放控制器资源
  48. vehicleNumController.dispose();
  49. vehicleInfoController.dispose();
  50. guestNameController.dispose();
  51. guestPhoneController.dispose();
  52. vehicleNumFocusNode.dispose();
  53. vehicleInfoFocusNode.dispose();
  54. guestNameFocusNode.dispose();
  55. guestPhoneFocusNode.dispose();
  56. };
  57. }, []);
  58. return WillPopScope(
  59. child: Scaffold(
  60. appBar: MyAppBar.appBar(context, state.applyDetail?['title']),
  61. backgroundColor: context.appColors.backgroundWhite,
  62. body: Column(
  63. crossAxisAlignment: CrossAxisAlignment.start,
  64. children: [
  65. SingleChildScrollView(
  66. scrollDirection: Axis.vertical,
  67. physics: const BouncingScrollPhysics(),
  68. child: Container(
  69. width: double.infinity,
  70. child: Column(
  71. mainAxisSize: MainAxisSize.max,
  72. crossAxisAlignment: CrossAxisAlignment.start,
  73. children: [
  74. //下拉选 - 访问时间
  75. MyTextView(
  76. S.current.date_of_entry,
  77. fontSize: 17,
  78. marginTop: 30,
  79. marginLeft: 15,
  80. marginBottom: 16,
  81. isFontMedium: true,
  82. textColor: context.appColors.textBlack,
  83. ),
  84. PickerContainer(
  85. hint: S.current.choose_date,
  86. onClick: () {
  87. viewModel.pickDate(null, (date) {
  88. ToastEngine.show("选择的日期:$date");
  89. });
  90. },
  91. ).marginOnly(left: 15, right: 15),
  92. //输入框 - 车牌号
  93. FormRequireText(
  94. text: S.current.vehicle_number,
  95. textColor: context.appColors.textBlack,
  96. fontSize: 17,
  97. fontWeight: FontWeight.w500,
  98. ).marginOnly(top: 14, bottom: 16, left: 15, right: 15),
  99. // 表单
  100. _buildInputLayout(
  101. context,
  102. "vehicle_num",
  103. textInputType: TextInputType.text,
  104. textInputAction: TextInputAction.next,
  105. controller: vehicleNumController,
  106. focusNode: vehicleNumFocusNode,
  107. onSubmit: (formKey, value) {
  108. vehicleNumFocusNode.unfocus();
  109. FocusScope.of(context).requestFocus(vehicleInfoFocusNode);
  110. },
  111. ),
  112. //输入框 - 车辆信息
  113. FormRequireText(
  114. text: S.current.vehicle_make_model_colour,
  115. textColor: context.appColors.textBlack,
  116. fontSize: 17,
  117. fontWeight: FontWeight.w500,
  118. ).marginOnly(top: 14, bottom: 16, left: 15, right: 15),
  119. // 表单
  120. _buildInputLayout(
  121. context,
  122. "vehicle_info",
  123. textInputType: TextInputType.text,
  124. textInputAction: TextInputAction.next,
  125. controller: vehicleInfoController,
  126. focusNode: vehicleInfoFocusNode,
  127. onSubmit: (formKey, value) {
  128. vehicleInfoFocusNode.unfocus();
  129. FocusScope.of(context).requestFocus(guestNameFocusNode);
  130. },
  131. ),
  132. //输入框 - 访客姓名
  133. FormRequireText(
  134. text: S.current.guest_name,
  135. textColor: context.appColors.textBlack,
  136. fontSize: 17,
  137. fontWeight: FontWeight.w500,
  138. ).marginOnly(top: 14, bottom: 16, left: 15, right: 15),
  139. // 表单
  140. _buildInputLayout(
  141. context,
  142. "guest_name",
  143. textInputType: TextInputType.text,
  144. textInputAction: TextInputAction.next,
  145. controller: guestNameController,
  146. focusNode: guestNameFocusNode,
  147. onSubmit: (formKey, value) {
  148. guestNameFocusNode.unfocus();
  149. FocusScope.of(context).requestFocus(guestPhoneFocusNode);
  150. },
  151. ),
  152. //输入框 - 访客电话
  153. FormRequireText(
  154. text: S.current.guest_mobile_number,
  155. textColor: context.appColors.textBlack,
  156. fontSize: 17,
  157. fontWeight: FontWeight.w500,
  158. ).marginOnly(top: 14, bottom: 16, left: 15, right: 15),
  159. // 表单
  160. _buildInputLayout(
  161. context,
  162. "guest_phone",
  163. textInputType: TextInputType.phone,
  164. textInputAction: TextInputAction.done,
  165. controller: guestPhoneController,
  166. focusNode: guestPhoneFocusNode,
  167. onSubmit: (formKey, value) {
  168. guestPhoneFocusNode.unfocus();
  169. },
  170. ),
  171. ],
  172. ),
  173. ),
  174. ).expanded(),
  175. //底部按钮
  176. MyButton(
  177. onPressed: () {
  178. vehicleNumFocusNode.unfocus();
  179. vehicleInfoFocusNode.unfocus();
  180. guestNameFocusNode.unfocus();
  181. guestPhoneFocusNode.unfocus();
  182. viewModel.gotoNextPage();
  183. },
  184. text: S.current.next,
  185. textColor: Colors.white,
  186. backgroundColor: context.appColors.btnBgDefault,
  187. fontWeight: FontWeight.w500,
  188. type: ClickType.throttle,
  189. fontSize: 16,
  190. minHeight: 50,
  191. radius: 0,
  192. ),
  193. ],
  194. )),
  195. onWillPop: () async {
  196. viewModel.handlePopAction();
  197. return true;
  198. });
  199. }
  200. Widget _buildInputLayout(
  201. BuildContext context,
  202. String key, {
  203. double marginTop = 0,
  204. bool? showRightIcon = false, //是否展示右侧的布局
  205. Widget? rightWidget, //右侧的布局
  206. TextInputType textInputType = TextInputType.text,
  207. String? errorText,
  208. bool obscureText = false,
  209. required TextEditingController controller,
  210. required FocusNode focusNode,
  211. bool enable = true,
  212. TextInputAction textInputAction = TextInputAction.done,
  213. Function? onSubmit,
  214. }) {
  215. return IgnoreKeyboardDismiss(
  216. child: MyTextField(
  217. key,
  218. fillBackgroundColor: context.appColors.authFiledBG,
  219. "",
  220. hintStyle: TextStyle(
  221. color: context.appColors.authFiledHint,
  222. fontSize: 16.0,
  223. fontWeight: FontWeight.w500,
  224. ),
  225. controller: controller,
  226. focusNode: focusNode,
  227. margin: EdgeInsets.only(top: marginTop, left: 15, right: 15),
  228. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  229. showDivider: false,
  230. height: 44,
  231. enabled: enable,
  232. style: TextStyle(
  233. color: context.appColors.authFiledText,
  234. fontSize: 16.0,
  235. fontWeight: FontWeight.w500,
  236. ),
  237. inputType: textInputType,
  238. textInputAction: textInputAction,
  239. onSubmit: onSubmit,
  240. cursorColor: context.appColors.authFiledText,
  241. obscureText: obscureText,
  242. errorText: errorText,
  243. showLeftIcon: true,
  244. showRightIcon: showRightIcon,
  245. rightWidget: rightWidget,
  246. ),
  247. );
  248. }
  249. }