Skip to main content
The Stac TextFormField allows you to build a Flutter TextFormField widget using JSON. To know more about the TextFormField widget in Flutter, refer to the official documentation.

Properties

PropertyTypeDescription
idStringThe identifier for the text form field.
compareIdStringThe identifier to compare with another text form field.
decorationStacInputDecorationThe decoration to show around the text form field.
initialValueStringThe initial value of the text form field.
keyboardTypeStacTextInputTypeThe type of keyboard to use for editing the text.
textInputActionStacTextInputActionThe action button to use for the keyboard.
textCapitalizationStacTextCapitalizationHow the text should be capitalized. Defaults to TextCapitalization.none.
styleStacTextStyleThe style to use for the text.
textAlignStacTextAlignHow the text should be aligned. Defaults to TextAlign.start.
textAlignVerticalStacTextAlignVerticalHow the text should be aligned vertically.
textDirectionStacTextDirectionThe direction of the text.
readOnlyboolWhether the text form field is read-only. Defaults to false.
showCursorboolWhether to show the cursor.
autofocusboolWhether the text form field should focus itself if nothing else is already focused. Defaults to false.
obscuringCharacterStringThe character to use for obscuring text. Defaults to .
maxLinesintThe maximum number of lines for the text.
minLinesintThe minimum number of lines for the text.
maxLengthintThe maximum number of characters for the text.
obscureTextboolWhether to obscure the text.
autocorrectboolWhether to enable autocorrect. Defaults to true.
smartDashesTypeStacSmartDashesTypeThe type of smart dashes to use.
smartQuotesTypeStacSmartQuotesTypeThe type of smart quotes to use.
maxLengthEnforcementStacMaxLengthEnforcementHow the max length limit should be enforced.
expandsboolWhether the text form field should expand to fill its parent. Defaults to false.
keyboardAppearanceStacBrightnessThe appearance of the keyboard.
scrollPaddingStacEdgeInsetsThe amount of space by which to inset the text form field when scrolling. Defaults to StacEdgeInsets(bottom: 20, top: 20, left: 20, right: 20).
restorationIdStringThe restoration ID to save and restore the text form field’s state.
enableIMEPersonalizedLearningboolWhether to enable personalized learning in the IME. Defaults to true.
enableSuggestionsboolWhether to enable suggestions. Defaults to true.
enabledboolWhether the text form field is enabled.
cursorWidthdoubleThe width of the cursor. Defaults to 2.
cursorHeightdoubleThe height of the cursor.
cursorColorStacColorThe color of the cursor.
hintTextStringThe hint text to display.
autovalidateModeStacAutovalidateModeThe mode to use for autovalidation.
inputFormattersList<StacInputFormatter>The list of input formatters to apply to the text. Defaults to an empty list.
validatorRulesList<StacFormFieldValidator>The list of validator rules to apply to the text. Defaults to an empty list.

StacInputDecoration

decoration supports Flutter input decoration fields such as labelText, hintText, prefixIcon, suffixIcon, borders, fill colors, and floatingLabelBehavior.
PropertyTypeDescription
floatingLabelBehaviorStringControls when the label floats. Supported values: auto, always, never.

Input Formatters

Use inputFormatters to restrict or transform user input. The supported formatter type values are allow, deny, and mask.
PropertyTypeDescription
typeStringFormatter type: allow, deny, or mask.
ruleStringRegular expression used by the formatter.
maskStringMask pattern used when type is mask; # consumes matching input values.
{
  "inputFormatters": [
    {
      "type": "mask",
      "rule": "\\d",
      "mask": "##/##/####"
    }
  ]
}

Validator Rules

Use validatorRules to validate user input. Each entry is a StacFormFieldValidator with a rule, an optional message shown when validation fails, and an optional options map for parameterized rules.
PropertyTypeDescription
ruleStringThe validator to apply (see below).
messageStringError message shown when validation fails. Defaults to Invalid input when omitted.
optionsMapArguments for parameterized rules. Ignored by rules that take no arguments.
Validators are powered by the flutter_validators package.
flutter_validators treats an empty string as invalid (e.g. isEmail('') is false), so any field with validatorRules is effectively required — an empty value fails validation. There is no built-in “validate only when filled” option. For an optional field, omit validatorRules; if you need conditional validation, handle the blank-input check in your app before applying the rules.
No-argument rules: isAlpha, isAlphanumeric, isAscii, isBase32, isBase58, isBoolean, isCreditCard, isDate, isDecimal, isEmail, isFQDN, isHexColor, isHexadecimal, isInt, isIP, isJson, isJWT, isLatLong, isLowercase, isMACAddress, isMD5, isMongoId, isNumeric, isOctal, isPhone, isPort, isSemVer, isSlug, isUppercase, isURL, isUUID. Parameterized rules (read arguments from options):
RuleOptions
isLengthmin (int), max (int, optional)
isByteLengthmin (int), max (int, optional)
isFloatmin (double, optional), max (double, optional)
isBase64urlSafe (bool)
isStrongPasswordminLength, minLowercase, minUppercase, minNumbers, minSymbols
containsseed (String), ignoreCase (bool), minOccurrences (int)
equalscomparison (String)
isInvalues (List of String)
matchespattern (String) — a raw regular expression
comparefieldId (String) — id of another field to compare values with
The matches rule matches the pattern anywhere in the value, so anchor it with ^...$ for a full-string match. The compare rule is useful for confirm-password fields. Remember that every rule fails on empty input, so a field carrying any of these rules is treated as required.
{
  "type": "textFormField",
  "id": "password",
  "obscureText": true,
  "validatorRules": [
    {
      "rule": "isStrongPassword",
      "message": "Use a stronger password"
    },
    {
      "rule": "isLength",
      "options": { "min": 8, "max": 32 },
      "message": "Password must be 8-32 characters"
    }
  ]
}

Example

StacTextFormField(
  id: 'date',
  autovalidateMode: StacAutovalidateMode.onUserInteraction,
  inputFormatters: [
    StacInputFormatter(
      type: StacInputFormatterType.mask,
      rule: r'\d',
      mask: '##/##/####',
    ),
  ],
  style: StacTextStyle(fontSize: 16, fontWeight: StacFontWeight.w400, height: 1.5),
  decoration: StacInputDecoration(
    labelText: 'Date of birth',
    hintText: 'DD/MM/YYYY',
    floatingLabelBehavior: 'always',
    filled: true,
    fillColor: StacColors.white,
    border: StacOutlineInputBorder(borderRadius: 8, color: '#24151D29'),
  ),
)