ReactiveDateRangePicker constructor

ReactiveDateRangePicker({
  1. Key? key,
  2. String? formControlName,
  3. FormControl<DateTimeRange>? formControl,
  4. ControlValueAccessor<DateTimeRange, String>? valueAccessor,
  5. Map<String, ValidationMessageFunction>? validationMessages,
  6. ShowErrorsFunction<DateTimeRange>? showErrors,
  7. InputDecoration? decoration,
  8. bool showClearIcon = true,
  9. Widget clearIcon = const Icon(Icons.clear),
  10. TextStyle? style,
  11. TransitionBuilder? builder,
  12. bool useRootNavigator = true,
  13. String? cancelText,
  14. String? confirmText,
  15. String? helpText,
  16. String? saveText,
  17. String? errorFormatText,
  18. String? errorInvalidText,
  19. String? errorInvalidRangeText,
  20. String? fieldStartHintText,
  21. String? fieldEndHintText,
  22. String? fieldStartLabelText,
  23. String? fieldEndLabelText,
  24. DateTime? firstDate,
  25. DateTime? lastDate,
  26. DateTime? currentDate,
  27. DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
  28. Locale? locale,
  29. TextDirection? textDirection,
  30. RouteSettings? routeSettings,
  31. bool barrierDismissible = true,
  32. Color? barrierColor,
  33. Offset? anchorPoint,
  34. TextInputType keyboardType = TextInputType.datetime,
  35. Icon? switchToInputEntryModeIcon,
  36. Icon? switchToCalendarEntryModeIcon,
})

Creates a ReactiveDateRangePickerField that wraps the function showDateRangePicker.

Can optionally provide a formControl to bind this widget to a control.

Can optionally provide a formControlName to bind this ReactiveFormField to a FormControl.

Must provide one of the arguments formControl or a formControlName, but not both at the same time.

The parameter transitionBuilder is the equivalent of builder parameter in the showTimePicker.

For documentation about the various parameters, see the showDateRangePicker function parameters.

Implementation

ReactiveDateRangePicker({
  super.key,
  super.formControlName,
  super.formControl,
  ControlValueAccessor<DateTimeRange, String>? valueAccessor,
  super.validationMessages,
  super.showErrors,

  ////////////////////////////////////////////////////////////////////////////
  InputDecoration? decoration,
  bool showClearIcon = true,
  Widget clearIcon = const Icon(Icons.clear),
  TextStyle? style,
  TransitionBuilder? builder,
  bool useRootNavigator = true,
  String? cancelText,
  String? confirmText,
  String? helpText,
  String? saveText,
  String? errorFormatText,
  String? errorInvalidText,
  String? errorInvalidRangeText,
  String? fieldStartHintText,
  String? fieldEndHintText,
  String? fieldStartLabelText,
  String? fieldEndLabelText,
  DateTime? firstDate,
  DateTime? lastDate,
  DateTime? currentDate,
  DatePickerEntryMode initialEntryMode = DatePickerEntryMode.calendar,
  Locale? locale,
  TextDirection? textDirection,
  RouteSettings? routeSettings,
  bool barrierDismissible = true,
  Color? barrierColor,
  Offset? anchorPoint,
  TextInputType keyboardType = TextInputType.datetime,
  Icon? switchToInputEntryModeIcon,
  Icon? switchToCalendarEntryModeIcon,
}) : super(
        valueAccessor: valueAccessor ?? DateTimeRangeValueAccessor(),
        builder: (field) {
          Widget? suffixIcon = decoration?.suffixIcon;
          final isEmptyValue =
              field.value == null || field.value.toString().isEmpty;

          if (showClearIcon && !isEmptyValue) {
            suffixIcon = InkWell(
              borderRadius: BorderRadius.circular(25),
              child: clearIcon,
              onTap: () {
                field.control.markAsTouched();
                field.didChange(null);
              },
            );
          }

          final InputDecoration effectiveDecoration =
              (decoration ?? const InputDecoration())
                  .applyDefaults(Theme.of(field.context).inputDecorationTheme)
                  .copyWith(suffixIcon: suffixIcon);

          final effectiveValueAccessor =
              valueAccessor ?? DateTimeRangeValueAccessor();

          final effectiveLastDate = lastDate ?? DateTime(2100);

          return IgnorePointer(
            ignoring: !field.control.enabled,
            child: GestureDetector(
              onTap: () async {
                final dateRange = await showDateRangePicker(
                  context: field.context,
                  initialDateRange: field.control.value,
                  firstDate: firstDate ?? DateTime(1900),
                  lastDate: effectiveLastDate,
                  currentDate: currentDate,
                  initialEntryMode: initialEntryMode,
                  helpText: helpText,
                  cancelText: cancelText,
                  confirmText: confirmText,
                  saveText: saveText,
                  errorFormatText: errorFormatText,
                  errorInvalidText: errorInvalidText,
                  errorInvalidRangeText: errorInvalidRangeText,
                  fieldStartHintText: fieldStartHintText,
                  fieldEndHintText: fieldEndHintText,
                  fieldStartLabelText: fieldStartLabelText,
                  fieldEndLabelText: fieldEndLabelText,
                  locale: locale,
                  useRootNavigator: useRootNavigator,
                  routeSettings: routeSettings,
                  textDirection: textDirection,
                  builder: builder,
                  barrierDismissible: barrierDismissible,
                  barrierColor: barrierColor,
                  anchorPoint: anchorPoint,
                  keyboardType: keyboardType,
                  switchToInputEntryModeIcon: switchToInputEntryModeIcon,
                  switchToCalendarEntryModeIcon:
                      switchToCalendarEntryModeIcon,
                );

                if (dateRange == null) {
                  return;
                }

                field.control.markAsTouched();
                field.didChange(
                    effectiveValueAccessor.modelToViewValue(dateRange));
              },
              child: InputDecorator(
                decoration: effectiveDecoration.copyWith(
                  errorText: field.errorText,
                  enabled: field.control.enabled,
                ),
                isEmpty: isEmptyValue,
                child: Text(
                  field.value ?? '',
                  style: Theme.of(field.context)
                      .textTheme
                      .titleMedium
                      ?.merge(style),
                ),
              ),
            ),
          );
        },
      );