renovation_company_page.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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:shared/utils/util.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_text_field.dart';
  14. import 'package:widgets/my_text_view.dart';
  15. import 'package:widgets/shatter/form_require_text.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 RenovationCompanyPage extends HookConsumerWidget {
  21. const RenovationCompanyPage({Key? key}) : super(key: key);
  22. //启动当前页面
  23. static void startInstance({BuildContext? context}) {
  24. if (context != null) {
  25. context.router.push(const RenovationCompanyPageRoute());
  26. } else {
  27. appRouter.push(const RenovationCompanyPageRoute());
  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 companyController = useTextEditingController();
  36. final contactController = useTextEditingController();
  37. final phoneController = useTextEditingController();
  38. final addressController = useTextEditingController();
  39. final companyFocusNode = useFocusNode();
  40. final contactFocusNode = useFocusNode();
  41. final phoneFocusNode = useFocusNode();
  42. final addressFocusNode = useFocusNode();
  43. useEffect(() {
  44. //赋值State的值
  45. Future.microtask(() {
  46. companyController.text = state.formContentDetail.renovationCompany ?? "";
  47. contactController.text = state.formContentDetail.personInCharge ?? "";
  48. phoneController.text = state.formContentDetail.mobileNumber ?? "";
  49. addressController.text = state.formContentDetail.companyAddress ?? "";
  50. });
  51. return () {};
  52. }, []);
  53. return WillPopScope(
  54. child: Scaffold(
  55. appBar: MyAppBar.appBar(context, state.detailPage?['title']),
  56. backgroundColor: context.appColors.backgroundWhite,
  57. body: Column(
  58. crossAxisAlignment: CrossAxisAlignment.start,
  59. children: [
  60. SingleChildScrollView(
  61. scrollDirection: Axis.vertical,
  62. physics: const BouncingScrollPhysics(),
  63. child: Container(
  64. width: double.infinity,
  65. child: Column(
  66. mainAxisSize: MainAxisSize.max,
  67. crossAxisAlignment: CrossAxisAlignment.start,
  68. children: [
  69. //输入框 - 装修公司
  70. FormRequireText(
  71. text: S.current.renovation_company,
  72. textColor: context.appColors.textBlack,
  73. fontSize: 17,
  74. fontWeight: FontWeight.w500,
  75. ).marginOnly(top: 14, bottom: 16, left: 15, right: 15),
  76. // 表单
  77. _buildInputLayout(
  78. context,
  79. "company",
  80. enable: state.enableEdit,
  81. textInputType: TextInputType.text,
  82. textInputAction: TextInputAction.next,
  83. controller: companyController,
  84. focusNode: companyFocusNode,
  85. onSubmit: (formKey, value) {
  86. companyFocusNode.unfocus();
  87. FocusScope.of(context).requestFocus(contactFocusNode);
  88. },
  89. ),
  90. //输入框 - 联系人
  91. FormRequireText(
  92. text: S.current.person_in_charge,
  93. textColor: context.appColors.textBlack,
  94. fontSize: 17,
  95. fontWeight: FontWeight.w500,
  96. ).marginOnly(top: 14, bottom: 16, left: 15, right: 15),
  97. // 表单
  98. _buildInputLayout(
  99. context,
  100. "contact",
  101. enable: state.enableEdit,
  102. textInputType: TextInputType.text,
  103. textInputAction: TextInputAction.next,
  104. controller: contactController,
  105. focusNode: contactFocusNode,
  106. onSubmit: (formKey, value) {
  107. contactFocusNode.unfocus();
  108. FocusScope.of(context).requestFocus(phoneFocusNode);
  109. },
  110. ),
  111. //输入框 - 联系电话
  112. FormRequireText(
  113. text: S.current.mobile_phone,
  114. textColor: context.appColors.textBlack,
  115. fontSize: 17,
  116. fontWeight: FontWeight.w500,
  117. ).marginOnly(top: 14, bottom: 16, left: 15, right: 15),
  118. // 表单
  119. _buildInputLayout(
  120. context,
  121. "phone",
  122. enable: state.enableEdit,
  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: state.enableEdit,
  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. if (state.enableEdit) {
  199. String? renovationCompany = companyController.text;
  200. String? personInCharge = contactController.text;
  201. String? mobileNumber = phoneController.text;
  202. String? companyAddress = addressController.text;
  203. if (Utils.isEmpty(renovationCompany)) {
  204. ToastEngine.show("Enter Renovation Company");
  205. return;
  206. }
  207. if (Utils.isEmpty(personInCharge)) {
  208. ToastEngine.show("Enter Person In Charge");
  209. return;
  210. }
  211. if (Utils.isEmpty(mobileNumber)) {
  212. ToastEngine.show("Enter Mobile Number");
  213. return;
  214. }
  215. //存入本表单数据
  216. viewModel.updateFormContentDetail((content) {
  217. content.renovationCompany = renovationCompany;
  218. content.personInCharge = personInCharge;
  219. content.mobileNumber = mobileNumber;
  220. content.companyAddress = companyAddress;
  221. });
  222. }
  223. viewModel.gotoNextPage();
  224. },
  225. text: S.current.next,
  226. textColor: Colors.white,
  227. backgroundColor: context.appColors.btnBgDefault,
  228. fontWeight: FontWeight.w500,
  229. type: ClickType.throttle,
  230. fontSize: 16,
  231. minHeight: 50,
  232. radius: 0,
  233. ),
  234. ],
  235. )),
  236. onWillPop: () async {
  237. viewModel.handlePopAction();
  238. return true;
  239. });
  240. }
  241. Widget _buildInputLayout(
  242. BuildContext context,
  243. String key, {
  244. double marginTop = 0,
  245. bool? showRightIcon = false, //是否展示右侧的布局
  246. Widget? rightWidget, //右侧的布局
  247. TextInputType textInputType = TextInputType.text,
  248. String? errorText,
  249. bool obscureText = false,
  250. required TextEditingController controller,
  251. required FocusNode focusNode,
  252. bool enable = true,
  253. TextInputAction textInputAction = TextInputAction.done,
  254. Function? onSubmit,
  255. }) {
  256. return IgnoreKeyboardDismiss(
  257. child: MyTextField(
  258. key,
  259. fillBackgroundColor: context.appColors.authFiledBG,
  260. "",
  261. hintStyle: TextStyle(
  262. color: context.appColors.authFiledHint,
  263. fontSize: 16.0,
  264. fontWeight: FontWeight.w500,
  265. ),
  266. controller: controller,
  267. focusNode: focusNode,
  268. margin: EdgeInsets.only(top: marginTop, left: 15, right: 15),
  269. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 3),
  270. showDivider: false,
  271. height: 44,
  272. enabled: enable,
  273. style: TextStyle(
  274. color: context.appColors.authFiledText,
  275. fontSize: 16.0,
  276. fontWeight: FontWeight.w500,
  277. ),
  278. inputType: textInputType,
  279. textInputAction: textInputAction,
  280. onSubmit: onSubmit,
  281. cursorColor: context.appColors.authFiledText,
  282. obscureText: obscureText,
  283. errorText: errorText,
  284. showLeftIcon: true,
  285. showRightIcon: showRightIcon,
  286. rightWidget: rightWidget,
  287. ),
  288. );
  289. }
  290. }