飞机票 日期选择页面完成

master
章文轩 4 years ago
parent f997352b7b
commit 677ff6074f

@ -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<ChooseTicketsTypePage> {
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<ChooseTicketsTypePage> {
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<ChooseTicketsTypePage> {
_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;
// },
// ),
// );
// }
}

@ -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<Month> extractWeeks(DateTime minDate, DateTime maxDate) {
DateTime weekMinDate = _findDayOfWeekInMonth(minDate, DateTime.monday);
DateTime weekMaxDate = _findDayOfWeekInMonth(maxDate, DateTime.sunday);

@ -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<CalendarVerticalWidget> {
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<CalendarVerticalWidget> {
),
),
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<CalendarVerticalWidget> {
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<CalendarVerticalWidget> {
.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<CalendarVerticalWidget> {
),
),
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,
),
),

@ -98,23 +98,22 @@ class _XiataCalendarWidgetState extends State<XiataCalendarWidget> {
? (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);
}

Loading…
Cancel
Save