DateFormField constructor
DateFormField({
- Key? key,
- TextEditingController? controller,
- String? initialValue,
- TextInputAction? textInputAction,
- TextStyle? style,
- StrutStyle? strutStyle,
- TextDirection? textDirection,
- TextAlign textAlign = TextAlign.start,
- bool autofocus = false,
- bool readOnly = false,
- bool? showCursor,
- bool enableSuggestions = true,
- MaxLengthEnforcement? maxLengthEnforcement,
- bool expands = false,
- int? maxLength,
- ValueChanged<
String> ? onChanged, - GestureTapCallback? onTap,
- VoidCallback? onEditingComplete,
- ValueChanged<
String> ? onFieldSubmitted, - FormFieldSetter<
String> ? onSaved, - FormFieldValidator<
String> ? validator, - bool enabled = true,
- double cursorWidth = 2.0,
- double? cursorHeight,
- EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
- bool? enableInteractiveSelection,
- TextSelectionControls? selectionControls,
- Iterable<
String> ? autofillHints, - AutovalidateMode? autovalidateMode,
- ScrollController? scrollController,
- String? restorationId,
- bool enableIMEPersonalizedLearning = true,
- FocusNode? focusNode,
- List<
TextInputFormatter> ? inputFormatters, - required DateTime initialDate,
- required DateTime firstDate,
- required DateTime lastDate,
- DateTime? currentDate,
- SelectableDayPredicate? selectableDayPredicate,
- DatePickerMode initialCalendarMode = DatePickerMode.day,
Creates a DateFormField.
Implementation
DateFormField({
super.key,
this.controller,
String? initialValue,
TextInputAction? textInputAction, // TODO(as): field.
TextStyle? style,
StrutStyle? strutStyle,
TextDirection? textDirection,
TextAlign textAlign = TextAlign.start,
bool autofocus = false,
bool readOnly = false,
bool? showCursor,
bool enableSuggestions = true, // TODO(as): field.
MaxLengthEnforcement? maxLengthEnforcement, // TODO(as): field.
bool expands = false, // TODO(as): field.
int? maxLength, // TODO(as): field.
this.onChanged,
GestureTapCallback? onTap,
VoidCallback? onEditingComplete,
ValueChanged<String>? onFieldSubmitted,
super.onSaved,
super.validator, // TODO(as): field.
bool enabled = true,
double cursorWidth = 2.0,
double? cursorHeight,
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
bool? enableInteractiveSelection,
TextSelectionControls? selectionControls,
Iterable<String>? autofillHints, // TODO(as): field.
AutovalidateMode? autovalidateMode,
ScrollController? scrollController,
super.restorationId,
bool enableIMEPersonalizedLearning = true,
this.focusNode,
List<TextInputFormatter>? inputFormatters,
// Used for the date picker.
required this.initialDate,
required this.firstDate,
required this.lastDate,
this.currentDate,
this.selectableDayPredicate,
this.initialCalendarMode = DatePickerMode.day,
// MouseCursor? mouseCursor,
}) : assert(initialValue == null || controller == null),
super(
initialValue:
controller != null ? controller.text : (initialValue ?? ''),
enabled: enabled,
autovalidateMode: autovalidateMode ?? AutovalidateMode.disabled,
builder: (FormFieldState<String> field) {
final _TextFormFieldState state = field as _TextFormFieldState;
void onChangedHandler(String value) {
field.didChange(value);
if (onChanged != null) {
onChanged(value);
}
}
final FocusNode effectiveFocusNode = state._effectiveFocusNode;
final ThemeData themeData = Theme.of(field.context);
final ColorScheme colorScheme = themeData.colorScheme;
final TextTheme textTheme = themeData.textTheme;
final Widget? error = field.errorText != null
? Text(
field.errorText!,
style: textTheme.caption.copyWith(
color: textTheme.textError,
fontWeight: FontWeight.w500,
),
)
: null;
final Color background =
enabled ? colorScheme.background[0] : colorScheme.shade[90];
final foreground = effectiveFocusNode.hasFocus
? colorScheme.shade[50]
: colorScheme.shade[30];
final Color borderColor = field._calendarButtonActive
? colorScheme.background[8]
: foreground;
final BoxDecoration decoration = BoxDecoration(
color: background,
border: enabled
? Border.all(color: borderColor, width: _kBorderWidth)
: null,
);
final List<TextInputFormatter> effectiveInputFormatters =
inputFormatters ??
[
DesktopLocalizations.of(field.context)
.dateFormInputFormatter
];
return Column(
mainAxisSize: MainAxisSize.min,
children: [
DecoratedBox(
decoration: decoration,
child: Padding(
padding: decoration.padding,
child: Row(
children: [
Flexible(
child: Align(
alignment: Alignment.centerRight,
child: UnmanagedRestorationScope(
bucket: field.bucket,
child: TextField(
restorationId: restorationId,
controller: state._effectiveController,
focusNode: effectiveFocusNode,
decoration: const BoxDecoration(),
keyboardType: TextInputType.datetime,
textInputAction: textInputAction,
style: style,
strutStyle: strutStyle,
textAlign: textAlign,
textDirection: textDirection,
textCapitalization: TextCapitalization.none,
autofocus: autofocus,
readOnly: readOnly,
showCursor: showCursor,
autocorrect: false,
smartDashesType: SmartDashesType.disabled,
smartQuotesType: SmartQuotesType.disabled,
enableSuggestions: enableSuggestions,
maxLines: 1,
minLines: 1,
expands: expands,
maxLength: maxLength,
onChanged: onChangedHandler,
onTap: onTap,
onEditingComplete: onEditingComplete,
onSubmitted: onFieldSubmitted,
inputFormatters: effectiveInputFormatters,
enabled: enabled,
cursorWidth: cursorWidth,
cursorHeight: cursorHeight,
scrollPadding: scrollPadding,
enableInteractiveSelection:
enableInteractiveSelection ?? !readOnly,
selectionControls: selectionControls,
autofillHints: autofillHints,
scrollController: scrollController,
enableIMEPersonalizedLearning:
enableIMEPersonalizedLearning,
maxLengthEnforcement: maxLengthEnforcement,
// mouseCursor: mouseCursor,
),
),
),
),
Padding(
// Considering the padding inside [TextField].
padding: const EdgeInsets.only(left: 4.0, right: 8.0),
child: Button.icon(
Icons.editCalendar,
active: field._calendarButtonActive,
theme: const ButtonThemeData(itemSpacing: 0.0),
onPressed: field._openDatePicker,
),
),
],
),
),
),
if (error != null)
Padding(
padding: const EdgeInsets.only(top: 4.0),
child: Align(
alignment: Alignment.bottomRight,
child: error,
),
),
],
);
},
);