|
|
|
@ -22,17 +22,17 @@ class CalendarController {
|
|
|
|
|
static const Map<DateModel, Object> EMPTY_MAP = {};
|
|
|
|
|
static const Duration DEFAULT_DURATION = const Duration(milliseconds: 500);
|
|
|
|
|
|
|
|
|
|
CalendarConfiguration calendarConfiguration;
|
|
|
|
|
late CalendarConfiguration calendarConfiguration;
|
|
|
|
|
|
|
|
|
|
CalendarProvider calendarProvider = CalendarProvider();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 下面的信息不是配置的
|
|
|
|
|
*/
|
|
|
|
|
List<DateModel> monthList = new List(); //月份list
|
|
|
|
|
List<DateModel> weekList = new List(); //星期list
|
|
|
|
|
PageController monthController; //月份的controller
|
|
|
|
|
PageController weekController; //星期的controller
|
|
|
|
|
List<DateModel> monthList = []; //月份list
|
|
|
|
|
List<DateModel> weekList = []; //星期list
|
|
|
|
|
PageController? monthController; //月份的controller
|
|
|
|
|
PageController? weekController; //星期的controller
|
|
|
|
|
|
|
|
|
|
CalendarController(
|
|
|
|
|
{CalendarSelectedMode selectMode = CalendarSelectedMode.singleSelect,
|
|
|
|
@ -41,8 +41,8 @@ class CalendarController {
|
|
|
|
|
int maxYear = 2055,
|
|
|
|
|
int minYearMonth = 1,
|
|
|
|
|
int maxYearMonth = 12,
|
|
|
|
|
int nowYear,
|
|
|
|
|
int nowMonth,
|
|
|
|
|
int? nowYear,
|
|
|
|
|
int? nowMonth,
|
|
|
|
|
int minSelectYear = 1971,
|
|
|
|
|
int minSelectMonth = 1,
|
|
|
|
|
int minSelectDay = 1,
|
|
|
|
@ -50,7 +50,7 @@ class CalendarController {
|
|
|
|
|
int maxSelectMonth = 12,
|
|
|
|
|
int maxSelectDay = 30,
|
|
|
|
|
Set<DateTime> selectedDateTimeList = EMPTY_SET, //多选模式下,默认选中的item列表
|
|
|
|
|
DateModel selectDateModel, //单选模式下,默认选中的item
|
|
|
|
|
DateModel? selectDateModel, //单选模式下,默认选中的item
|
|
|
|
|
int maxMultiSelectCount = 9999,
|
|
|
|
|
Map<DateModel, Object> extraDataMap = EMPTY_MAP,
|
|
|
|
|
int offset = 0 // 首日偏移量
|
|
|
|
@ -84,8 +84,8 @@ class CalendarController {
|
|
|
|
|
selectDateModel: selectDateModel,
|
|
|
|
|
offset: offset);
|
|
|
|
|
|
|
|
|
|
calendarConfiguration.defaultSelectedDateList = new HashSet<DateModel>();
|
|
|
|
|
calendarConfiguration.defaultSelectedDateList
|
|
|
|
|
calendarConfiguration.defaultSelectedDateList = new HashSet<DateModel?>();
|
|
|
|
|
calendarConfiguration.defaultSelectedDateList!
|
|
|
|
|
.addAll(selectedDateTimeList.map((dateTime) {
|
|
|
|
|
return DateModel.fromDateTime(dateTime);
|
|
|
|
|
}).toSet());
|
|
|
|
@ -94,13 +94,13 @@ class CalendarController {
|
|
|
|
|
calendarProvider.selectedDateList =
|
|
|
|
|
calendarConfiguration.defaultSelectedDateList;
|
|
|
|
|
calendarConfiguration.minSelectDate = DateModel.fromDateTime(DateTime(
|
|
|
|
|
calendarConfiguration.minSelectYear,
|
|
|
|
|
calendarConfiguration.minSelectMonth,
|
|
|
|
|
calendarConfiguration.minSelectDay));
|
|
|
|
|
calendarConfiguration.minSelectYear!,
|
|
|
|
|
calendarConfiguration.minSelectMonth!,
|
|
|
|
|
calendarConfiguration.minSelectDay!));
|
|
|
|
|
calendarConfiguration.maxSelectDate = DateModel.fromDateTime(DateTime(
|
|
|
|
|
calendarConfiguration.maxSelectYear,
|
|
|
|
|
calendarConfiguration.maxSelectMonth,
|
|
|
|
|
calendarConfiguration.maxSelectDay));
|
|
|
|
|
calendarConfiguration.maxSelectYear!,
|
|
|
|
|
calendarConfiguration.maxSelectMonth!,
|
|
|
|
|
calendarConfiguration.maxSelectDay!));
|
|
|
|
|
|
|
|
|
|
LogUtil.log(
|
|
|
|
|
TAG: this.runtimeType,
|
|
|
|
@ -116,24 +116,24 @@ class CalendarController {
|
|
|
|
|
void _weekAndMonthViewChange(
|
|
|
|
|
int showMode,
|
|
|
|
|
) {
|
|
|
|
|
int minYear = calendarConfiguration.minYear;
|
|
|
|
|
int maxYear = calendarConfiguration.maxYear;
|
|
|
|
|
int minYearMonth = calendarConfiguration.minYearMonth;
|
|
|
|
|
int maxYearMonth = calendarConfiguration.maxYearMonth;
|
|
|
|
|
int nowYear = calendarConfiguration.nowYear;
|
|
|
|
|
int nowMonth = calendarConfiguration.nowMonth;
|
|
|
|
|
int? minYear = calendarConfiguration.minYear;
|
|
|
|
|
int? maxYear = calendarConfiguration.maxYear;
|
|
|
|
|
int? minYearMonth = calendarConfiguration.minYearMonth;
|
|
|
|
|
int? maxYearMonth = calendarConfiguration.maxYearMonth;
|
|
|
|
|
int? nowYear = calendarConfiguration.nowYear;
|
|
|
|
|
int? nowMonth = calendarConfiguration.nowMonth;
|
|
|
|
|
|
|
|
|
|
if (showMode != CalendarConstants.MODE_SHOW_ONLY_WEEK) {
|
|
|
|
|
//初始化pageController,initialPage默认是当前时间对于的页面
|
|
|
|
|
int initialPage = 0;
|
|
|
|
|
int nowMonthIndex = 0;
|
|
|
|
|
monthList.clear();
|
|
|
|
|
for (int i = minYear; i <= maxYear; i++) {
|
|
|
|
|
for (int i = minYear!; i <= maxYear!; i++) {
|
|
|
|
|
for (int j = 1; j <= 12; j++) {
|
|
|
|
|
if (i == minYear && j < minYearMonth) {
|
|
|
|
|
if (i == minYear && j < minYearMonth!) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (i == maxYear && j > maxYearMonth) {
|
|
|
|
|
if (i == maxYear && j > maxYearMonth!) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
DateModel dateModel = new DateModel();
|
|
|
|
@ -166,13 +166,13 @@ class CalendarController {
|
|
|
|
|
nowYear = DateTime.now().year;
|
|
|
|
|
nowMonth = DateTime.now().month;
|
|
|
|
|
}
|
|
|
|
|
DateTime nowTime = new DateTime(nowYear, nowMonth, 15);
|
|
|
|
|
DateTime firstDayOfMonth = DateTime(minYear, minYearMonth, 1);
|
|
|
|
|
DateTime nowTime = new DateTime(nowYear!, nowMonth!, 15);
|
|
|
|
|
DateTime firstDayOfMonth = DateTime(minYear!, minYearMonth!, 1);
|
|
|
|
|
//计算第一个星期的第一天的日期
|
|
|
|
|
DateTime firstWeekDate =
|
|
|
|
|
firstDayOfMonth.add(Duration(days: -(firstDayOfMonth.weekday - 1)));
|
|
|
|
|
|
|
|
|
|
DateTime lastDay = DateTime(maxYear, maxYearMonth,
|
|
|
|
|
DateTime lastDay = DateTime(maxYear!, maxYearMonth!,
|
|
|
|
|
DateUtil.getMonthDaysCount(maxYear, maxYearMonth));
|
|
|
|
|
int temp = -1;
|
|
|
|
|
for (DateTime dateTime = firstWeekDate;
|
|
|
|
@ -210,13 +210,13 @@ class CalendarController {
|
|
|
|
|
|
|
|
|
|
//周视图切换
|
|
|
|
|
void addWeekChangeListener(OnWeekChange listener) {
|
|
|
|
|
this.calendarConfiguration.weekChangeListeners.add(listener);
|
|
|
|
|
this.calendarConfiguration.weekChangeListeners!.add(listener);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//月份切换监听
|
|
|
|
|
void addMonthChangeListener(OnMonthChange listener) {
|
|
|
|
|
// this.calendarConfiguration.monthChange = listener;
|
|
|
|
|
this.calendarConfiguration.monthChangeListeners.add(listener);
|
|
|
|
|
this.calendarConfiguration.monthChangeListeners!.add(listener);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//点击选择监听
|
|
|
|
@ -263,7 +263,7 @@ class CalendarController {
|
|
|
|
|
//可以动态修改默认选中的item。
|
|
|
|
|
void changeDefaultSelectedDateList(Set<DateModel> defaultSelectedDateList) {
|
|
|
|
|
this.calendarConfiguration.defaultSelectedDateList =
|
|
|
|
|
defaultSelectedDateList;
|
|
|
|
|
defaultSelectedDateList as HashSet<DateModel?>?;
|
|
|
|
|
this.calendarProvider.generation.value++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -280,13 +280,13 @@ class CalendarController {
|
|
|
|
|
if (calendarProvider.expandStatus.value == true) {
|
|
|
|
|
//月视图
|
|
|
|
|
int currentIndex =
|
|
|
|
|
calendarProvider.calendarConfiguration.monthController.page.toInt();
|
|
|
|
|
calendarProvider.calendarConfiguration!.monthController!.page!.toInt();
|
|
|
|
|
if (currentIndex == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
calendarProvider.calendarConfiguration.monthController
|
|
|
|
|
calendarProvider.calendarConfiguration!.monthController!
|
|
|
|
|
.previousPage(duration: DEFAULT_DURATION, curve: Curves.ease);
|
|
|
|
|
calendarProvider.calendarConfiguration.monthChangeListeners
|
|
|
|
|
calendarProvider.calendarConfiguration!.monthChangeListeners!
|
|
|
|
|
.forEach((listener) {
|
|
|
|
|
listener(monthList[currentIndex - 1].year,
|
|
|
|
|
monthList[currentIndex - 1].month);
|
|
|
|
@ -301,11 +301,11 @@ class CalendarController {
|
|
|
|
|
} else {
|
|
|
|
|
//周视图
|
|
|
|
|
int currentIndex =
|
|
|
|
|
calendarProvider.calendarConfiguration.weekController.page.toInt();
|
|
|
|
|
calendarProvider.calendarConfiguration!.weekController!.page!.toInt();
|
|
|
|
|
if (currentIndex == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
calendarProvider.calendarConfiguration.weekController
|
|
|
|
|
calendarProvider.calendarConfiguration!.weekController!
|
|
|
|
|
.previousPage(duration: DEFAULT_DURATION, curve: Curves.ease);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -321,13 +321,13 @@ class CalendarController {
|
|
|
|
|
if (calendarProvider.expandStatus.value == true) {
|
|
|
|
|
//月视图
|
|
|
|
|
int currentIndex =
|
|
|
|
|
calendarProvider.calendarConfiguration.monthController.page.toInt();
|
|
|
|
|
calendarProvider.calendarConfiguration!.monthController!.page!.toInt();
|
|
|
|
|
if (monthList.length - 1 == currentIndex) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
calendarProvider.calendarConfiguration.monthController
|
|
|
|
|
calendarProvider.calendarConfiguration!.monthController!
|
|
|
|
|
.nextPage(duration: DEFAULT_DURATION, curve: Curves.ease);
|
|
|
|
|
calendarProvider.calendarConfiguration.monthChangeListeners
|
|
|
|
|
calendarProvider.calendarConfiguration!.monthChangeListeners!
|
|
|
|
|
.forEach((listener) {
|
|
|
|
|
listener(monthList[currentIndex + 1].year,
|
|
|
|
|
monthList[currentIndex + 1].month);
|
|
|
|
@ -343,11 +343,11 @@ class CalendarController {
|
|
|
|
|
} else {
|
|
|
|
|
//周视图
|
|
|
|
|
int currentIndex =
|
|
|
|
|
calendarProvider.calendarConfiguration.weekController.page.toInt();
|
|
|
|
|
calendarProvider.calendarConfiguration!.weekController!.page!.toInt();
|
|
|
|
|
if (weekList.length - 1 == currentIndex) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
calendarProvider.calendarConfiguration.weekController
|
|
|
|
|
calendarProvider.calendarConfiguration!.weekController!
|
|
|
|
|
.nextPage(duration: DEFAULT_DURATION, curve: Curves.ease);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
@ -366,15 +366,15 @@ class CalendarController {
|
|
|
|
|
if (targetPage == -1) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (calendarProvider.calendarConfiguration.monthController.hasClients ==
|
|
|
|
|
if (calendarProvider.calendarConfiguration!.monthController!.hasClients ==
|
|
|
|
|
false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (needAnimation) {
|
|
|
|
|
calendarProvider.calendarConfiguration.monthController
|
|
|
|
|
calendarProvider.calendarConfiguration!.monthController!
|
|
|
|
|
.animateToPage(targetPage, duration: duration, curve: curve);
|
|
|
|
|
} else {
|
|
|
|
|
calendarProvider.calendarConfiguration.monthController
|
|
|
|
|
calendarProvider.calendarConfiguration!.monthController!
|
|
|
|
|
.jumpToPage(targetPage);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -389,15 +389,15 @@ class CalendarController {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (calendarProvider.calendarConfiguration.weekController.hasClients ==
|
|
|
|
|
if (calendarProvider.calendarConfiguration!.weekController!.hasClients ==
|
|
|
|
|
false) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (needAnimation) {
|
|
|
|
|
calendarProvider.calendarConfiguration.weekController
|
|
|
|
|
calendarProvider.calendarConfiguration!.weekController!
|
|
|
|
|
.animateToPage(targetPage, duration: duration, curve: curve);
|
|
|
|
|
} else {
|
|
|
|
|
calendarProvider.calendarConfiguration.weekController
|
|
|
|
|
calendarProvider.calendarConfiguration!.weekController!
|
|
|
|
|
.jumpToPage(targetPage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -409,7 +409,7 @@ class CalendarController {
|
|
|
|
|
Duration duration = const Duration(milliseconds: 500),
|
|
|
|
|
Curve curve = Curves.ease}) {
|
|
|
|
|
DateTime targetDateTime = monthList[calendarProvider
|
|
|
|
|
.calendarConfiguration.monthController.page
|
|
|
|
|
.calendarConfiguration!.monthController!.page!
|
|
|
|
|
.toInt() +
|
|
|
|
|
12]
|
|
|
|
|
.getDateTime();
|
|
|
|
@ -424,7 +424,7 @@ class CalendarController {
|
|
|
|
|
Duration duration = const Duration(milliseconds: 500),
|
|
|
|
|
Curve curve = Curves.ease}) {
|
|
|
|
|
DateTime targetDateTime = monthList[calendarProvider
|
|
|
|
|
.calendarConfiguration.monthController.page
|
|
|
|
|
.calendarConfiguration!.monthController!.page!
|
|
|
|
|
.toInt() -
|
|
|
|
|
12]
|
|
|
|
|
.getDateTime();
|
|
|
|
@ -440,30 +440,30 @@ class CalendarController {
|
|
|
|
|
Curve curve = Curves.ease}) {
|
|
|
|
|
// 如果当前显示的是周视图的话,需要计算出第一个月的index后,调用weekController
|
|
|
|
|
if (calendarProvider.expandStatus.value == false) {
|
|
|
|
|
int currentMonth = weekList[calendarProvider
|
|
|
|
|
.calendarConfiguration.weekController.page
|
|
|
|
|
int? currentMonth = weekList[calendarProvider
|
|
|
|
|
.calendarConfiguration!.weekController!.page!
|
|
|
|
|
.toInt()]
|
|
|
|
|
.month;
|
|
|
|
|
for (int i = calendarProvider.calendarConfiguration.weekController.page
|
|
|
|
|
for (int i = calendarProvider.calendarConfiguration!.weekController!.page!
|
|
|
|
|
.toInt();
|
|
|
|
|
i < weekList.length;
|
|
|
|
|
i++) {
|
|
|
|
|
if (weekList[i].month != currentMonth) {
|
|
|
|
|
calendarProvider.calendarConfiguration.weekController.jumpToPage(i);
|
|
|
|
|
calendarProvider.calendarConfiguration!.weekController!.jumpToPage(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((calendarProvider.calendarConfiguration.monthController.page.toInt() +
|
|
|
|
|
if ((calendarProvider.calendarConfiguration!.monthController!.page!.toInt() +
|
|
|
|
|
1) >=
|
|
|
|
|
monthList.length) {
|
|
|
|
|
LogUtil.log(TAG: this.runtimeType, message: "moveToNextMonth:当前是最后一个月份");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DateTime targetDateTime = monthList[calendarProvider
|
|
|
|
|
.calendarConfiguration.monthController.page
|
|
|
|
|
.calendarConfiguration!.monthController!.page!
|
|
|
|
|
.toInt() +
|
|
|
|
|
1]
|
|
|
|
|
.getDateTime();
|
|
|
|
@ -479,30 +479,30 @@ class CalendarController {
|
|
|
|
|
Curve curve = Curves.ease}) {
|
|
|
|
|
// 如果当前显示的是周视图的话,需要计算出第一个月的index后,调用weekController
|
|
|
|
|
if (calendarProvider.expandStatus.value == false) {
|
|
|
|
|
int currentMonth = weekList[weekController.page.toInt()].month;
|
|
|
|
|
for (int i = calendarProvider.calendarConfiguration.weekController.page
|
|
|
|
|
int? currentMonth = weekList[weekController!.page!.toInt()].month;
|
|
|
|
|
for (int i = calendarProvider.calendarConfiguration!.weekController!.page!
|
|
|
|
|
.toInt();
|
|
|
|
|
i >= 0;
|
|
|
|
|
i--) {
|
|
|
|
|
if (weekList[i].month != currentMonth &&
|
|
|
|
|
weekList[i].isAfter(DateModel.fromDateTime(DateTime(
|
|
|
|
|
calendarConfiguration.minYear,
|
|
|
|
|
calendarConfiguration.minYearMonth)))) {
|
|
|
|
|
calendarProvider.calendarConfiguration.weekController.jumpToPage(i);
|
|
|
|
|
calendarConfiguration.minYear!,
|
|
|
|
|
calendarConfiguration.minYearMonth!)))) {
|
|
|
|
|
calendarProvider.calendarConfiguration!.weekController!.jumpToPage(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((calendarProvider.calendarConfiguration.monthController.page.toInt()) ==
|
|
|
|
|
if ((calendarProvider.calendarConfiguration!.monthController!.page!.toInt()) ==
|
|
|
|
|
0) {
|
|
|
|
|
LogUtil.log(
|
|
|
|
|
TAG: this.runtimeType, message: "moveToPreviousMonth:当前是第一个月份");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DateTime targetDateTime = monthList[calendarProvider
|
|
|
|
|
.calendarConfiguration.monthController.page
|
|
|
|
|
.calendarConfiguration!.monthController!.page!
|
|
|
|
|
.toInt() -
|
|
|
|
|
1]
|
|
|
|
|
.getDateTime();
|
|
|
|
@ -513,16 +513,16 @@ class CalendarController {
|
|
|
|
|
|
|
|
|
|
// 获取当前的月份
|
|
|
|
|
DateModel getCurrentMonth() {
|
|
|
|
|
return monthList[monthController.page.toInt()];
|
|
|
|
|
return monthList[monthController!.page!.toInt()];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取被选中的日期,多选
|
|
|
|
|
Set<DateModel> getMultiSelectCalendar() {
|
|
|
|
|
Set<DateModel?>? getMultiSelectCalendar() {
|
|
|
|
|
return calendarProvider.selectedDateList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取被选中的日期,单选
|
|
|
|
|
DateModel getSingleSelectCalendar() {
|
|
|
|
|
DateModel? getSingleSelectCalendar() {
|
|
|
|
|
return calendarProvider.selectDateModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -571,21 +571,21 @@ bool defaultInRange(DateModel dateModel) {
|
|
|
|
|
/**
|
|
|
|
|
* 周视图切换
|
|
|
|
|
*/
|
|
|
|
|
typedef void OnWeekChange(int year, int month);
|
|
|
|
|
typedef void OnWeekChange(int? year, int? month);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 月份切换事件
|
|
|
|
|
*/
|
|
|
|
|
typedef void OnMonthChange(int year, int month);
|
|
|
|
|
typedef void OnMonthChange(int? year, int? month);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 日期选择事件
|
|
|
|
|
*/
|
|
|
|
|
typedef void OnCalendarSelect(DateModel dateModel);
|
|
|
|
|
typedef void OnCalendarSelect(DateModel? dateModel);
|
|
|
|
|
/**
|
|
|
|
|
* 取消选择
|
|
|
|
|
*/
|
|
|
|
|
typedef void OnCalendarUnSelect(DateModel dateModel);
|
|
|
|
|
typedef void OnCalendarUnSelect(DateModel? dateModel);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 多选超出指定范围
|
|
|
|
|