TxFormField<T> constructor

TxFormField<T>({
  1. required TxFormFieldBuilder<T> builder,
  2. Key? key,
  3. T? initialValue,
  4. FormFieldSetter<T>? onSaved,
  5. FormFieldValidator<T>? validator,
  6. AutovalidateMode? autovalidateMode = AutovalidateMode.onUserInteraction,
  7. String? restorationId,
  8. InputDecoration? decoration,
  9. bool? enabled,
  10. ValueChanged<T?>? onChanged,
  11. String? hintText,
  12. TextAlign? textAlign,
  13. bool? bordered,
  14. String? labelText,
  15. Widget? label,
  16. bool? required,
  17. TextStyle? labelStyle,
  18. TextAlign? labelTextAlign,
  19. TextOverflow? labelOverflow,
  20. Color? tileColor,
  21. Axis? layoutDirection,
  22. EdgeInsetsGeometry? padding,
  23. FieldActionsBuilder<T>? actionsBuilder,
  24. TxFormFieldBuilder<T>? trailingBuilder,
  25. Widget? leading,
  26. double? horizontalGap,
  27. VisualDensity? visualDensity,
  28. ShapeBorder? shape,
  29. Color? iconColor,
  30. Color? textColor,
  31. TextStyle? leadingAndTrailingTextStyle,
  32. GestureTapCallback? onTap,
  33. double? minLeadingWidth,
  34. double? minLabelWidth,
  35. double? minVerticalPadding,
  36. bool? dense,
  37. bool? colon,
  38. 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,
      );