moving_date_page.dart 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 MovingDatePage extends HookConsumerWidget {
  21. const MovingDatePage({Key? key}) : super(key: key);
  22. //启动当前页面
  23. static void startInstance({BuildContext? context}) {
  24. if (context != null) {
  25. context.router.push(const MovingDatePageRoute());
  26. } else {
  27. appRouter.push(const MovingDatePageRoute());
  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.start_date_caps,
  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.startDate,
  68. onClick: () {
  69. viewModel.pickDate(null, (date) {
  70. viewModel.updateFormContentDetail((content) {
  71. content.startDate = DateTimeUtils.formatDate(date, format: 'yyyy-MM-dd');
  72. });
  73. });
  74. },
  75. ).marginOnly(left: 15, right: 15),
  76. //下拉选 - 结束时间
  77. FormRequireText(
  78. text: S.current.end_date_caps,
  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.endDate,
  87. onClick: () {
  88. viewModel.pickDate(null, (date) {
  89. viewModel.updateFormContentDetail((content) {
  90. content.endDate = DateTimeUtils.formatDate(date, format: 'yyyy-MM-dd');
  91. });
  92. });
  93. },
  94. ).marginOnly(left: 15, right: 15),
  95. //下拉选 - 到达时间
  96. MyTextView(
  97. S.current.time_of_arrival,
  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.timeOrArrival,
  109. onClick: () {
  110. viewModel.pickTime(null, (date) {
  111. viewModel.updateFormContentDetail((content) {
  112. content.timeOrArrival = DateTimeUtils.formatDate(date, format: 'HH:mm');
  113. });
  114. });
  115. },
  116. ).marginOnly(left: 15, right: 15),
  117. ],
  118. ),
  119. ),
  120. ).expanded(),
  121. //底部按钮
  122. MyButton(
  123. onPressed: () {
  124. if (state.enableEdit) {
  125. //校验数据
  126. final startDate = state.formContentDetail.startDate;
  127. final endDate = state.formContentDetail.endDate;
  128. if (Utils.isEmpty(startDate)) {
  129. ToastEngine.show("Select Start Date");
  130. return;
  131. }
  132. if (Utils.isEmpty(endDate)) {
  133. ToastEngine.show("Select End Date");
  134. return;
  135. }
  136. }
  137. viewModel.gotoNextPage();
  138. },
  139. text: S.current.next,
  140. textColor: Colors.white,
  141. backgroundColor: context.appColors.btnBgDefault,
  142. fontWeight: FontWeight.w500,
  143. type: ClickType.throttle,
  144. fontSize: 16,
  145. minHeight: 50,
  146. radius: 0,
  147. ),
  148. ],
  149. )),
  150. onWillPop: () async {
  151. viewModel.handlePopAction();
  152. return true;
  153. });
  154. }
  155. }