Skip to content

Commit 449b1ec

Browse files
committed
Use a built-in date compare function
1 parent 74a3a4b commit 449b1ec

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

lib/date_picker_widget.dart

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,8 @@ class _DatePickerState extends State<DatePicker> {
145145

146146
// check if this date needs to be deactivated for only DeactivatedDates
147147
if (widget.inactiveDates != null) {
148-
// print("Inside Inactive dates.");
149148
for (DateTime inactiveDate in widget.inactiveDates!) {
150-
if (_compareDate(date, inactiveDate)) {
149+
if (DateUtils.isSameDay(date, inactiveDate)) {
151150
isDeactivated = true;
152151
break;
153152
}
@@ -158,17 +157,17 @@ class _DatePickerState extends State<DatePicker> {
158157
if (widget.activeDates != null) {
159158
isDeactivated = true;
160159
for (DateTime activateDate in widget.activeDates!) {
161-
// Compare the date if it is in the
162-
if (_compareDate(date, activateDate)) {
160+
if (DateUtils.isSameDay(date, activateDate)) {
163161
isDeactivated = false;
164162
break;
165163
}
166164
}
167165
}
168166

169167
// Check if this date is the one that is currently selected
170-
bool isSelected =
171-
_currentDate != null ? _compareDate(date, _currentDate!) : false;
168+
bool isSelected = _currentDate != null
169+
? DateUtils.isSameDay(date, _currentDate!)
170+
: false;
172171

173172
// Return the Date Widget
174173
return DateWidget(
@@ -208,14 +207,6 @@ class _DatePickerState extends State<DatePicker> {
208207
),
209208
);
210209
}
211-
212-
/// Helper function to compare two dates
213-
/// Returns True if both dates are the same
214-
bool _compareDate(DateTime date1, DateTime date2) {
215-
return date1.day == date2.day &&
216-
date1.month == date2.month &&
217-
date1.year == date2.year;
218-
}
219210
}
220211

221212
class DatePickerController {

0 commit comments

Comments
 (0)