ahmedoid / hijri_picker

Flutter Widget to Pick Hijri Calendar Dates
BSD 2-Clause "Simplified" License
25 stars 23 forks source link

Pass weekday number to weekdayBuilder #14

Open musaffa opened 11 months ago

musaffa commented 11 months ago

Sometimes special adjustments need to be made on weekdays. For example, changing the Hijri date after Sunset while keeping the weekday the same as Gregorian date. For these adjustments String day passed to the weekdayBuilder isn't enough. Weekday number can be very handy for these kind of adjustments. Here's an example:

HijriMonthPicker(
  builders: HijriCalendarBuilders(
    weekdayBuilder: (context, day, number) {
      MaterialLocalizations localizations = MaterialLocalizations.of(context);

      int adjustedWeekdayNumber = 0;

      if (isAfterDateStartTime(DateTime.now())) {
         adjustedWeekdayNumber -= 1;
      }

      int num = (number + adjustedWeekdayNumber) % 7;
      final String weekday = localizations.narrowWeekdays[num];

      return Center(
        child: Text(weekday),
      );
    },
  ),
),

This PR passes the weekday number to weekdayBuilder. This is a breaking change for those who use custom weekdayBuilders.