Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide deactivated dates widgets #62

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
79 changes: 45 additions & 34 deletions lib/date_picker_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class DatePicker extends StatefulWidget {

/// Locale for the calendar default: en_us
final String locale;
//===================== PROPOSED =======================//
/// If providing Active or Deactivated Dates,
// Allow hiding the widgets so there are no spaces in between active dates
final bool hideDeactivatedDates;


DatePicker(
this.startDate, {
Expand All @@ -78,6 +83,8 @@ class DatePicker extends StatefulWidget {
this.daysCount = 500,
this.onDateChange,
this.locale = "en_US",
//===================== PROPOSED =======================//
this.hideDeactivatedDates = false,
}) : assert(
activeDates == null || inactiveDates == null,
"Can't "
Expand Down Expand Up @@ -173,40 +180,44 @@ class _DatePickerState extends State<DatePicker> {
_currentDate != null ? _compareDate(date, _currentDate!) : false;

// Return the Date Widget
return DateWidget(
date: date,
monthTextStyle: isDeactivated
? deactivatedMonthStyle
: isSelected
? selectedMonthStyle
: widget.monthTextStyle,
dateTextStyle: isDeactivated
? deactivatedDateStyle
: isSelected
? selectedDateStyle
: widget.dateTextStyle,
dayTextStyle: isDeactivated
? deactivatedDayStyle
: isSelected
? selectedDayStyle
: widget.dayTextStyle,
width: widget.width,
locale: widget.locale,
selectionColor:
isSelected ? widget.selectionColor : Colors.transparent,
onDateSelected: (selectedDate) {
// Don't notify listener if date is deactivated
if (isDeactivated) return;

// A date is selected
if (widget.onDateChange != null) {
widget.onDateChange!(selectedDate);
}
setState(() {
_currentDate = selectedDate;
});
},
);
return
//===================== PROPOSED: Wrap in visibility widget to hide it if deactivated =========================//
Visibility(
child: DateWidget(
date: date,
monthTextStyle: isDeactivated
? deactivatedMonthStyle
: isSelected
? selectedMonthStyle
: widget.monthTextStyle,
dateTextStyle: isDeactivated
? deactivatedDateStyle
: isSelected
? selectedDateStyle
: widget.dateTextStyle,
dayTextStyle: isDeactivated
? deactivatedDayStyle
: isSelected
? selectedDayStyle
: widget.dayTextStyle,
width: widget.width,
locale: widget.locale,
selectionColor:
isSelected ? widget.selectionColor : Colors.transparent,
onDateSelected: (selectedDate) {
// Don't notify listener if date is deactivated
if (isDeactivated) return;

// A date is selected
if (widget.onDateChange != null) {
widget.onDateChange!(selectedDate);
}
setState(() {
_currentDate = selectedDate;
});
},
),
visible: widget.hideDeactivatedDates == true && isDeactivated == true ? false : true );
},
),
);
Expand Down