Automatically resize Flutter TextFormField content as the user is typing while keeping maxLines equal to 1

Issue

I am using TextFormField in my Flutter app to get the email address of users. Some email addresses are long and so, if I keep typing, it will go out of the box. See how the first few letters of the email in the image below are outside the box.

enter image description here

Below is the code (just a simple TextFormField). I want the text to automatically resize while remaining in one line and also I can see all the text. Is there a way to do that?

SizedBox(
    width: ScreenUtil().setWidth(407),
    height: ScreenUtil().setHeight(69),
    child: TextFormField(
      textAlign: TextAlign.center,
      autocorrect: false,
      textCapitalization: TextCapitalization.none,
      keyboardType: TextInputType.emailAddress,
    )
)

Solution

Use auto_size_text_field package

AutoSizeTextField(
  controller: _textEditingController,
  style: TextStyle(fontSize: 20),
  maxLines: 1,
)

Answered By – AzerSD

Answer Checked By – Katrina (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.