CoolDatepicker constructor
CoolDatepicker({
- int limitCount = 1,
- String format = 'yyyy-mm-dd',
- double iconSize = 25,
- double calendarSize = 400,
- List<
DateTime> ? disabledList, - List<
Map< ? disabledRangeList,String, DateTime?> > - int? minYear,
- int? maxYear,
- required Function onSelected,
- bool isRange = false,
- dynamic resultIcon,
- dynamic placeholderTS,
- bool isResultIconLabelReverse = false,
- String placeholder = '',
- double resultWidth = 220,
- double resultHeight = 50,
- Alignment resultAlign = Alignment.centerLeft,
- EdgeInsets resultPadding = const EdgeInsets.only(left: 10, right: 10),
- dynamic resultBD,
- dynamic resultTS,
- double labelIconGap = 10,
- dynamic defaultValue,
- List<
String> ? weekLabelList, - List<
String> ? monthLabelList, - bool isYearMonthDropdownReverse = false,
- Color bottomSelectedBorderColor = const Color(0XFF6771e4),
- Color headerColor = const Color(0XFF6771e4),
- Color arrowIconAreaColor = const Color(0XFF4752e0),
- Color selectedCircleColor = const Color(0XFF6771e4),
- Color selectedBetweenAreaColor = const Color(0XFFe2e4fa),
- Color cancelFontColor = const Color(0XFF4a54c5),
- LinearGradient okButtonColor = const LinearGradient(colors: [Color(0XFF4a54c5), Color(0XFF6771e4)]),
- bool isDark = false,
- String cancelBtnLabel = 'CANCEL',
- String okBtnLabel = 'OK',
- bool isResultLabel = true,
- int? firstWeekDay = DateTime.sunday,
Implementation
CoolDatepicker({
this.limitCount = 1,
this.format = 'yyyy-mm-dd',
this.iconSize = 25,
this.calendarSize = 400,
this.disabledList,
this.disabledRangeList,
this.minYear,
this.maxYear,
required this.onSelected,
this.isRange = false,
resultIcon,
placeholderTS,
this.isResultIconLabelReverse = false,
this.placeholder = '',
this.resultWidth = 220,
this.resultHeight = 50,
this.resultAlign = Alignment.centerLeft,
this.resultPadding = const EdgeInsets.only(left: 10, right: 10),
resultBD,
resultTS,
this.labelIconGap = 10,
// this.isAnimation = true,
// this.isResultIconLabel = true,
this.defaultValue,
this.weekLabelList,
this.monthLabelList,
this.isYearMonthDropdownReverse = false,
this.bottomSelectedBorderColor = const Color(0XFF6771e4),
this.headerColor = const Color(0XFF6771e4),
this.arrowIconAreaColor = const Color(0XFF4752e0),
this.selectedCircleColor = const Color(0XFF6771e4),
this.selectedBetweenAreaColor = const Color(0XFFe2e4fa),
this.cancelFontColor = const Color(0XFF4a54c5),
this.okButtonColor = const LinearGradient(colors: [
Color(0XFF4a54c5),
Color(0XFF6771e4), // headerColor
]),
this.isDark = false,
this.cancelBtnLabel = 'CANCEL',
this.okBtnLabel = 'OK',
this.isResultLabel = true,
this.firstWeekDay = DateTime.sunday,
}) {
// disabledRangeList 체크
if (disabledRangeList != null) {
for (var rangeMap in disabledRangeList!) {
assert((rangeMap['start'] != null) && (rangeMap['end'] != null),
"both of start and end can't be null");
assert(rangeMap['start']!.isBefore(rangeMap['end']!),
'start DateTIme must be earlier than end DateTime');
assert(!(rangeMap['start']!.compare(rangeMap['end']!)),
"start and end can't be the same. Try to use in 'disabledList' option");
}
}
// year dropdownList 셋팅
minYear = minYear ?? (DateTime.now().year - 100);
maxYear = maxYear ?? (DateTime.now().year + 100);
assert((maxYear! > minYear!), 'maxYear > minYear');
for (var i = maxYear; i! >= minYear!; i--) {
years.add({'label': '$i', 'value': i});
}
assert(
(format.contains('yyyy') &&
format.contains('mm') &&
format.contains('dd')),
'you must include yyyy, dd, mm');
assert(
(firstWeekDay! >=1) && (firstWeekDay! <= 7),
'firstWeekDay must be > 0 and <= 7. The code number is: '
' monday = 1, tuesday = 2 wednesday = 3, thursday = 4, friday = 5, saturday = 6, sunday = 7'
);
// weekLabelList setting
weekLabelMapList = [
{'label': weekLabelList?[0] ?? 'S', 'color': const Color(0XFFE70000)},
{'label': weekLabelList?[1] ?? 'M', 'color': const Color(0XFF333333)},
{'label': weekLabelList?[2] ?? 'T', 'color': const Color(0XFF333333)},
{'label': weekLabelList?[3] ?? 'W', 'color': const Color(0XFF333333)},
{'label': weekLabelList?[4] ?? 'T', 'color': const Color(0XFF333333)},
{'label': weekLabelList?[5] ?? 'F', 'color': const Color(0XFF333333)},
{'label': weekLabelList?[6] ?? 'S', 'color': const Color(0XFF22A2BF)}
];
List sourceWeekLabels = List.from(weekLabelMapList);
for(int i=0; i<sourceWeekLabels.length; i++){
weekLabelMapList[i] = sourceWeekLabels[(i+firstWeekDay!)%7];
}
monthLabelMapList = [
{'label': monthLabelList?[0] ?? '01', 'value': 1},
{'label': monthLabelList?[1] ?? '02', 'value': 2},
{'label': monthLabelList?[2] ?? '03', 'value': 3},
{'label': monthLabelList?[3] ?? '04', 'value': 4},
{'label': monthLabelList?[4] ?? '05', 'value': 5},
{'label': monthLabelList?[5] ?? '06', 'value': 6},
{'label': monthLabelList?[6] ?? '07', 'value': 7},
{'label': monthLabelList?[7] ?? '08', 'value': 8},
{'label': monthLabelList?[8] ?? '09', 'value': 9},
{'label': monthLabelList?[9] ?? '10', 'value': 10},
{'label': monthLabelList?[10] ?? '11', 'value': 11},
{'label': monthLabelList?[11] ?? '12', 'value': 12},
];
// box decoration 셋팅
this.resultBD = resultBD ??
BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.1),
spreadRadius: 1,
blurRadius: 10,
offset: const Offset(0, 1), // changes position of shadow
),
],
);
this.resultTS = resultTS ??
const TextStyle(
fontSize: 20,
color: Colors.black,
);
this.placeholderTS = placeholderTS ??
TextStyle(color: Colors.grey.withOpacity(0.7), fontSize: 20);
if (defaultValue != null) {
if (isRange) {
assert(defaultValue is Map<String, DateTime?>,
'the range defaultValue must be type of Map<String, DateTime?>');
assert(defaultValue['start'] != null,
'the range defaultValue must include "start" key of Map');
if (disabledList != null) {
for (var j = 0; j < disabledList!.length; j++) {
assert(!!isSameBtwDates(defaultValue!['start'], disabledList![j]),
"the range defaultValue['start'] and the disabledList items can't be duplicated");
}
for (var j = 0; j < disabledList!.length; j++) {
assert(!isSameBtwDates(defaultValue!['end'], disabledList![j]),
"the range defaultValue['end'] and the disabledList items can't be duplicated");
}
}
if (disabledRangeList != null) {
for (var j = 0; j < disabledRangeList!.length; j++) {
DateTime startDate = disabledRangeList![j]['start']!;
DateTime endDate = disabledRangeList![j]['end']!;
DateTime targetStartDate = defaultValue['start'];
DateTime targetEndDate = defaultValue['end'];
assert(
!(startDate.checkAfter(target: targetStartDate) &&
endDate.checkBefore(target: targetStartDate)),
"the defaultValue range start can't be ranged between disabledRangeList items");
assert(
!(startDate.checkAfter(target: targetEndDate) &&
endDate.checkBefore(target: targetEndDate)),
"the defaultValue range end can't be ranged between disabledRangeList items");
}
}
} else {
assert(defaultValue is List<DateTime>,
'the single defaultValue must be type of List<DateTime>');
assert(!(defaultValue!.length > limitCount),
'the number of the single defaultValue items must be less than limitCount');
for (var i = 0; i < defaultValue.length; i++) {
if (disabledList != null) {
for (var j = 0; j < disabledList!.length; j++) {
assert(!isSameBtwDates(defaultValue![i], disabledList![j]),
"the single defaultValue and the disabledList items can't be duplicated");
}
}
if (disabledRangeList != null) {
for (var j = 0; j < disabledRangeList!.length; j++) {
DateTime startDate = disabledRangeList![j]['start']!;
DateTime endDate = disabledRangeList![j]['end']!;
DateTime targetDate = defaultValue[i];
assert(
!(startDate.checkAfter(target: targetDate) &&
endDate.checkBefore(target: targetDate)),
"the defaultValue can't be ranged between disabledRangeList items");
}
}
for (var j = 0; j < defaultValue.length; j++) {
if (i != j) {
assert(!isSameBtwDates(defaultValue![i], defaultValue[j]),
"the signle defaultValue items can't be duplicated");
}
}
}
}
}
}