DateTimeFormField constructor

DateTimeFormField({
  1. required ValueChanged<DateTime?>? onChanged,
  2. Key? key,
  3. DateTime? initialValue,
  4. FormFieldSetter<DateTime>? onSaved,
  5. FormFieldValidator<DateTime>? validator,
  6. String? restorationId,
  7. AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
  8. bool canClear = true,
  9. IconData clearIconData = Icons.clear,
  10. TextStyle? style,
  11. VoidCallback? onTap,
  12. FocusNode? focusNode,
  13. bool autofocus = false,
  14. bool? enableFeedback,
  15. EdgeInsetsGeometry? padding,
  16. bool hideDefaultSuffixIcon = false,
  17. DateTime? initialPickerDateTime,
  18. CupertinoDatePickerOptions cupertinoDatePickerOptions = const CupertinoDatePickerOptions(),
  19. MaterialDatePickerOptions materialDatePickerOptions = const MaterialDatePickerOptions(),
  20. MaterialTimePickerOptions materialTimePickerOptions = const MaterialTimePickerOptions(),
  21. InputDecoration? decoration,
  22. DateFormat? dateFormat,
  23. DateTime? firstDate,
  24. DateTime? lastDate,
  25. DateTimeFieldPickerMode mode = DateTimeFieldPickerMode.dateAndTime,
  26. DateTimeFieldPickerPlatform pickerPlatform = DateTimeFieldPickerPlatform.adaptive,
})

Implementation

DateTimeFormField({
  required this.onChanged,
  super.key,
  super.initialValue,
  super.onSaved,
  super.validator,
  super.restorationId,
  super.autovalidateMode = AutovalidateMode.disabled,
  this.canClear = true,
  this.clearIconData = Icons.clear,
  TextStyle? style,
  VoidCallback? onTap,
  FocusNode? focusNode,
  bool autofocus = false,
  bool? enableFeedback,
  EdgeInsetsGeometry? padding,
  bool hideDefaultSuffixIcon = false,
  DateTime? initialPickerDateTime,
  CupertinoDatePickerOptions cupertinoDatePickerOptions =
      const CupertinoDatePickerOptions(),
  MaterialDatePickerOptions materialDatePickerOptions =
      const MaterialDatePickerOptions(),
  MaterialTimePickerOptions materialTimePickerOptions =
      const MaterialTimePickerOptions(),
  InputDecoration? decoration,
  DateFormat? dateFormat,
  DateTime? firstDate,
  DateTime? lastDate,
  DateTimeFieldPickerMode mode = DateTimeFieldPickerMode.dateAndTime,
  DateTimeFieldPickerPlatform pickerPlatform =
      DateTimeFieldPickerPlatform.adaptive,
}) : super(
        enabled: decoration?.enabled ?? true,
        builder: (FormFieldState<DateTime> field) {
          final _DateTimeFormFieldState state =
              field as _DateTimeFormFieldState;

          final bool isEmpty = state.value == null;

          InputDecoration decorationArg =
              (decoration ?? const InputDecoration())
                  .copyWith(errorText: field.errorText);

          if (canClear && !isEmpty) {
            decorationArg = decorationArg.copyWith(
              suffixIcon: IconButton(
                icon: Icon(clearIconData),
                onPressed: () => field.didChange(null),
              ),
            );
          }

          // An un-focusable Focus widget so that this widget can detect if its
          // descendants have focus or not.
          return Focus(
            canRequestFocus: false,
            skipTraversal: true,
            child: Builder(
              builder: (BuildContext context) {
                return DateTimeField._formField(
                  value: state.value,
                  onChanged: onChanged == null ? null : state.didChange,
                  onTap: onTap,
                  style: style,
                  focusNode: focusNode,
                  autofocus: autofocus,
                  enableFeedback: enableFeedback,
                  decoration: decorationArg,
                  padding: padding,
                  firstDate: firstDate,
                  initialPickerDateTime: initialPickerDateTime,
                  lastDate: lastDate,
                  dateFormat: dateFormat,
                  mode: mode,
                  hideDefaultSuffixIcon: hideDefaultSuffixIcon,
                  cupertinoDatePickerOptions: cupertinoDatePickerOptions,
                  materialDatePickerOptions: materialDatePickerOptions,
                  materialTimePickerOptions: materialTimePickerOptions,
                  pickerPlatform: pickerPlatform,
                );
              },
            ),
          );
        },
      );