FormTextField<TValue> constructor

const FormTextField<TValue>({
  1. FormController<TValue>? form,
  2. Key? key,
  3. TextEditingController? controller,
  4. FormAffixStyle? prefix,
  5. FormAffixStyle? suffix,
  6. FormStyle? style,
  7. TextInputType keyboardType = TextInputType.text,
  8. int? maxLength,
  9. VoidCallback? onTap,
  10. int? minLength,
  11. int maxLines = 1,
  12. int minLines = 1,
  13. bool expands = false,
  14. String? hintText,
  15. String? labelText,
  16. String? lengthErrorText,
  17. List<String> suggestion = const [],
  18. bool enabled = true,
  19. bool readOnly = false,
  20. bool obscureText = false,
  21. String? counterText = "",
  22. String? counterbuilder(
    1. String text
    )?,
  23. void onDeleteSuggestion(
    1. String value
    )?,
  24. String? validator(
    1. String? value
    )?,
  25. List<TextInputFormatter>? inputFormatters,
  26. TValue onSaved(
    1. String value
    )?,
  27. void onSubmitted(
    1. String? value
    )?,
  28. void onChanged(
    1. String? value
    )?,
  29. bool? showCursor,
  30. bool autofocus = false,
  31. bool autocorrect = false,
  32. bool selectOnFocus = false,
  33. FocusNode? focusNode,
  34. String? emptyErrorText,
  35. String? initialValue,
  36. VoidCallback? onTapSuggestion,
  37. SuggestionStyle? suggestionStyle,
  38. bool keepAlive = true,
  39. bool clearOnSubmitted = false,
  40. void onFocusChanged(
    1. String? value,
    2. bool hasFocus
    )?,
})

Widgets for text fields for forms.

Place under the Form that gave FormController.key, or pass FormController to form.

When FormController is passed to form, onSaved must also be passed together. The contents of onSaved will be used to save the data.

Enter the initial value given by FormController.value in initialValue.

Each time the content is changed, onChanged is executed.

When FormController.validate is executed, validation and data saving are performed.

Only when emptyErrorText is specified, emptyErrorText will be displayed as an error if no characters are entered. Only when lengthErrorText is specified, if the number of characters entered is less than minLength, it is displayed as lengthErrorText.

Other error checking is performed by specifying validator. If a string other than Null is returned in the callback, the string is displayed as an error statement. If Null is returned, it is processed as no error.

The onSubmitted process is executed when the Enter key or other keys are pressed.

If suggestion is specified, suggestions will be displayed according to what you have entered.

If onDeleteSuggestion is specified, a delete button is displayed on the displayed suggestions, and if the button is pressed, the process is executed when the suggestion is deleted.

If enabled is false, the text is deactivated.

If readOnly is set to true, the activation is displayed, but the text cannot be changed.

If obscureText is set to true, the input string will be hidden. Please use this function for inputting passwords, etc.

If inputFormatters is specified, it is possible to restrict the characters to be entered.

フォーム用のテキストフィールド用のウィジェット。

FormController.keyを与えたForm配下に配置、もしくはformFormControllerを渡します。

formFormControllerを渡した場合、一緒にonSavedも渡してください。データの保存はonSavedの内容が実行されます。

initialValueFormController.valueから与えられた初期値を入力します。

内容が変更される度onChangedが実行されます。

FormController.validateが実行された場合、バリデーションとデータの保存を行ないます。

emptyErrorTextが指定されている時に限り、文字が入力されていない場合emptyErrorTextがエラーとして表示されます。 lengthErrorTextが指定されている時に限り、minLengthより入力された文字数が少ない場合lengthErrorTextとして表示されます。

それ以外のエラーチェックはvalidatorを指定することで行ないます。 コールバック内でNull以外を返すようにするとその文字列がエラー文として表示されます。Nullの場合はエラーなしとして処理されます。

Enterキーなどが押された場合の処理をonSubmittedが実行されます。

suggestionが指定されている場合、入力した内容に応じてサジェストが表示されます。

onDeleteSuggestionが指定されている場合、表示されたサジェストに削除ボタンが表示され、ボタンが押された場合、サジェスト削除時の処理が実行されます。

enabledfalseになるとテキストが非有効化されます。

readOnlytrueになっている場合は、有効化の表示になりますが、テキストが変更できなくなります。

obscureTexttrueになると入力された文字列が隠されます。パスワードの入力などにご利用ください。

inputFormattersが指定されると入力される文字を制限することが可能です。

Implementation

const FormTextField({
  this.form,
  super.key,
  this.controller,
  this.prefix,
  this.suffix,
  this.style,
  this.keyboardType = TextInputType.text,
  this.maxLength,
  this.onTap,
  this.minLength,
  this.maxLines = 1,
  this.minLines = 1,
  this.expands = false,
  this.hintText,
  this.labelText,
  this.lengthErrorText,
  this.suggestion = const [],
  this.enabled = true,
  this.readOnly = false,
  this.obscureText = false,
  this.counterText = "",
  this.counterbuilder,
  this.onDeleteSuggestion,
  this.validator,
  this.inputFormatters,
  this.onSaved,
  this.onSubmitted,
  this.onChanged,
  this.showCursor,
  this.autofocus = false,
  this.autocorrect = false,
  this.selectOnFocus = false,
  this.focusNode,
  this.emptyErrorText,
  this.initialValue,
  this.onTapSuggestion,
  this.suggestionStyle,
  this.keepAlive = true,
  this.clearOnSubmitted = false,
  this.onFocusChanged,
}) : assert(
        (form == null && onSaved == null) ||
            (form != null && onSaved != null),
        "Both are required when using [form] or [onSaved].",
      );