Search code examples
flutterpasswordstext-formatting

How to extend the line under text form field till under visibility icon?


I have a text form field to enter password, I have added a visibility icon button with the field in a row. How do I extend the underline till under the icon? (There is a validator in the text form field, so I want the exact same line extended so that the behavior is same).


Solution

  • Define the IconButton as a prefixIcon within the TextFormField:

    child: TextFormField(
      decoration: InputDecoration(
        prefixIcon: IconButton(
          icon: Icon(Icons.visibility),
          onPressed: () {},
        ),
      ),
      ...
    ),