hijri_picker icon indicating copy to clipboard operation
hijri_picker copied to clipboard

Pass weekday number to weekdayBuilder

Open musaffa opened this issue 1 year ago • 0 comments

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.

musaffa avatar Jul 19 '23 05:07 musaffa