DateTimeFormField constructor
DateTimeFormField({
- required ValueChanged<
DateTime?> ? onChanged, - Key? key,
- DateTime? initialValue,
- FormFieldSetter<
DateTime> ? onSaved, - FormFieldValidator<
DateTime> ? validator, - String? restorationId,
- AutovalidateMode? autovalidateMode = AutovalidateMode.disabled,
- bool canClear = true,
- IconData 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,
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,
);
},
),
);
},
);