Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dhwanish-3 committed Mar 3, 2024
2 parents 5247939 + a82de8a commit f9e7f89
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import 'package:calendar_slider/calendar_slider.dart';

Use the **CalendarAgenda** Widget
```dart
CalendarAgenda(
CalendarSlider(
initialDate: DateTime.now(),
firstDate: DateTime.now().subtract(Duration(days: 140)),
lastDate: DateTime.now().add(Duration(days: 4)),
Expand Down
24 changes: 19 additions & 5 deletions lib/src/calendar_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class CalendarSlider extends StatefulWidget implements PreferredSizeWidget {
final BoxShadow? tileShadow; // shadow of the date tile
final Color?
selectedTileBackgroundColor; // background color of the selected date tile
final Color?
disabledTileBackgroundColor; // background color of the selected date tile
final Color?
monthYearButtonBackgroundColor; // background color of the month year button on top
final Color? dateColor; // color of the date on each tile
Expand All @@ -61,6 +63,9 @@ class CalendarSlider extends StatefulWidget implements PreferredSizeWidget {
weekDay; // format of the week day (long or short)("Monday" or "Mon")
final List<DateTime>? events; // list of events

final DateTime? disabledTo;
final DateTime? disabledFrom;

CalendarSlider({
Key? key,
required this.initialDate,
Expand All @@ -76,6 +81,7 @@ class CalendarSlider extends StatefulWidget implements PreferredSizeWidget {
this.tileShadow,
this.tileBackgroundColor = Colors.white,
this.selectedTileBackgroundColor = Colors.blue,
this.disabledTileBackgroundColor = Colors.grey,
this.monthYearTextColor = Colors.white,
this.monthYearButtonBackgroundColor = Colors.grey,
this.calendarEventSelectedColor = Colors.white,
Expand All @@ -88,6 +94,8 @@ class CalendarSlider extends StatefulWidget implements PreferredSizeWidget {
this.weekDay = WeekDay.short,
this.fullCalendarWeekDay = WeekDay.short,
this.selectedDayPosition = SelectedDayPosition.center,
this.disabledTo,
this.disabledFrom,
}) : assert(
initialDate.difference(firstDate).inDays >= 0,
'initialDate must be on or after firstDate',
Expand Down Expand Up @@ -179,23 +187,29 @@ class CalendarSliderState extends State<CalendarSlider>
DateTime date = _dates[index];
bool isSelected = _daySelectedIndex == index;

bool isDisabled = widget.disabledTo != null ? (date.isBefore(widget.disabledTo!)) : false;
isDisabled = !isDisabled && widget.disabledFrom != null ? (date.isAfter(widget.disabledFrom!)) : isDisabled;

return Align(
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 5.0, horizontal: 4.0),
child: GestureDetector(
onTap: () => _goToActualDay(index),
onTap: isDisabled ? null : () => _goToActualDay(index),
child: Container(
height: isSelected
? widget.selectedTileHeight
: widget.tileHeight,
width: isSelected ? selectedTileWidth : tileWidth,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12.0),
color: isSelected
? widget.selectedTileBackgroundColor
: widget.tileBackgroundColor,
color: isDisabled
? widget.disabledTileBackgroundColor
: (isSelected
? widget.selectedTileBackgroundColor
: widget.tileBackgroundColor
),
boxShadow: [
widget.tileShadow ??
BoxShadow(
Expand Down Expand Up @@ -270,7 +284,7 @@ class CalendarSliderState extends State<CalendarSlider>

return SizedBox(
width: MediaQuery.of(context).size.width,
height: 180,
height: 180 - (widget.fullCalendar! ? 0 : widget.selectedTileHeight),
child: Stack(
children: [
Positioned(
Expand Down

0 comments on commit f9e7f89

Please sign in to comment.