facility_booking_page.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. selectedDate: state.selectedDate,
  65. onChangedSelectedDate: (dateTime) {
  66. Log.d("onChangedSelectedDate选中 - ${dateTime}}");
  67. viewModel.changeSelectedDate(dateTime);
  68. },
  69. ),
  70. ],
  71. ),
  72. ),
  73. );
  74. }
  75. //日期日历的选择器,底部弹窗选择
  76. void _datePickerBottomSheet(BuildContext context, WidgetRef ref) {
  77. final viewModel = ref.watch(facilityBookingViewModelProvider.notifier);
  78. final state = ref.watch(facilityBookingViewModelProvider);
  79. showModalBottomSheet<void>(
  80. context: context,
  81. isScrollControlled: true,
  82. shape: const RoundedRectangleBorder(
  83. borderRadius: BorderRadius.only(topLeft: Radius.circular(30.0), topRight: Radius.circular(30.0)),
  84. ),
  85. builder: (BuildContext context) {
  86. return CustomCalendarBottomSheet(
  87. firstDate: DateTime.now(),
  88. lastDate: DateTime.now().add(const Duration(days: 365)),
  89. selectedDate: state.selectedDate,
  90. locale: "en",
  91. onDateChange: (dateTime) {
  92. Navigator.pop(context);
  93. viewModel.changeSelectedDate(dateTime);
  94. },
  95. );
  96. },
  97. );
  98. }
  99. }