MacosTextField.borderless constructor

const MacosTextField.borderless({
  1. Key? key,
  2. TextEditingController? controller,
  3. FocusNode? focusNode,
  4. BoxDecoration? decoration,
  5. BoxDecoration? focusedDecoration,
  6. EdgeInsets padding = const EdgeInsets.fromLTRB(2.0, 4.0, 2.0, 4.0),
  7. String? placeholder,
  8. TextStyle? placeholderStyle = _kDefaultPlaceholderStyle,
  9. Widget? prefix,
  10. OverlayVisibilityMode prefixMode = OverlayVisibilityMode.always,
  11. Widget? suffix,
  12. OverlayVisibilityMode suffixMode = OverlayVisibilityMode.always,
  13. OverlayVisibilityMode clearButtonMode = OverlayVisibilityMode.never,
  14. TextInputType? keyboardType,
  15. TextInputAction? textInputAction,
  16. TextCapitalization textCapitalization = TextCapitalization.none,
  17. TextStyle? style,
  18. StrutStyle? strutStyle,
  19. TextAlign textAlign = TextAlign.start,
  20. TextAlignVertical? textAlignVertical,
  21. bool readOnly = false,
  22. bool? showCursor,
  23. bool autofocus = false,
  24. String obscuringCharacter = '•',
  25. bool obscureText = false,
  26. bool autocorrect = true,
  27. SmartDashesType? smartDashesType,
  28. SmartQuotesType? smartQuotesType,
  29. bool enableSuggestions = true,
  30. int? maxLines = 1,
  31. int? minLines,
  32. bool expands = false,
  33. int? maxLength,
  34. MaxLengthEnforcement? maxLengthEnforcement,
  35. ValueChanged<String>? onChanged,
  36. VoidCallback? onEditingComplete,
  37. ValueChanged<String>? onSubmitted,
  38. List<TextInputFormatter>? inputFormatters,
  39. bool? enabled,
  40. double cursorWidth = 2.0,
  41. double? cursorHeight,
  42. Radius cursorRadius = const Radius.circular(2.0),
  43. Color? cursorColor,
  44. BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  45. BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  46. Brightness? keyboardAppearance,
  47. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  48. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  49. bool enableInteractiveSelection = true,
  50. TextSelectionControls? selectionControls,
  51. GestureTapCallback? onTap,
  52. ScrollController? scrollController,
  53. ScrollPhysics? scrollPhysics,
  54. Iterable<String>? autofillHints,
  55. String? restorationId,
  56. EditableTextContextMenuBuilder? contextMenuBuilder = _defaultContextMenuBuilder,
})

Creates a borderless macOS-style text field.

To provide a prefilled text entry, pass in a TextEditingController with an initial value to the controller parameter.

To provide a hint placeholder text that appears when the text entry is empty, pass a String to the placeholder parameter.

The maxLines property can be set to null to remove the restriction on the number of lines. In this mode, the intrinsic height of the widget will grow as the number of lines of text grows. By default, it is 1, meaning this is a single-line text field and will scroll horizontally when overflown. maxLines must not be zero.

The text cursor is not shown if showCursor is false or if showCursor is null (the default) and readOnly is true.

If specified, the maxLength property must be greater than zero.

The selectionHeightStyle and selectionWidthStyle properties allow changing the shape of the selection highlighting. These properties default to ui.BoxHeightStyle.tight and ui.BoxWidthStyle.tight respectively and must not be null.

The autocorrect, autofocus, clearButtonMode, dragStartBehavior, expands, maxLengthEnforcement, obscureText, prefixMode, readOnly, scrollPadding, suffixMode, textAlign, selectionHeightStyle, selectionWidthStyle, and enableSuggestions properties must not be null.

See also:

  • minLines, which is the minimum number of lines to occupy when the content spans fewer lines.
  • expands, to allow the widget to size itself to its parent's height.
  • maxLength, which discusses the precise meaning of "number of characters" and how it may differ from the intuitive meaning.

Implementation

const MacosTextField.borderless({
  super.key,
  this.controller,
  this.focusNode,
  this.decoration,
  this.focusedDecoration,
  this.padding = const EdgeInsets.fromLTRB(2.0, 4.0, 2.0, 4.0),
  this.placeholder,
  this.placeholderStyle = _kDefaultPlaceholderStyle,
  this.prefix,
  this.prefixMode = OverlayVisibilityMode.always,
  this.suffix,
  this.suffixMode = OverlayVisibilityMode.always,
  this.clearButtonMode = OverlayVisibilityMode.never,
  TextInputType? keyboardType,
  this.textInputAction,
  this.textCapitalization = TextCapitalization.none,
  this.style,
  this.strutStyle,
  this.textAlign = TextAlign.start,
  this.textAlignVertical,
  this.readOnly = false,
  this.showCursor,
  this.autofocus = false,
  this.obscuringCharacter = '•',
  this.obscureText = false,
  this.autocorrect = true,
  SmartDashesType? smartDashesType,
  SmartQuotesType? smartQuotesType,
  this.enableSuggestions = true,
  this.maxLines = 1,
  this.minLines,
  this.expands = false,
  this.maxLength,
  this.maxLengthEnforcement,
  this.onChanged,
  this.onEditingComplete,
  this.onSubmitted,
  this.inputFormatters,
  this.enabled,
  this.cursorWidth = 2.0,
  this.cursorHeight,
  this.cursorRadius = const Radius.circular(2.0),
  this.cursorColor,
  this.selectionHeightStyle = ui.BoxHeightStyle.tight,
  this.selectionWidthStyle = ui.BoxWidthStyle.tight,
  this.keyboardAppearance,
  this.scrollPadding = const EdgeInsets.all(20.0),
  this.dragStartBehavior = DragStartBehavior.start,
  this.enableInteractiveSelection = true,
  this.selectionControls,
  this.onTap,
  this.scrollController,
  this.scrollPhysics,
  this.autofillHints,
  this.restorationId,
  this.contextMenuBuilder = _defaultContextMenuBuilder,
})  : smartDashesType = smartDashesType ??
          (obscureText ? SmartDashesType.disabled : SmartDashesType.enabled),
      smartQuotesType = smartQuotesType ??
          (obscureText ? SmartQuotesType.disabled : SmartQuotesType.enabled),
      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 || (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 the following instead of setting it directly to avoid surprising the user by silently changing the value they set.
      assert(
          !identical(textInputAction, TextInputAction.newline) ||
              maxLines == 1 ||
              !identical(keyboardType, TextInputType.text),
          'Use keyboardType TextInputType.multiline when using TextInputAction.newline on a multiline TextField.'),
      keyboardType = keyboardType ??
          (maxLines == 1 ? TextInputType.text : TextInputType.multiline);