Home > Net >  Automatically resize Flutter TextFormField content as the user is typing while keeping maxLines equa
Automatically resize Flutter TextFormField content as the user is typing while keeping maxLines equa

Time:01-06

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,
    )
)

CodePudding user response:

Use auto_size_text_field package

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