renovation_date_page.dart 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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/date_time_utils.dart';
  10. import 'package:shared/utils/util.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_text_view.dart';
  15. import 'package:widgets/shatter/form_require_text.dart';
  16. import 'package:widgets/shatter/picker_container.dart';
  17. import '../../router/page/form_page_router.dart';
  18. import 'vm/apply_view_model.dart';
  19. @RoutePage()
  20. class RenovationDatePage extends HookConsumerWidget {
  21. const RenovationDatePage({Key? key}) : super(key: key);
  22. //启动当前页面
  23. static void startInstance({BuildContext? context}) {
  24. if (context != null) {
  25. context.router.push(const RenovationDatePageRoute());
  26. } else {
  27. appRouter.push(const RenovationDatePageRoute());
  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. useEffect(() {
  35. //赋值State的值
  36. Future.microtask(() {});
  37. return () {
  38. // 组件卸载时执行
  39. };
  40. }, []);
  41. return WillPopScope(
  42. child: Scaffold(
  43. appBar: MyAppBar.appBar(context, state.detailPage?['title']),
  44. backgroundColor: context.appColors.backgroundWhite,
  45. body: Column(
  46. crossAxisAlignment: CrossAxisAlignment.start,
  47. children: [
  48. SingleChildScrollView(
  49. scrollDirection: Axis.vertical,
  50. physics: const BouncingScrollPhysics(),
  51. child: Container(
  52. width: double.infinity,
  53. child: Column(
  54. mainAxisSize: MainAxisSize.max,
  55. crossAxisAlignment: CrossAxisAlignment.start,
  56. children: [
  57. //下拉选 - 开始时间
  58. FormRequireText(
  59. text: S.current.renovation_start_date,
  60. textColor: context.appColors.textBlack,
  61. fontSize: 17,
  62. fontWeight: FontWeight.w500,
  63. ).marginOnly(top: 30, bottom: 16, left: 15, right: 15),
  64. PickerContainer(
  65. hint: S.current.choose_date,
  66. enable: state.enableEdit,
  67. content: state.formContentDetail.renovationStartDate,
  68. onClick: () {
  69. viewModel.pickDate(null, (date) {
  70. viewModel.updateFormContentDetail((content) {
  71. content.renovationStartDate = DateTimeUtils.formatDate(date, format: 'yyyy-MM-dd');
  72. });
  73. });
  74. },
  75. ).marginOnly(left: 15, right: 15),
  76. //下拉选 - 结束时间
  77. FormRequireText(
  78. text: S.current.renovation_end_date,
  79. textColor: context.appColors.textBlack,
  80. fontSize: 17,
  81. fontWeight: FontWeight.w500,
  82. ).marginOnly(top: 14, bottom: 16, left: 15, right: 15),
  83. PickerContainer(
  84. hint: S.current.choose_date,
  85. enable: state.enableEdit,
  86. content: state.formContentDetail.renovationEndDate,
  87. onClick: () {
  88. viewModel.pickDate(null, (date) {
  89. viewModel.updateFormContentDetail((content) {
  90. content.renovationEndDate = DateTimeUtils.formatDate(date, format: 'yyyy-MM-dd');
  91. });
  92. });
  93. },
  94. ).marginOnly(left: 15, right: 15),
  95. //下拉选 - 施工时间开始时间
  96. MyTextView(
  97. S.current.hacking_start_date,
  98. fontSize: 17,
  99. marginTop: 14,
  100. marginLeft: 15,
  101. marginBottom: 16,
  102. isFontMedium: true,
  103. textColor: context.appColors.textBlack,
  104. ),
  105. PickerContainer(
  106. hint: S.current.choose_date,
  107. enable: state.enableEdit,
  108. content: state.formContentDetail.hackingStartDate,
  109. onClick: () {
  110. viewModel.pickDate(null, (date) {
  111. viewModel.updateFormContentDetail((content) {
  112. content.hackingStartDate = DateTimeUtils.formatDate(date, format: 'yyyy-MM-dd');
  113. });
  114. });
  115. },
  116. ).marginOnly(left: 15, right: 15),
  117. //下拉选 - 施工时间结束时间
  118. MyTextView(
  119. S.current.hacking_end_date,
  120. fontSize: 17,
  121. marginTop: 14,
  122. marginLeft: 15,
  123. marginBottom: 16,
  124. isFontMedium: true,
  125. textColor: context.appColors.textBlack,
  126. ),
  127. PickerContainer(
  128. hint: S.current.choose_date,
  129. enable: state.enableEdit,
  130. content: state.formContentDetail.hackingEndDate,
  131. onClick: () {
  132. viewModel.pickDate(null, (date) {
  133. viewModel.updateFormContentDetail((content) {
  134. content.hackingEndDate = DateTimeUtils.formatDate(date, format: 'yyyy-MM-dd');
  135. });
  136. });
  137. },
  138. ).marginOnly(left: 15, right: 15),
  139. ],
  140. ),
  141. ),
  142. ).expanded(),
  143. //底部按钮
  144. MyButton(
  145. onPressed: () {
  146. if (state.enableEdit) {
  147. //校验数据
  148. final startDate = state.formContentDetail.renovationEndDate;
  149. final endDate = state.formContentDetail.renovationEndDate;
  150. if (Utils.isEmpty(startDate)) {
  151. ToastEngine.show("Select Renovation Start Date");
  152. return;
  153. }
  154. if (Utils.isEmpty(endDate)) {
  155. ToastEngine.show("Select Renovation End Date");
  156. return;
  157. }
  158. }
  159. viewModel.gotoNextPage();
  160. },
  161. text: S.current.next,
  162. textColor: Colors.white,
  163. backgroundColor: context.appColors.btnBgDefault,
  164. fontWeight: FontWeight.w500,
  165. type: ClickType.throttle,
  166. fontSize: 16,
  167. minHeight: 50,
  168. radius: 0,
  169. ),
  170. ],
  171. )),
  172. onWillPop: () async {
  173. viewModel.handlePopAction();
  174. return true;
  175. });
  176. }
  177. }