CupertinoTextFormFieldRow constructor Null safety

CupertinoTextFormFieldRow(
  1. {Key? key,
  2. Widget? prefix,
  3. EdgeInsetsGeometry? padding,
  4. TextEditingController? controller,
  5. String? initialValue,
  6. FocusNode? focusNode,
  7. BoxDecoration? decoration,
  8. TextInputType? keyboardType,
  9. TextCapitalization textCapitalization = TextCapitalization.none,
  10. TextInputAction? textInputAction,
  11. TextStyle? style,
  12. StrutStyle? strutStyle,
  13. TextDirection? textDirection,
  14. TextAlign textAlign = TextAlign.start,
  15. TextAlignVertical? textAlignVertical,
  16. bool autofocus = false,
  17. bool readOnly = false,
  18. ToolbarOptions? toolbarOptions,
  19. bool? showCursor,
  20. String obscuringCharacter = '•',
  21. bool obscureText = false,
  22. bool autocorrect = true,
  23. SmartDashesType? smartDashesType,
  24. SmartQuotesType? smartQuotesType,
  25. bool enableSuggestions = true,
  26. int? maxLines = 1,
  27. int? minLines,
  28. bool expands = false,
  29. int? maxLength,
  30. ValueChanged<String>? onChanged,
  31. GestureTapCallback? onTap,
  32. VoidCallback? onEditingComplete,
  33. ValueChanged<String>? onFieldSubmitted,
  34. FormFieldSetter<String>? onSaved,
  35. FormFieldValidator<String>? validator,
  36. List<TextInputFormatter>? inputFormatters,
  37. bool? enabled,
  38. double cursorWidth = 2.0,
  39. double? cursorHeight,
  40. Color? cursorColor,
  41. Brightness? keyboardAppearance,
  42. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  43. bool enableInteractiveSelection = true,
  44. TextSelectionControls? selectionControls,
  45. ScrollPhysics? scrollPhysics,
  46. Iterable<String>? autofillHints,
  47. AutovalidateMode autovalidateMode = AutovalidateMode.disabled,
  48. String? placeholder,
  49. TextStyle? placeholderStyle = const TextStyle(fontWeight: FontWeight.w400, color: CupertinoColors.placeholderText)}
)

Creates a CupertinoFormRow containing a FormField that wraps a CupertinoTextField.

When a controller is specified, initialValue must be null (the default). If controller is null, then a TextEditingController will be constructed automatically and its text will be initialized to initialValue or the empty string.

The prefix parameter is displayed at the start of the row. Standard iOS guidelines encourage passing a Text widget to prefix to detail the nature of the input.

The padding parameter is used to pad the contents of the row. It is directly passed to CupertinoFormRow. If the padding parameter is null, CupertinoFormRow constructs its own default padding (which is the standard form row padding in iOS.) If no edge insets are intended, explicitly pass EdgeInsets.zero to padding.

For documentation about the various parameters, see the CupertinoTextField class and CupertinoTextField.borderless, the constructor.

Implementation

CupertinoTextFormFieldRow({
  super.key,
  this.prefix,
  this.padding,
  this.controller,
  String? initialValue,
  FocusNode? focusNode,
  BoxDecoration? decoration,
  TextInputType? keyboardType,
  TextCapitalization textCapitalization = TextCapitalization.none,
  TextInputAction? textInputAction,
  TextStyle? style,
  StrutStyle? strutStyle,
  TextDirection? textDirection,
  TextAlign textAlign = TextAlign.start,
  TextAlignVertical? textAlignVertical,
  bool autofocus = false,
  bool readOnly = false,
  ToolbarOptions? toolbarOptions,
  bool? showCursor,
  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,
  ValueChanged<String>? onChanged,
  GestureTapCallback? onTap,
  VoidCallback? onEditingComplete,
  ValueChanged<String>? onFieldSubmitted,
  super.onSaved,
  super.validator,
  List<TextInputFormatter>? inputFormatters,
  bool? enabled,
  double cursorWidth = 2.0,
  double? cursorHeight,
  Color? cursorColor,
  Brightness? keyboardAppearance,
  EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  bool enableInteractiveSelection = true,
  TextSelectionControls? selectionControls,
  ScrollPhysics? scrollPhysics,
  Iterable<String>? autofillHints,
  AutovalidateMode super.autovalidateMode = AutovalidateMode.disabled,
  String? placeholder,
  TextStyle? placeholderStyle = const TextStyle(
    fontWeight: FontWeight.w400,
    color: CupertinoColors.placeholderText,
  ),
})  : assert(initialValue == null || controller == null),
      assert(textAlign != null),
      assert(autofocus != null),
      assert(readOnly != null),
      assert(obscuringCharacter != null && obscuringCharacter.length == 1),
      assert(obscureText != null),
      assert(autocorrect != null),
      assert(enableSuggestions != null),
      assert(scrollPadding != null),
      assert(maxLines == null || maxLines > 0),
      assert(minLines == null || minLines > 0),
      assert(
        (maxLines == null) || (minLines == null) || (maxLines >= minLines),
        "minLines can't be greater than maxLines",
      ),
      assert(expands != null),
      assert(
        !expands || (maxLines == null && minLines == null),
        'minLines and maxLines must be null when expands is true.',
      ),
      assert(!obscureText || maxLines == 1, 'Obscured fields cannot be multiline.'),
      assert(maxLength == null || maxLength > 0),
      assert(enableInteractiveSelection != null),
      super(
        initialValue: controller?.text ?? initialValue ?? '',
        builder: (FormFieldState<String> field) {
          final _CupertinoTextFormFieldRowState state =
              field as _CupertinoTextFormFieldRowState;

          void onChangedHandler(String value) {
            field.didChange(value);
            if (onChanged != null) {
              onChanged(value);
            }
          }

          return CupertinoFormRow(
            prefix: prefix,
            padding: padding,
            error: (field.errorText == null) ? null : Text(field.errorText!),
            child: CupertinoTextField.borderless(
              controller: state._effectiveController,
              focusNode: focusNode,
              keyboardType: keyboardType,
              decoration: decoration,
              textInputAction: textInputAction,
              style: style,
              strutStyle: strutStyle,
              textAlign: textAlign,
              textAlignVertical: textAlignVertical,
              textCapitalization: textCapitalization,
              textDirection: textDirection,
              autofocus: autofocus,
              toolbarOptions: toolbarOptions,
              readOnly: readOnly,
              showCursor: showCursor,
              obscuringCharacter: obscuringCharacter,
              obscureText: obscureText,
              autocorrect: autocorrect,
              smartDashesType: smartDashesType,
              smartQuotesType: smartQuotesType,
              enableSuggestions: enableSuggestions,
              maxLines: maxLines,
              minLines: minLines,
              expands: expands,
              maxLength: maxLength,
              onChanged: onChangedHandler,
              onTap: onTap,
              onEditingComplete: onEditingComplete,
              onSubmitted: onFieldSubmitted,
              inputFormatters: inputFormatters,
              enabled: enabled,
              cursorWidth: cursorWidth,
              cursorHeight: cursorHeight,
              cursorColor: cursorColor,
              scrollPadding: scrollPadding,
              scrollPhysics: scrollPhysics,
              keyboardAppearance: keyboardAppearance,
              enableInteractiveSelection: enableInteractiveSelection,
              selectionControls: selectionControls,
              autofillHints: autofillHints,
              placeholder: placeholder,
              placeholderStyle: placeholderStyle,
            ),
          );
        },
      );