Ask the assistant
0/400
Your question is processed by an AI service and kept to improve answers. Do not enter personal data.

    TextFormField

    A text input field with validation and form submission. It works with the Form element to collect data.

    Type: multi-child

    TextFormField name:email
      #decoration hintText:"example@email.com"

    Main parameters

    Parameter Type Default Description
    name string — Field name for form submission
    initialValue string — Initial value
    autofocus bool false Focus automatically
    readOnly bool false Read only
    obscureText bool false Hide the text (password)
    obscuringCharacter string • Masking character
    maxLines int 1 Maximum lines
    minLines int — Minimum lines
    maxLength int — Maximum characters
    enabled bool — Enabled/disabled
    autocorrect bool true Autocorrection
    enableSuggestions bool true Input suggestions
    textAlign string start Text alignment
    canRequestFocus bool true Can receive focus

    Fine-tuning

    Parameters of the Flutter field that are rarely needed. The "Site" column says whether the parameter works on the site; the others act only in the app.

    Parameter Type Default Description Site
    keyboardType #keyboardType text On-screen keyboard type — as on TextField yes ( inputmode / type )
    textCapitalization string none none , words , sentences , characters yes ( autocapitalize )
    textInputAction string — The key shown instead of Enter on a phone: next , done , go , send , search … yes ( enterkeyhint )
    expands bool false Stretch the field over all of the parent's space. In the app expands:true does not work for now — the field fails with an error yes
    cursorColor color — Cursor color yes ( caret-color )
    cursorErrorColor color — Cursor color while the field shows an error no
    forceErrorText string — Show this error under the field regardless of #validators — for example, a server response yes
    selectAllOnFocus bool — Select all the text when the field gets focus no
    autofillHints #autofillHints — What autofill should offer: #autofillHints email , username , password … yes ( autocomplete )
    textDirection string ltr ltr or rtl — text direction yes ( dir )
    textAlignVertical string center Vertical alignment of the text in the field: top , center , bottom no
    showCursor bool — false — the cursor is not drawn yes (transparent caret)
    smartDashesType string enabled The system keyboard replacing -- with a dash: enabled / disabled no
    smartQuotesType string enabled Replacing straight quotes with typographic ones: enabled / disabled no
    maxLengthEnforcement string none How to enforce maxLength : enforced , truncateAfterCompositionEnds , none no
    onTapAlwaysCalled bool false Call the tap handler also on a repeated tap on a focused field no
    ignorePointers bool — true — the field ignores touch and mouse no
    cursorWidth double 2.0 Cursor thickness no
    cursorHeight double — Cursor height (by default — the line height) no
    cursorRadius #cursorRadius — Cursor corner radius: #cursorRadius circular 2 or elliptical x:… y:… no
    keyboardAppearance string light Theme of the iOS system keyboard: light / dark no
    scrollPadding #scrollPadding all 20 The margin scrolling leaves around the field when it shows it above the keyboard (like #padding ) no
    enableInteractiveSelection bool — false — the text cannot be selected and copied yes ( user-select:none )
    selectionHeightStyle string — Height of the selection highlight: tight , max , includeLineSpacingMiddle , includeLineSpacingTop , includeLineSpacingBottom , strut no
    selectionWidthStyle string — Width of the selection highlight: tight , max no
    restorationId string — Key for restoring the field's state after the system restarts the app no
    enableIMEPersonalizedLearning bool true false — asks the keyboard not to learn from the input (Android incognito mode) no
    mouseCursor string — Mouse cursor over the field: text , basic , click , forbidden … no
    cursorOpacityAnimates bool — Smooth cursor blinking instead of abrupt no
    dragStartBehavior string start When dragging a selection starts: start or down no
    clipBehavior string hardEdge Clipping of the field's content: none , hardEdge , antiAlias , antiAliasWithSaveLayer no
    stylusHandwritingEnabled bool as in the system Stylus handwriting input (Android, iPadOS) no
    hintLocales #hintLocales — Languages the keyboard offers first: #hintLocales ru:RU en:US no
    strutStyle #strutStyle — Minimum line height by a text style: #strutStyle fromTextStyle with #textStyle inside no

    Nested structures

    #decoration

    Styling of the input field. Supports hint, label, error, prefix/suffix, border and much more.

    TextFormField name:email
      #decoration
        labelText:"Email"
        hintText:"example@email.com"
        #enabledBorder outline
          #borderRadius circular 8
          #borderSide color:#585593 width:1
        #focusedBorder outline
          #borderRadius circular 8
          #borderSide color:#6C63FF width:2

    #style

    Style of the text inside the field.

    #validators

    Rules the value must satisfy. They are checked when the form is submitted — or immediately if the field is marked autovalidateMode:always .

    #validators
      #isEmpty "This field is required"
      #minLength 8 "At least eight characters"

    The rules run in the order they are written , and the message of the first one that objects is shown — so #isEmpty is written first, so that "required" reads before "too short".

    The last positional argument is the message. Without it the rule speaks for itself in English; your own text is the only way to get a translation.

    Rule Arguments What it checks
    #isEmpty — The value is not empty. The only one that an empty value does not pass
    #email — An address with a name, @ and a domain with a dot. Deliberately lenient; Cyrillic addresses pass
    #url — An http:// or https:// link. Only these two schemes: a field that accepts javascript: is a hole
    #phone — Digits with the punctuation people actually type, at least seven digits
    #numeric — Parses as a number. A decimal comma does not pass
    #minLength length Not shorter. Counts characters, not bytes
    #maxLength length Not longer
    #min number Not less. A non-number does not pass
    #max number Not greater
    #pattern regular expression Matches it. Anchors are up to the author: without them a match is searched anywhere
    #match field name Equals another field of the form — password confirmation. The name of a nonexistent field does not pass

    An empty value passes every rule except #isEmpty and #match . Otherwise an optional field could not be optional: an email left empty would report a wrong format.

    The field does not let an unknown rule name through — it names it in the message. A silent pass would mean a form that accepts anything.

    The rules run the same way in the app and on the site .

    Builder child elements

    • errorBuilder — a custom error widget
    • buildCounter — a custom character counter

    Examples

    Email field

    TextFormField name:email autofocus:true
      #decoration
        labelText:"Email"
        hintText:"example@email.com"
      #validators
        #isEmpty "Enter your email"
        #email "Invalid address"

    Password confirmation

    Form @password:"" @confirm:""
      Column
        TextFormField name:"password" obscureText:true
          #validators
            #minLength 8 "At least eight characters"
        TextFormField name:"confirm" obscureText:true
          #validators
            #match "password" "Passwords do not match"

    The field's value as you type

    value:$variable binds the field both ways — typing writes to the variable, changing the variable rewrites the text. This is separate from name: , which hands over the value on a successful submission.

    @query:""
    TextFormField value:$query onChanged:(value){query=value}

    Password field

    TextFormField name:password obscureText:true
      #decoration
        labelText:"Password"
      #validators
        #isEmpty "Enter your password"

    Multi-line field

    TextFormField name:comment maxLines:5 minLines:3
      #decoration
        labelText:"Comment"
        hintText:"Type your text..."

    See also

    • Text — displaying text (no input)
    • Button — a button to submit the form