Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide letter counter from bottom of TextField in Flutter

Tags:

flutter

dart

People also ask

How do you customize a TextField in Flutter?

By default, a TextField is decorated with an underline. You can add a label, icon, inline hint text, and error text by supplying an InputDecoration as the decoration property of the TextField . To remove the decoration entirely (including the underline and the space reserved for the label), set the decoration to null.

How do I clean my TextField Flutter?

You can control the TextField in your Flutter App. The TextField widget of Flutter has an inbuilt method TextEditingController. clear() which is used to clear or empty the typed text inside the Text Input widget. The clear() method would empty the entered string text and set its default value is empty.


To hide counter value from TextField or TextFormField widget while using maxLength attribute, try following:

TextField(
  decoration: InputDecoration(
    hintText: "Email",
    counterText: "",
  ),
  maxLength: 40,
),

In this, I have set counterText attribute inside InputDecoration property with empty value. Hope it will help.


This is the proper approach, it will prevent extra space below the Text Field, and also avoid extra code to set a null widget.

You can use input formatters in TextField

The following is:

    inputFormatters:[
      LengthLimitingTextInputFormatter(1),
    ]

Thank You!


you can use InputDecoratoin to hide letter counter.

TextFormField(
   decoration: InputDecoration(
     labelText: "username",
     counterStyle: TextStyle(height: double.minPositive,),
     counterText: ""
)

You can hide the counter by adding counterText: '', inside the textfield decoration. It will simply display an empty String.


Simply set counter to Offstage() will do the trick.

TextField(
    maxLines: 1,
    decoration: InputDecoration(
      counter: Offstage(),
    ),
),

You can do:

TextField(
   maxLength: 10,
   buildCounter: (BuildContext context, { int currentLength, int maxLength, bool isFocused }) => null,
)