MTextField constructor

const MTextField({
  1. Key? key,
  2. TextEditingController? controller,
  3. FocusNode? focusNode,
  4. UndoHistoryController? undoController,
  5. InputDecoration? decoration,
  6. TextInputType? keyboardType,
  7. TextInputAction? textInputAction,
  8. TextCapitalization textCapitalization = TextCapitalization.none,
  9. TextStyle? style,
  10. StrutStyle? strutStyle,
  11. TextAlign textAlign = TextAlign.start,
  12. TextAlignVertical? textAlignVertical,
  13. TextDirection? textDirection,
  14. bool readOnly = false,
  15. bool? showCursor,
  16. bool autofocus = false,
  17. MaterialStatesController? statesController,
  18. String obscuringCharacter = '•',
  19. bool obscureText = false,
  20. bool autocorrect = true,
  21. SmartDashesType? smartDashesType,
  22. SmartQuotesType? smartQuotesType,
  23. bool enableSuggestions = true,
  24. int? maxLines = 1,
  25. int? minLines,
  26. bool expands = false,
  27. int? maxLength,
  28. MaxLengthEnforcement? maxLengthEnforcement,
  29. ValueChanged<String>? onChanged,
  30. VoidCallback? onEditingComplete,
  31. ValueChanged<String>? onSubmitted,
  32. AppPrivateCommandCallback? onAppPrivateCommand,
  33. List<TextInputFormatter>? inputFormatters,
  34. bool? enabled,
  35. double cursorWidth = 2.0,
  36. double? cursorHeight,
  37. Radius? cursorRadius,
  38. bool? cursorOpacityAnimates,
  39. Color? cursorColor,
  40. Color? cursorErrorColor,
  41. BoxHeightStyle selectionHeightStyle = ui.BoxHeightStyle.tight,
  42. BoxWidthStyle selectionWidthStyle = ui.BoxWidthStyle.tight,
  43. Brightness? keyboardAppearance,
  44. EdgeInsets scrollPadding = const EdgeInsets.all(20.0),
  45. DragStartBehavior dragStartBehavior = DragStartBehavior.start,
  46. bool? enableInteractiveSelection,
  47. TextSelectionControls? selectionControls,
  48. GestureTapCallback? onTap,
  49. bool onTapAlwaysCalled = false,
  50. TapRegionCallback? onTapOutside,
  51. MouseCursor? mouseCursor,
  52. InputCounterWidgetBuilder? buildCounter,
  53. ScrollController? scrollController,
  54. ScrollPhysics? scrollPhysics,
  55. Iterable<String>? autofillHints = const <String>[],
  56. ContentInsertionConfiguration? contentInsertionConfiguration,
  57. Clip clipBehavior = Clip.hardEdge,
  58. String? restorationId,
  59. bool scribbleEnabled = true,
  60. bool enableIMEPersonalizedLearning = true,
  61. EditableTextContextMenuBuilder? contextMenuBuilder = _defaultContextMenuBuilder,
  62. bool canRequestFocus = true,
  63. SpellCheckConfiguration? spellCheckConfiguration,
  64. TextMagnifierConfiguration? magnifierConfiguration,
  65. double? fontSize,
  66. FontWeight? fontWeight,
  67. Color? color,
  68. bool isBold = false,
  69. bool forceStrutHeight = false,
  70. bool? filled,
  71. InputBorder? errorBorder,
  72. InputBorder? focusedBorder,
  73. InputBorder? focusedErrorBorder,
  74. InputBorder? disabledBorder,
  75. InputBorder? enabledBorder,
  76. InputBorder? border,
  77. String? text,
  78. Color? fillColor,
  79. double? width,
  80. double? height,
  81. BoxConstraints? constraints,
  82. BorderRadius? borderRadius,
  83. double? radius,
  84. BorderSide? side,
  85. MTextFieldBorderStyle borderStyle = MTextFieldBorderStyle.underline,
  86. double? gapPadding,
  87. Widget? icon,
  88. Color? iconColor,
  89. Widget? label,
  90. String? labelText,
  91. TextStyle? labelStyle,
  92. TextStyle? floatingLabelStyle,
  93. String? helperText,
  94. TextStyle? helperStyle,
  95. int? helperMaxLines,
  96. String? hintText,
  97. Color? hintColor,
  98. TextStyle? hintStyle,
  99. TextDirection? hintTextDirection,
  100. int? hintMaxLines,
  101. Duration? hintFadeDuration,
  102. Widget? error,
  103. String? errorText,
  104. TextStyle? errorStyle,
  105. int? errorMaxLines,
  106. FloatingLabelBehavior? floatingLabelBehavior,
  107. FloatingLabelAlignment? floatingLabelAlignment,
  108. bool? isCollapsed,
  109. bool? isDense,
  110. EdgeInsetsGeometry? contentPadding,
  111. Widget? prefixIcon,
  112. BoxConstraints? prefixIconConstraints,
  113. Widget? prefix,
  114. String? prefixText,
  115. TextStyle? prefixStyle,
  116. Color? prefixIconColor,
  117. Widget? suffixIcon,
  118. Widget? suffix,
  119. String? suffixText,
  120. TextStyle? suffixStyle,
  121. Color? suffixIconColor,
  122. BoxConstraints? suffixIconConstraints,
  123. EdgeInsetsGeometry? suffixPadding,
  124. EdgeInsetsGeometry? suffixIconPadding,
  125. Widget? counter,
  126. String? counterText,
  127. TextStyle? counterStyle,
  128. bool? alignLabelWithHint,
  129. Color? focusColor,
  130. Color? hoverColor,
  131. String? semanticCounterText,
})

