moving_company_page.dart 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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:router/ext/auto_router_extensions.dart';
  8. import 'package:widgets/ext/ex_widget.dart';
  9. import 'package:widgets/my_appbar.dart';
  10. import 'package:widgets/my_button.dart';
  11. import 'package:widgets/my_text_field.dart';
  12. import 'package:widgets/my_text_view.dart';
  13. import 'package:widgets/shatter/form_require_text.dart';
  14. import 'package:widgets/widget_export.dart';
  15. import '../../router/page/form_page_router.dart';
  16. import 'vm/apply_view_model.dart';
  17. @RoutePage()
  18. class MovingCompanyPage extends HookConsumerWidget {
  19. const MovingCompanyPage({Key? key}) : super(key: key);
  20. //启动当前页面
  21. static void startInstance({BuildContext? context}) {
  22. if (context != null) {
  23. context.router.push(const MovingCompanyPageRoute());
  24. } else {
  25. appRouter.push(const MovingCompanyPageRoute());
  26. }
  27. }
  28. @override
  29. Widget build(BuildContext context, WidgetRef ref) {
  30. final viewModel = ref.watch(applyViewModelProvider.notifier);
  31. final state = ref.watch(applyViewModelProvider);
  32. // 使用 useState 来持久化 TextEditingController 和 FocusNode
  33. final companyController = useTextEditingController();
  34. final contactController = useTextEditingController();
  35. final phoneController = useTextEditingController();
  36. final addressController = useTextEditingController();
  37. final companyFocusNode = useFocusNode();
  38. final contactFocusNode = useFocusNode();
  39. final phoneFocusNode = useFocusNode();
  40. final addressFocusNode = useFocusNode();
  41. useEffect(() {
  42. //赋值State的值
  43. Future.microtask(() {});
  44. return () {
  45. // 释放控制器资源
  46. companyController.dispose();
  47. contactController.dispose();
  48. phoneController.dispose();
  49. addressController.dispose();
  50. companyFocusNode.dispose();
  51. contactFocusNode.dispose();
  52. phoneFocusNode.dispose();
  53. addressFocusNode.dispose();
  54. };
  55. }, []);
  56. return WillPopScope(
  57. child: Scaffold(
  58. appBar: MyAppBar.appBar(context, state.applyDetail?['title']),
  59. backgroundColor: context.appColors.backgroundWhite,
  60. body: Column(
  61. crossAxisAlignment: CrossAxisAlignment.start,
  62. children: [
  63. SingleChildScrollView(
  64. scrollDirection: Axis.vertical,
  65. physics: const BouncingScrollPhysics(),
  66. child: Container(
  67. width: double.infinity,
  68. child: Column(
  69. mainAxisSize: MainAxisSize.max,
  70. crossAxisAlignment: CrossAxisAlignment.start,
  71. children: [
  72. //输入框 - 搬家公司
  73. FormRequireText(
  74. text: S.current.moving_company,
  75. textColor: context.appColors.textBlack,
  76. fontSize: 17,
  77. fontWeight: FontWeight.w500,
  78. ).marginOnly(top: 14, bottom: 16, left: 15, right: 15),
  79. // 表单
  80. _buildInputLayout(
  81. context,
  82. "company",
  83. textInputType: TextInputType.text,
  84. textInputAction: TextInputAction.next,
  85. controller: companyController,
  86. focusNode: companyFocusNode,
  87. onSubmit: (formKey, value) {
  88. companyFocusNode.unfocus();
  89. FocusScope.of(context).requestFocus(contactFocusNode);
  90. },
  91. ),
  92. //输入框 - 联系人
  93. FormRequireText(
  94. text: S.current.person_in_charge,
  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. "contact",
  103. textInputType: TextInputType.text,
  104. textInputAction: TextInputAction.next,
  105. controller: contactController,
  106. focusNode: contactFocusNode,
  107. onSubmit: (formKey, value) {
  108. contactFocusNode.unfocus();
  109. FocusScope.of(context).requestFocus(phoneFocusNode);
  110. },
  111. ),
  112. //输入框 - 联系电话
  113. FormRequireText(
  114. text: S.current.mobile_phone,
  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. "phone",
  123. textInputType: TextInputType.phone,
  124. textInputAction: TextInputAction.next,
  125. controller: phoneController,
  126. focusNode: phoneFocusNode,
  127. onSubmit: (formKey, value) {
  128. phoneFocusNode.unfocus();
  129. FocusScope.of(context).requestFocus(addressFocusNode);
  130. },
  131. ),
  132. //输入框 - 公司地址
  133. MyTextView(
  134. S.current.company_address,
  135. fontSize: 17,
  136. marginTop: 14,
  137. marginBottom: 16,
  138. marginLeft: 15,
  139. marginRight: 15,
  140. isFontMedium: true,
  141. textColor: context.appColors.textBlack,
  142. ),
  143. //文本框
  144. IgnoreKeyboardDismiss(
  145. child: Container(
  146. height: 160,
  147. margin: const EdgeInsets.symmetric(horizontal: 15),
  148. padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 15),
  149. decoration: BoxDecoration(
  150. color: context.appColors.authFiledBG,
  151. borderRadius: const BorderRadius.all(Radius.circular(5)),
  152. ),
  153. child: TextField(
  154. cursorColor: context.appColors.authFiledText,
  155. cursorWidth: 1.5,
  156. autofocus: false,
  157. enabled: true,
  158. focusNode: addressFocusNode,
  159. controller: addressController,
  160. decoration: InputDecoration(
  161. isDense: true,
  162. isCollapsed: true,
  163. border: InputBorder.none,
  164. hintStyle: TextStyle(
  165. color: context.appColors.authFiledHint,
  166. fontSize: 16.0,
  167. fontWeight: FontWeight.w500,
  168. ),
  169. ),
  170. style: TextStyle(
  171. color: context.appColors.authFiledText,
  172. fontSize: 16.0,
  173. fontWeight: FontWeight.w500,
  174. ),
  175. textInputAction: TextInputAction.done,
  176. onSubmitted: (value) {
  177. FocusScope.of(context).unfocus();
  178. },
  179. maxLines: null,
  180. expands: true,
  181. onChanged: (text) {
  182. // 当文本改变时
  183. },
  184. ),
  185. ),
  186. ),
  187. ],
  188. ),
  189. ),
  190. ).expanded(),
  191. //底部按钮
  192. MyButton(
  193. onPressed: (){
  194. companyFocusNode.unfocus();
  195. contactFocusNode.unfocus();
  196. phoneFocusNode.unfocus();
  197. addressFocusNode.unfocus();
  198. viewModel.gotoNextPage();
  199. },
  200. text: S.current.next,
  201. textColor: Colors.white,
  202. backgroundColor: context.appColors.btnBgDefault,
  203. fontWeight: FontWeight.w500,
  204. type: ClickType.throttle,
  205. fontSize: 16,
  206. minHeight: 50,
  207. radius: 0,
  208. ),
  209. ],
  210. )),
  211. onWillPop: () async {
  212. viewModel.handlePopAction();
  213. return true;
  214. });
  215. }
  216. Widget _buildInputLayout(
  217. BuildContext context,
  218. String key, {
  219. double marginTop = 0,
  220. bool? showRightIcon = false, //是否展示右侧的布局
  221. Widget? rightWidget, //右侧的布局
  222. TextInputType textInputType = TextInputType.text,
  223. String? errorText,
  224. bool obscureText = false,
  225. required TextEditingController controller,
  226. required FocusNode focusNode,
  227. bool enable = true,
  228. TextInputAction textInputAction = TextInputAction.done,
  229. Function? onSubmit,
  230. }) {
  231. return IgnoreKeyboardDismiss(
  232. child: MyTextField(
  233. key,
  234. fillBackgroundColor: context.appColors.authFiledBG,
  235. "",
  236. hintStyle: TextStyle(
  237. color: context.appColors.authFiledHint,
  238. fontSize: 16.0,
  239. fontWeight: FontWeight.w500,
  240. ),
  241. controller: controller,
  242. focusNode: focusNode,
  243. margin: EdgeInsets.only(top: marginTop, left: 15, right: 15),
  244. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  245. showDivider: false,
  246. height: 44,
  247. enabled: enable,
  248. style: TextStyle(
  249. color: context.appColors.authFiledText,
  250. fontSize: 16.0,
  251. fontWeight: FontWeight.w500,
  252. ),
  253. inputType: textInputType,
  254. textInputAction: textInputAction,
  255. onSubmit: onSubmit,
  256. cursorColor: context.appColors.authFiledText,
  257. obscureText: obscureText,
  258. errorText: errorText,
  259. showLeftIcon: true,
  260. showRightIcon: showRightIcon,
  261. rightWidget: rightWidget,
  262. ),
  263. );
  264. }
  265. }