facility_booking_page.dart 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import 'dart:math';
  2. import 'package:cs_resources/generated/assets.dart';
  3. import 'package:cs_resources/theme/app_colors_theme.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:auto_route/auto_route.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/log_utils.dart';
  11. import 'package:widgets/ext/ex_widget.dart';
  12. import 'package:widgets/my_appbar.dart';
  13. import 'package:widgets/my_load_image.dart';
  14. import 'package:widgets/my_text_view.dart';
  15. import 'package:widgets/shatter/select_calendar/calendar_bottom_sheet.dart';
  16. import 'package:widgets/widget_export.dart';
  17. import '../../router/page/facility_page_router.dart';
  18. import 'facility_booking_view_model.dart';
  19. @RoutePage()
  20. class FacilityBookingPage extends HookConsumerWidget {
  21. const FacilityBookingPage({Key? key}) : super(key: key);
  22. //启动当前页面
  23. static void startInstance({BuildContext? context}) {
  24. if (context != null) {
  25. context.router.push(const FacilityBookingPageRoute());
  26. } else {
  27. appRouter.push(const FacilityBookingPageRoute());
  28. }
  29. }
  30. @override
  31. Widget build(BuildContext context, WidgetRef ref) {
  32. final viewModel = ref.watch(facilityBookingViewModelProvider.notifier);
  33. final state = ref.watch(facilityBookingViewModelProvider);
  34. return Scaffold(
  35. appBar: MyAppBar.appBar(context, "Kids party room", backgroundColor: context.appColors.whiteBG),
  36. backgroundColor: context.appColors.backgroundDark,
  37. body: SingleChildScrollView(
  38. scrollDirection: Axis.vertical,
  39. physics: const BouncingScrollPhysics(),
  40. child: Column(
  41. mainAxisSize: MainAxisSize.max,
  42. crossAxisAlignment: CrossAxisAlignment.center,
  43. children: [
  44. Row(
  45. mainAxisSize: MainAxisSize.max,
  46. children: [
  47. MyTextView(
  48. "${DateTimeUtils.getWeekday(state.selectedDate,languageCode: 'en')}, ${DateTimeUtils.formatDate(state.selectedDate,format: 'dd MMM yyyy')}",
  49. textColor: context.appColors.textBlack,
  50. fontSize: 17,
  51. marginTop: 18,
  52. marginBottom: 16,
  53. marginLeft: 15,
  54. isFontMedium: true,
  55. ).expanded(),
  56. const MyAssetImage(Assets.facilityConfirmDateIcon, width: 22.5, height: 22.5).marginOnly(right: 10).onTap(() {
  57. //日历日期选择器
  58. _datePickerBottomSheet(context, ref);
  59. }, padding: 5),
  60. ],
  61. ),
  62. //二周的日期选择
  63. WeeklyCalendar(
  64. isAutoSelect: false,
  65. selectedDate: state.selectedDate,
  66. onChangedSelectedDate: (dateTime) {
  67. Log.d("onChangedSelectedDate选中 - ${dateTime}}");
  68. viewModel.changeSelectedDate(dateTime);
  69. },
  70. onChangedPage: (dateTime, state) {
  71. Log.d("onChangedPage - ${dateTime} state:${state}");
  72. },
  73. ),
  74. ],
  75. ),
  76. ),
  77. );
  78. }
  79. //日期日历的选择器,底部弹窗选择
  80. void _datePickerBottomSheet(BuildContext context, WidgetRef ref) {
  81. final viewModel = ref.watch(facilityBookingViewModelProvider.notifier);
  82. final state = ref.watch(facilityBookingViewModelProvider);
  83. showModalBottomSheet<void>(
  84. context: context,
  85. isScrollControlled: true,
  86. shape: const RoundedRectangleBorder(
  87. borderRadius: BorderRadius.only(topLeft: Radius.circular(30.0), topRight: Radius.circular(30.0)),
  88. ),
  89. builder: (BuildContext context) {
  90. return CustomCalendarBottomSheet(
  91. firstDate: DateTime.now(),
  92. lastDate: DateTime.now().add(const Duration(days: 365)),
  93. selectedDate: state.selectedDate,
  94. locale: "en",
  95. onDateChange: (dateTime) {
  96. Navigator.pop(context);
  97. viewModel.changeSelectedDate(dateTime);
  98. },
  99. );
  100. },
  101. );
  102. }
  103. }