kDayTileBuilder function

Widget kDayTileBuilder(
  1. DayModel dayModel,
  2. CalendarTheme theme,
  3. ValueChanged<DateTime> onDateChanged
)

A function that builds a day tile for the date range picker.

  • dayModel - The model for the day tile to be built.
  • theme - The theme to apply to the day tile.
  • onTap - A callback function to be called when the day tile is tapped.

Implementation

Widget kDayTileBuilder(
  DayModel dayModel,
  CalendarTheme theme,
  ValueChanged<DateTime> onDateChanged,
) {
  TextStyle combinedTextStyle = theme.defaultTextStyle;

  if (dayModel.isToday) {
    combinedTextStyle = combinedTextStyle.merge(theme.todayTextStyle);
  }

  if (dayModel.isInRange) {
    combinedTextStyle = combinedTextStyle.merge(theme.inRangeTextStyle);
  }

  if (dayModel.isSelected) {
    combinedTextStyle = combinedTextStyle.merge(theme.selectedTextStyle);
  }

  if (!dayModel.isSelectable) {
    combinedTextStyle = combinedTextStyle.merge(theme.disabledTextStyle);
  }

  return DayTileWidget(
    size: theme.tileSize,
    textStyle: combinedTextStyle,
    backgroundColor: dayModel.isInRange ? theme.inRangeColor : null,
    color: dayModel.isSelected ? theme.selectedColor : null,
    text: "${dayModel.date.day.toString()}",
    value: dayModel.date,
    onTap: dayModel.isSelectable ? onDateChanged : null,
    radius: BorderRadius.horizontal(
      left: Radius.circular(
          dayModel.isEnd && dayModel.isInRange ? 0 : theme.radius),
      right: Radius.circular(
          dayModel.isStart && dayModel.isInRange ? 0 : theme.radius),
    ),
    backgroundRadius: BorderRadius.horizontal(
      left: Radius.circular(dayModel.isStart ? theme.radius : 0),
      right: Radius.circular(dayModel.isEnd ? theme.radius : 0),
    ),
  );
}