From 677ff6074f6de640727df10cf1b2b10063270bcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=AB=A0=E6=96=87=E8=BD=A9?= <12812285557@qq.com> Date: Tue, 20 Jul 2021 09:30:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A3=9E=E6=9C=BA=E7=A5=A8=20=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E9=80=89=E6=8B=A9=E9=A1=B5=E9=9D=A2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../buy_tickets/choose_tickets_type_page.dart | 125 +++++------------- lib/utils/date/date_utils.dart | 21 +++ .../calendar/calendar_vertial_widget.dart | 31 ++--- .../calendar/xiata_calendar_widget.dart | 21 +-- 4 files changed, 81 insertions(+), 117 deletions(-) diff --git a/lib/pages/buy_tickets/choose_tickets_type_page.dart b/lib/pages/buy_tickets/choose_tickets_type_page.dart index d029bc3..a0e4bb5 100644 --- a/lib/pages/buy_tickets/choose_tickets_type_page.dart +++ b/lib/pages/buy_tickets/choose_tickets_type_page.dart @@ -7,6 +7,7 @@ import 'package:get/get.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:recook/constants/styles.dart'; import 'package:recook/utils/permission_tool.dart'; +import 'package:recook/widgets/alert.dart'; import 'package:recook/widgets/calendar/calendar_vertial_widget.dart'; import 'package:recook/widgets/custom_app_bar.dart'; import 'package:recook/constants/header.dart'; @@ -362,10 +363,13 @@ class _ChooseTicketsTypePageState extends State { children: [ 40.wb, GestureDetector( - onTap: () { - _date = _date.add(new Duration(days: -1)); - setState(() {}); - }, + onTap: _date.day != DateTime.now().day + ? () { + _date = _date.add(new Duration(days: -1)); + + setState(() {}); + } + : () {}, child: Container( color: Colors.transparent, alignment: Alignment.center, @@ -455,6 +459,33 @@ class _ChooseTicketsTypePageState extends State { fontSize: 16 * 2.sp, borderRadius: BorderRadius.all(Radius.circular(2)), onPressed: () { + if (_originText == '出发地' || _originText == null || _date == null) { + Alert.show( + context, + NormalTextDialog( + type: NormalTextDialogType.normal, + title: "提示", + content: "请您先选择出发地", + items: ["确认"], + listener: (index) { + Alert.dismiss(context); + }, + )); + } else if (_destinationText == '选择到达' || _destinationText == null) { + Alert.show( + context, + NormalTextDialog( + type: NormalTextDialogType.normal, + title: "提示", + content: "请您先选择目的地", + items: ["确认"], + listener: (index) { + Alert.dismiss(context); + }, + )); + } else { + Get.to(); + } print('查询'); }, ), @@ -464,96 +495,10 @@ class _ChooseTicketsTypePageState extends State { _dateWidget() { return CalendarVerticalWidget( startDay: _date, - //endDay: _date, callBack: (BuildContext context, DateTime start) { _date = start; setState(() {}); }, ); } - - // _dateWidget() { - // return Container( - // height: 448.rw, - // color: Colors.white, - // child: TableCalendar( - // //availableGestures: (AvailableGestures.verticalSwipe), - // calendarBuilders: CalendarBuilders(), - // daysOfWeekHeight: 20.rw, - // locale: 'zh_CN', - // headerStyle: HeaderStyle( - // titleTextStyle: TextStyle( - // color: Colors.black, - // fontSize: 20.0, - // ), - // titleCentered: true, - // leftChevronVisible: true, - // rightChevronVisible: true, - // formatButtonVisible: false, - // ), - // rangeStartDay: DateTime.utc(2021, 7, 16), - // rangeEndDay: DateTime.utc(2021, 8, 15), - // calendarStyle: CalendarStyle( - // defaultTextStyle: TextStyle( - // color: Color(0xFFCCCCCC), - // fontSize: 16.0, - // ), - - // weekendTextStyle: TextStyle( - // color: Color(0xFFCCCCCC), - // fontSize: 16.0, - // ), - // rangeHighlightColor: Colors.transparent, - // rangeStartDecoration: (BoxDecoration(color: Colors.transparent)), - // rangeStartTextStyle: TextStyle( - // color: Colors.black, - // fontSize: 16.0, - // ), - // rangeEndTextStyle: TextStyle( - // color: Colors.black, - // fontSize: 16.0, - // ), - // withinRangeTextStyle: TextStyle( - // color: Colors.black, - // fontSize: 16.0, - // ), - // outsideDaysVisible: false, - // todayTextStyle: TextStyle( - // color: Colors.blue, - // fontSize: 26.0, - // ), - // // disabledTextStyle: TextStyle( - // // color: Color(0xFFCCCCCC), - // // fontSize: 16.0, - // // ), - // ), - // firstDay: DateTime.utc(2021, 6, 1), - // lastDay: DateTime.utc(2021, 8, 1), - // focusedDay: _date, - // selectedDayPredicate: (day) { - // return isSameDay(_selectedDay, day); - // }, - // onDaySelected: (selectedDay, focusedDay) { - // if (!isSameDay(_selectedDay, selectedDay)) { - // setState(() { - // _selectedDay = selectedDay; - // _date = focusedDay; // update `_focusedDay` here as well - // }); - // } - // }, - // onFormatChanged: (format) { - // if (_calendarFormat != format) { - // // Call `setState()` when updating calendar format - // setState(() { - // _calendarFormat = format; - // }); - // } - // }, - // onPageChanged: (focusedDay) { - // // No need to call `setState()` here - // _date = focusedDay; - // }, - // ), - // ); - // } } diff --git a/lib/utils/date/date_utils.dart b/lib/utils/date/date_utils.dart index 1ed2929..e22aaa9 100644 --- a/lib/utils/date/date_utils.dart +++ b/lib/utils/date/date_utils.dart @@ -1,6 +1,27 @@ import 'package:recook/utils/date/date_models.dart'; class DateUtilss { + static bool sameDay(DateTime day, DateTime diffDay) { + return (day.year == diffDay.year && + day.month == diffDay.month && + day.day == diffDay.day); + } + + static bool sameYear(DateTime day, DateTime diffDay) { + return (day.year == diffDay.year); + } + + static int monthBetween(DateTime day, DateTime diffDay) { + return (diffDay.month + 12 - day.month) % 12; + } + + static int countDays(DateTime day, DateTime diffDay) { + return DateTime.fromMillisecondsSinceEpoch( + (diffDay.millisecondsSinceEpoch - day.millisecondsSinceEpoch)) + .day - + 1; + } + static List extractWeeks(DateTime minDate, DateTime maxDate) { DateTime weekMinDate = _findDayOfWeekInMonth(minDate, DateTime.monday); DateTime weekMaxDate = _findDayOfWeekInMonth(maxDate, DateTime.sunday); diff --git a/lib/widgets/calendar/calendar_vertial_widget.dart b/lib/widgets/calendar/calendar_vertial_widget.dart index ac689e3..482a6bb 100644 --- a/lib/widgets/calendar/calendar_vertial_widget.dart +++ b/lib/widgets/calendar/calendar_vertial_widget.dart @@ -14,7 +14,6 @@ class CalendarVerticalWidget extends StatefulWidget { CalendarVerticalWidget({ Key key, @required this.startDay, - //@required this.endDay, @required this.callBack, }) : super(key: key); @@ -34,7 +33,7 @@ class _CalendarVerticalWidgetState extends State { borderRadius: BorderRadius.vertical(top: Radius.circular(8.rw)), child: Material( child: Container( - height: 448.rw, + height: 484.rw, decoration: BoxDecoration( color: Colors.white, ), @@ -71,7 +70,7 @@ class _CalendarVerticalWidgetState extends State { ), ), Container( - height: 44.rw, + height: 34.rw, alignment: Alignment.center, padding: EdgeInsets.symmetric(horizontal: 16.rw), child: DefaultTextStyle( @@ -101,7 +100,7 @@ class _CalendarVerticalWidgetState extends State { 1, ), maxDate: DateTime.now().add(Duration(days: 365)), - // initialMinDate: appProvider.checkInDate, + initialMinDate: widget.startDay, // initialMaxDate: appProvider.checkOutDate, onRangeSelected: (minDate) { _firstDay = minDate; @@ -175,16 +174,14 @@ class _CalendarVerticalWidgetState extends State { .add(Duration(days: 30)) .millisecondsSinceEpoch; return Opacity( - opacity: isBeforeToday || isIn30Days ? 0.6 : 1, + opacity: isBeforeToday || isIn30Days ? 0.2 : 1, child: Container( padding: EdgeInsets.symmetric( horizontal: 2.rw, ), - color: - isSelected ? Color(0xFFECF4FF) : Colors.transparent, child: Container( decoration: BoxDecoration( - borderRadius: BorderRadius.all(Radius.circular(10)), + borderRadius: BorderRadius.all(Radius.circular(5)), color: isSelected ? Color(0xFF0086F5) : Colors.white, ), @@ -203,25 +200,25 @@ class _CalendarVerticalWidgetState extends State { ), ), Text( - isToday ? '今天' : date.day.toString(), + date.day.toString(), maxLines: 1, overflow: TextOverflow.visible, style: TextStyle( fontWeight: FontWeight.w500, - fontSize: isToday ? 14.rsp : 18.rsp, - color: DateUtil.sameDay(date, _firstDay) - ? Colors.white - : Colors.black, + fontSize: 18.rsp, + color: + isSelected ? Colors.white : Colors.black, height: 1, ), ), Text( - DateModel.fromDateTime(date).lunarString, + isToday + ? '今天' + : DateModel.fromDateTime(date).lunarString, style: TextStyle( fontSize: 10.rsp, - color: DateUtil.sameDay(date, _firstDay) - ? Colors.white - : Colors.black, + color: + isSelected ? Colors.white : Colors.black, height: 1, ), ), diff --git a/lib/widgets/calendar/xiata_calendar_widget.dart b/lib/widgets/calendar/xiata_calendar_widget.dart index 29f72bf..55499d6 100644 --- a/lib/widgets/calendar/xiata_calendar_widget.dart +++ b/lib/widgets/calendar/xiata_calendar_widget.dart @@ -98,23 +98,22 @@ class _XiataCalendarWidgetState extends State { ? (DateTime date) { if (rangeMinDate == null) { setState(() { + print(rangeMinDate); + print('1111'); rangeMinDate = date; //rangeMaxDate = null; }); - } else if (date - .isAfter(rangeMinDate.add(Duration(days: 30)))) { - } else if (date.isBefore(rangeMinDate)) { - setState(() { - //rangeMaxDate = rangeMinDate; - rangeMinDate = date; - }); - } else if (date.isAfter(rangeMinDate)) { + } else { setState(() { + print(rangeMinDate); + print('2222'); //rangeMaxDate = date; + rangeMinDate = date; }); } - // widget.onRangeSelected(rangeMinDate); + //弹窗自动隐藏判断 + widget.onRangeSelected(rangeMinDate); if (widget.onDayPressed != null) { widget.onDayPressed(date); @@ -185,10 +184,12 @@ class _MonthView extends StatelessWidget { return const SizedBox(); } else { bool isSelected = false; + print(day); + print(rangeMinDate); if (rangeFeatureEnabled) { if (rangeMinDate != null) { - isSelected = day.isSameDayOrAfter(rangeMinDate); + isSelected = day.isSameDay(rangeMinDate); } else { isSelected = day.isAtSameMomentAs(rangeMinDate); }