showExpressiveDateRangePicker function

Future<({DateTime end, DateTime start})?> showExpressiveDateRangePicker({
  1. required BuildContext context,
  2. ExpressiveComponentThemeData? style,
  3. DateTime? initialStart,
  4. DateTime? initialEnd,
  5. DateTime? firstDate,
  6. DateTime? lastDate,
  7. bool selectableDay(
    1. DateTime day
    )?,
  8. String? title,
  9. DateTime? today,
  10. int? firstDayOfWeek,
  11. String? confirmLabel,
  12. String? dismissLabel,
})

Raises an ExpressiveDateRangePicker in an ExpressiveDatePickerDialog and resolves to the range confirmed with OK (OK waits for both ends), or null when cancelled.

Implementation

Future<({DateTime start, DateTime end})?> showExpressiveDateRangePicker({
  required BuildContext context,
  ExpressiveComponentThemeData? style,
  DateTime? initialStart,
  DateTime? initialEnd,
  DateTime? firstDate,
  DateTime? lastDate,
  bool Function(DateTime day)? selectableDay,
  String? title,
  DateTime? today,
  int? firstDayOfWeek,
  String? confirmLabel,
  String? dismissLabel,
}) {
  final strings = ExpressiveLocalizations.of(context);
  var start = initialStart;
  var end = initialEnd;
  return showExpressiveDialog<({DateTime start, DateTime end})>(
    context: context,
    builder: (context) => StatefulBuilder(
      builder: (context, update) {
        final s = start;
        final e = end;
        return ExpressiveDatePickerDialog(
          style: style,
          dismiss: ExpressiveTextButton(
            dismissLabel ?? strings.cancel,
            onPressed: () => Navigator.of(context).pop(),
          ),
          confirm: ExpressiveTextButton(
            confirmLabel ?? strings.ok,
            onPressed: s == null || e == null
                ? null
                : () => Navigator.of(context).pop((start: s, end: e)),
          ),
          child: ExpressiveDateRangePicker(
            style: style,
            start: s,
            end: e,
            onChanged: (ns, ne) => update(() {
              start = ns;
              end = ne;
            }),
            firstDate: firstDate,
            lastDate: lastDate,
            selectableDayPredicate: selectableDay,
            title: title,
            currentDate: today,
            firstDayOfWeek: firstDayOfWeek,
          ),
        );
      },
    ),
  );
}