Styling TextField in Flutter (STF)


STF:    SOLD




Text fields allow users to type text into an app. They are used to create forms, send messages, create search experiences, and much more. In this recipe, explore how to create and style text fields.

Flutter provides two text fields: TextField and TextFormField.

TextField

TextField is the most commonly used text input widget.

By default, the TextField is decorated with an underline. You can add a label, icon, single-line hint text, and error text by providing an InputDecoration as the decoration property of TextField. To remove all decorations (including the underline and space allocated for the label), set the decoration to null.

TextField(
  decoration: InputDecoration(
    border: OutlineInputBorder(),
    hintText: 'Enter a search term',
  ),
),

TextFormField

TextFormField wraps TextField and integrates it with the attached Form. It provides additional functionality such as validation and integration with other FormField widgets.

TextFormField(
  decoration: const InputDecoration(
    border: UnderlineInputBorder(),
    labelText: 'Enter your username',
  ),
),

Post a Comment

Previous Next

نموذج الاتصال