Creates a Material Design TextField.

Implementation

const MTextField({
  super.key,
  this.controller,
  this.focusNode,
  this.undoController,
  this.decoration,
  TextInputType? keyboardType,
  this.textInputAction,
  this.textCapitalization = TextCapitalization.none,
  this.style,
  this.strutStyle,
  this.textAlign = TextAlign.start,
  this.textAlignVertical,
  this.textDirection,
  this.readOnly = false,
  this.showCursor,
  this.autofocus = false,
  this.statesController,
  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.onAppPrivateCommand,
  this.inputFormatters,
  this.enabled,
  this.cursorWidth = 2.0,
  this.cursorHeight,
  this.cursorRadius,
  this.cursorOpacityAnimates,
  this.cursorColor,
  this.cursorErrorColor,
  this.selectionHeightStyle = ui.BoxHeightStyle.tight,
  this.selectionWidthStyle = ui.BoxWidthStyle.tight,
  this.keyboardAppearance,
  this.scrollPadding = const EdgeInsets.all(20.0),
  this.dragStartBehavior = DragStartBehavior.start,
  bool? enableInteractiveSelection,
  this.selectionControls,
  this.onTap,
  this.onTapAlwaysCalled = false,
  this.onTapOutside,
  this.mouseCursor,
  this.buildCounter,
  this.scrollController,
  this.scrollPhysics,
  this.autofillHints = const <String>[],
  this.contentInsertionConfiguration,
  this.clipBehavior = Clip.hardEdge,
  this.restorationId,
  this.scribbleEnabled = true,
  this.enableIMEPersonalizedLearning = true,
  this.contextMenuBuilder = _defaultContextMenuBuilder,
  this.canRequestFocus = true,
  this.spellCheckConfiguration,
  this.magnifierConfiguration,
  this.fontSize,
  this.fontWeight,
  this.color,
  this.isBold = false,
  this.forceStrutHeight = false,
  this.filled,
  this.errorBorder,
  this.focusedBorder,
  this.focusedErrorBorder,
  this.disabledBorder,
  this.enabledBorder,
  this.border,
  this.text,
  this.fillColor,
  this.width,
  this.height,
  this.constraints,
  this.borderRadius,
  this.radius,
  this.side,
  this.borderStyle = MTextFieldBorderStyle.underline,
  this.gapPadding,
  this.icon,
  this.iconColor,
  this.label,
  this.labelText,
  this.labelStyle,
  this.floatingLabelStyle,
  this.helperText,
  this.helperStyle,
  this.helperMaxLines,
  this.hintText,
  this.hintColor,
  this.hintStyle,
  this.hintTextDirection,
  this.hintMaxLines,
  this.hintFadeDuration,
  this.error,
  this.errorText,
  this.errorStyle,
  this.errorMaxLines,
  this.floatingLabelBehavior,
  this.floatingLabelAlignment,
  this.isCollapsed,
  this.isDense,
  this.contentPadding,
  this.prefixIcon,
  this.prefixIconConstraints,
  this.prefix,
  this.prefixText,
  this.prefixStyle,
  this.prefixIconColor,
  this.suffixIcon,
  this.suffix,
  this.suffixText,
  this.suffixStyle,
  this.suffixIconColor,
  this.suffixIconConstraints,
  this.suffixPadding,
  this.suffixIconPadding,
  this.counter,
  this.counterText,
  this.counterStyle,
  this.alignLabelWithHint,
  this.focusColor,
  this.hoverColor,
  this.semanticCounterText,
})  : assert(obscuringCharacter.length == 1),
      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 == TextField.noMaxLength || 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),
      enableInteractiveSelection = enableInteractiveSelection ?? (!readOnly || !obscureText);