ObserverFormField<T> constructor
ObserverFormField<T> ({
- required ObservableBase<
T> observable, - TextFormatter<
T> ? formatter, - TextInputType? keyboardType,
- Key? key,
- InputDecoration decoration = const InputDecoration(),
- TextInputAction? textInputAction,
- TextCapitalization textCapitalization = TextCapitalization.none,
- TextStyle? style,
- StrutStyle? strutStyle,
- TextAlign textAlign = TextAlign.start,
- TextAlignVertical? textAlignVertical,
- TextDirection textDirection = TextDirection.ltr,
- bool readOnly = false,
- ToolbarOptions? toolbarOptions,
- bool showCursor = true,
- bool autofocus = false,
- String obscuringCharacter = '•',
- bool obscureText = false,
- bool autocorrect = true,
- SmartDashesType? smartDashesType,
- SmartQuotesType? smartQuotesType,
- bool enableSuggestions = true,
- int? maxLines = 1,
- int? minLines,
- bool expands = false,
- int? maxLength,
- MaxLengthEnforcement? maxLengthEnforcement,
- ValueChanged<
T> ? onChanged, - VoidCallback? onEditingComplete,
- bool enabled = true,
- double cursorWidth = 2.0,
- double? cursorHeight,
- Radius? cursorRadius,
- Color? cursorColor,
- Brightness? keyboardAppearance,
- EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
- bool enableInteractiveSelection = true,
- TextSelectionControls? selectionControls,
- VoidCallback? onTap,
- MouseCursor? mouseCursor,
- InputCounterWidgetBuilder? buildCounter,
- ScrollController? scrollController,
- ScrollPhysics? scrollPhysics,
- Iterable<
String> ? autofillHints, - DragStartBehavior dragStartBehavior = DragStartBehavior.start,
- bool enableIMEPersonalizedLearning = true,
- AppPrivateCommandCallback? onAppPrivateCommand,
- BoxHeightStyle selectionHeightStyle = BoxHeightStyle.tight,
- BoxWidthStyle selectionWidthStyle = BoxWidthStyle.tight,
- ValueChanged<
T> ? onSubmitted, - String? restorationId,
Create new form field for an observable
For documentation about the various parameters, see the TextField class
and new TextField
, the constructor.
Implementation
ObserverFormField({
required this.observable,
this.formatter,
this.keyboardType,
Key? key,
//copy from constructor TextField
InputDecoration decoration = const InputDecoration(),
TextInputAction? textInputAction,
TextCapitalization textCapitalization = TextCapitalization.none,
TextStyle? style,
StrutStyle? strutStyle,
TextAlign textAlign = TextAlign.start,
TextAlignVertical? textAlignVertical,
TextDirection textDirection = TextDirection.ltr,
bool readOnly = false,
ToolbarOptions? toolbarOptions,
bool showCursor = true,
bool autofocus = false,
String obscuringCharacter = '•',
bool obscureText = false,
bool autocorrect = true,
SmartDashesType? smartDashesType,
SmartQuotesType? smartQuotesType,
bool enableSuggestions = true,
int? maxLines = 1,
int? minLines,
bool expands = false,
int? maxLength,
MaxLengthEnforcement? maxLengthEnforcement,
ValueChanged<T>? onChanged,
VoidCallback? onEditingComplete,
bool enabled = true,
double cursorWidth = 2.0,
double? cursorHeight,
Radius? cursorRadius,
Color? cursorColor,
Brightness? keyboardAppearance,
EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
bool enableInteractiveSelection = true,
TextSelectionControls? selectionControls,
VoidCallback? onTap,
MouseCursor? mouseCursor,
InputCounterWidgetBuilder? buildCounter,
ScrollController? scrollController,
ScrollPhysics? scrollPhysics,
Iterable<String>? autofillHints,
DragStartBehavior dragStartBehavior = DragStartBehavior.start,
bool enableIMEPersonalizedLearning = true,
AppPrivateCommandCallback? onAppPrivateCommand,
BoxHeightStyle selectionHeightStyle = BoxHeightStyle.tight,
BoxWidthStyle selectionWidthStyle = BoxWidthStyle.tight,
ValueChanged<T>? onSubmitted,
String? restorationId,
}) : super(
key: key,
initialValue: observable.value,
enabled: enabled,
builder: (field) {
final state = field as _ObserverFormFieldState<T>;
return ObserverWidget(
observable: state._err!,
builder: (context, String? err) => TextField(
controller: state._controller,
decoration: decoration
.applyDefaults(Theme.of(context).inputDecorationTheme)
.copyWith(errorText: err),
keyboardType: state._keyboardType,
focusNode: state._focusNode,
textInputAction: textInputAction,
textCapitalization: textCapitalization,
style: style,
strutStyle: strutStyle,
textAlign: textAlign,
textAlignVertical: textAlignVertical,
textDirection: textDirection,
readOnly: readOnly && observable is ObservableWritable,
toolbarOptions: toolbarOptions,
showCursor: showCursor,
autofocus: autofocus,
obscuringCharacter: obscuringCharacter,
obscureText: obscureText,
autocorrect: autocorrect,
smartDashesType: smartDashesType ??
(obscureText
? SmartDashesType.disabled
: SmartDashesType.enabled),
smartQuotesType: smartQuotesType ??
(obscureText
? SmartQuotesType.disabled
: SmartQuotesType.enabled),
enableSuggestions: enableSuggestions,
maxLines: maxLines,
minLines: minLines,
expands: expands,
maxLength: maxLength,
onChanged: (val) {
if (state._formatter!.isValid(val)) {
final v = state._getValue(val);
if (observable is ObservableWritable<T> && v is T) {
state._updating = true;
observable.value = v;
}
onChanged?.call(v);
}
},
onEditingComplete: onEditingComplete,
inputFormatters: <TextInputFormatter>[state._formatter!],
enabled: enabled,
cursorWidth: cursorWidth,
cursorHeight: cursorHeight,
cursorRadius: cursorRadius,
cursorColor: cursorColor,
keyboardAppearance: keyboardAppearance,
scrollPadding: scrollPadding,
enableInteractiveSelection: enableInteractiveSelection,
selectionControls: selectionControls,
onTap: onTap,
mouseCursor: mouseCursor,
buildCounter: buildCounter,
scrollController: scrollController,
scrollPhysics: scrollPhysics,
autofillHints: autofillHints,
dragStartBehavior: dragStartBehavior,
enableIMEPersonalizedLearning: enableIMEPersonalizedLearning,
maxLengthEnforcement: maxLengthEnforcement,
onAppPrivateCommand: onAppPrivateCommand,
selectionHeightStyle: selectionHeightStyle,
selectionWidthStyle: selectionWidthStyle,
onSubmitted: onSubmitted != null
? (_) => onSubmitted.call(observable.peek)
: null,
restorationId: restorationId,
),
);
},
);