TxFormField<T> constructor
TxFormField<T> ({
- required TxFormFieldBuilder<
T> builder, - Key? key,
- T? initialValue,
- FormFieldSetter<
T> ? onSaved, - FormFieldValidator<
T> ? validator, - AutovalidateMode? autovalidateMode = AutovalidateMode.onUserInteraction,
- String? restorationId,
- InputDecoration? decoration,
- bool? enabled,
- ValueChanged<
T?> ? onChanged, - String? hintText,
- TextAlign? textAlign,
- bool? bordered,
- String? labelText,
- Widget? label,
- bool? required,
- TextStyle? labelStyle,
- TextAlign? labelTextAlign,
- TextOverflow? labelOverflow,
- Color? tileColor,
- Axis? layoutDirection,
- EdgeInsetsGeometry? padding,
- FieldActionsBuilder<
T> ? actionsBuilder, - TxFormFieldBuilder<
T> ? trailingBuilder, - Widget? leading,
- double? horizontalGap,
- VisualDensity? visualDensity,
- ShapeBorder? shape,
- Color? iconColor,
- Color? textColor,
- TextStyle? leadingAndTrailingTextStyle,
- GestureTapCallback? onTap,
- double? minLeadingWidth,
- double? minLabelWidth,
- double? minVerticalPadding,
- bool? dense,
- bool? colon,
- Color? focusColor,
创建一个输入框组件
Implementation
TxFormField({
required TxFormFieldBuilder<T> builder,
super.key,
super.initialValue,
super.onSaved,
super.validator,
super.autovalidateMode = AutovalidateMode.onUserInteraction,
super.restorationId,
this.decoration,
bool? enabled,
this.onChanged,
this.hintText,
this.textAlign,
this.bordered,
this.labelText,
this.label,
bool? required,
TextStyle? labelStyle,
TextAlign? labelTextAlign,
TextOverflow? labelOverflow,
Color? tileColor,
Axis? layoutDirection,
EdgeInsetsGeometry? padding,
FieldActionsBuilder<T>? actionsBuilder,
TxFormFieldBuilder<T>? trailingBuilder,
Widget? leading,
double? horizontalGap,
VisualDensity? visualDensity,
ShapeBorder? shape,
Color? iconColor,
Color? textColor,
TextStyle? leadingAndTrailingTextStyle,
GestureTapCallback? onTap,
double? minLeadingWidth,
double? minLabelWidth,
double? minVerticalPadding,
bool? dense,
bool? colon,
Color? focusColor,
}) : required = required ?? false,
super(
builder: (field) {
final TxFormFieldState<T> state = field as TxFormFieldState<T>;
final List<InlineSpan> spans = [
if (required == true)
const TextSpan(
text: '*\t',
style: TextStyle(
color: Colors.red,
fontWeight: FontWeight.w900,
),
),
if (label != null)
WidgetSpan(
child: label,
alignment: PlaceholderAlignment.middle,
),
if (labelText != null && labelText.isNotEmpty)
TextSpan(text: labelText),
];
return TxTile(
content: builder(state),
label:
spans.isEmpty ? null : Text.rich(TextSpan(children: spans)),
labelTextAlign: labelTextAlign,
padding: padding,
actions: actionsBuilder == null ? null : actionsBuilder(field),
trailing: trailingBuilder == null ? null : trailingBuilder(field),
labelStyle: labelStyle,
horizontalGap: horizontalGap,
tileColor: tileColor,
layoutDirection: layoutDirection,
leading: leading,
visualDensity: visualDensity,
shape: shape,
iconColor: iconColor,
textColor: textColor,
leadingAndTrailingTextStyle: leadingAndTrailingTextStyle,
enabled: field.isEnabled,
onTap: onTap,
minLeadingWidth: minLeadingWidth,
minLabelWidth: minLabelWidth,
dense: dense,
colon: colon,
focusColor: focusColor,
);
},
enabled: enabled ?? decoration?.enabled ?? true,
);