dateRangePicker static method
dynamic
dateRangePicker({})
pick date range with customization
Implementation
static dateRangePicker(
{required BuildContext context,
required Function(String fromDate, String toDate) onSelected,
String? fromDate,
String? toDate,
String? minDate,
String? maxDate,
String format = Format.fyyyyMMdd}) {
String startDate = _isNullOrEmpty(fromDate)
? getCurrentDate()
: formatDateTime(
dateTime: fromDate!, inFormat: format, outFormat: format);
String endDate = _isNullOrEmpty(toDate)
? getCurrentDate()
: formatDateTime(
dateTime: toDate!, inFormat: format, outFormat: format);
if (!validDateTimeRange(
fromDateTime: startDate, toDateTime: endDate, format: format)) {
startDate = getCurrentDate();
endDate = getCurrentDate();
}
showDateRangePicker(
context: context,
firstDate: _isNullOrEmpty(minDate)
? DateTime(1950)
: stringToDateTime(date: minDate!),
lastDate: _isNullOrEmpty(maxDate)
? DateTime(3000)
: stringToDateTime(date: maxDate!),
initialDateRange: DateTimeRange(
start: stringToDateTime(date: startDate),
end: stringToDateTime(date: endDate),
)).then((value) {
String fDate = "";
String tDate = "";
if (value != null) {
fDate = dateTimeToString(date: value.start, format: format);
tDate = dateTimeToString(date: value.end, format: format);
} else {
fDate = _isNullOrEmpty(fromDate)
? ""
: formatDateTime(
dateTime: fromDate!, inFormat: format, outFormat: format);
tDate = _isNullOrEmpty(toDate)
? ""
: formatDateTime(
dateTime: toDate!, inFormat: format, outFormat: format);
}
onSelected(fDate, tDate);
});
}