I'm facing a small problem. As you can see, i have set maxLength 1 of TextField in Flutter, But i'm unable to hide bottom label of text counter.
22 Answers
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.

- 4,718
- 8
- 47
- 72

- 12,515
- 6
- 21
- 30
-
9This is great if you just want to hide it, but it's still there and take up space often resulting in an uneven text box. Replacing maxLength with `TextField( inputFormatters: [LengthLimitingTextInputFormatter(mMaxLength)] )` Will solve it, but requires you to add an extra library to the file. – Joel Broström Feb 11 '19 at 12:58
-
1this is working but `counterText` taking space height and affecting the UI – Farhana Naaz Ansari Feb 19 '19 at 07:33
-
18for me doesn't keep the empty space, its being removed, running latest version of flutter helps? – voytez Oct 21 '19 at 14:09
-
@FarhanaNaazAnsari also set your helperText = ' ' . if it doesn't work wrap it with container – Pius T.K Jul 09 '21 at 17:53
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!

- 7,293
- 1
- 54
- 54

- 1,658
- 1
- 7
- 11
-
8It works, but requires you to import an extra library to the file: `import 'package:flutter/services.dart';` – Joel Broström Feb 11 '19 at 12:59
-
I used this method with `InputDecoration.collapsed`, but It's not working. However, user10481267's answer works. – Tokenyet Oct 10 '19 at 09:07
-
2It might be obvious, but `maxLength` parameter must be removed for this to work properly. – flomaster Oct 15 '19 at 12:21
you can use InputDecoratoin to hide letter counter.
TextFormField(
decoration: InputDecoration(
labelText: "username",
counterStyle: TextStyle(height: double.minPositive,),
counterText: ""
)

- 2,968
- 1
- 17
- 17
-
Question is related to TextField, not TextFormField. Thanks for your suggestion in case of TextFormField. – Kamlesh Feb 05 '21 at 08:53
-
1
You can hide the counter by adding counterText: ''
, inside the textfield decoration. It will simply display an empty String.

- 12,515
- 6
- 21
- 30

- 2,538
- 3
- 16
- 23
Simply set counter to Offstage() will do the trick.
TextField(
maxLines: 1,
decoration: InputDecoration(
counter: Offstage(),
),
),

- 351
- 3
- 3
-
1This solution still affects the GUI (displaces the input text above the max length counter). The best solution (atleast for my use-case) was the ``counterText=""`` solution. – SilSur Jul 31 '22 at 10:04
You can do:
TextField(
maxLength: 10,
buildCounter: (BuildContext context, { int currentLength, int maxLength, bool isFocused }) => null,
)
Most of the answers seem to work. Another way would be to assign the counter with a shrink SizeBox.
TextField(decoration: InputDecoration(
hintText: "Email",
counter: SizedBox.shrink()
),
maxLength: 40,
),

- 785
- 1
- 6
- 11
Add counterText: "", to InputDecoration
TextField(
decoration: InputDecoration(
counterText: "",
),
maxLength: 10,
),

- 29,388
- 11
- 94
- 103

- 351
- 3
- 7
This alone solved my problem!
TextField(
decoration: InputDecoration(
labelText: "Table Number",
counterText: ""
)

- 4,350
- 9
- 52
- 78

- 361
- 4
- 7
Whenever you don't need something in flutter just put an empty container!
TextField(
decoration: InputDecoration(
hintText: "Email",
counter: Container(),
),
maxLength: 20,
),
-
this also hides validation error message, not good solution if you still need it – kashlo Jun 21 '20 at 13:03
-
Empty containers aren't recommended for use. Better to use the OffStage widget or a SizedBox. – Tonny Bawembye Jul 21 '21 at 17:51
Simply set buildCounter to null.
It is a callback that generates a custom [InputDecorator.counter] widget
TextField(
maxLength: (some length),
buildCounter: (BuildContext context, {int currentLength, int maxLength, bool isFocused}) => null,
);

- 101
- 1
- 4
For null-safety use this:
TextField(
maxLength: 10,
buildCounter: (BuildContext context, {int? currentLength, int? maxLength, bool? isFocused}) => null,
)

- 1,326
- 1
- 16
- 31
-
1This is the best answer IMO to remove the counter completely since setting the "counter" parameter in the InputDecoration to OffStage() or other zero space widget may hide the counter, but I have noticed that there is a 4 pixel height padding that remains - so this "buildCounter" method completely removes it. – Pip Apr 28 '22 at 20:09
-
1I agree. This answer is the most flexible and isn't that too difficult to implement considering the added amount of control you now have. – enchance Oct 27 '22 at 06:56
You can use input formatters in TextField setting a limit to input and this is the best approach if you just want to hide the counter making a input limit.
import 'package:flutter/services.dart';
inputFormatters:[
LengthLimitingTextInputFormatter(1),
]
Or you can customize the decoration making a counter = Container():
decoration: InputDecoration(
hintText: "Email",
counter: Container(),
),
You if prefer to customize the buildCounter, here is how to do it properly (you can also customise the font, color etc). When you text field loses the focus the counter limits will disappears. Or you can just set
TextField(
controller: _clienteTextEditingController,
maxLength: 50,
buildCounter: (BuildContext context,
{int currentLength, int maxLength, bool isFocused}) {
return isFocused
? Text(
'The Input Limits are: $currentLength/$maxLength ',
style: new TextStyle(
fontSize: 10.0,
),
semanticsLabel: 'Input constraints',
)
: null;
},
),

- 7,293
- 1
- 54
- 54
you can use InputDecoratoin to hide the letter counter.
TextField(
keyboardType: TextInputType.number,
maxLength: 10,
decoration: InputDecoration(
**counterText:""**)
)

- 41,002
- 9
- 78
- 107

- 41
- 2
Another solution is to hide the counter widget by using SizedBox:
TextFormField(
...
decoration: InputDecoration(
contentPadding: EdgeInsets.all(10.0),
counter: new SizedBox(
height: 0.0,
)),
...
)

- 481
- 7
- 5
-
Good solution but this https://stackoverflow.com/a/51895946/1599713 is better – Husam Dec 17 '19 at 16:30
You can follow the below codes.
TextField(
controller: myController,
maxLength: 3,
buildCounter: (BuildContext context, {int currentLength, int maxLength, bool isFocused}) =>null
)

- 1,423
- 1
- 8
- 19
Container(
height: 48,
alignment: Alignment.centerLeft,
padding: EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration(
border: Border.all(
color: CustomColors.kToDark,
),
color: CustomColors.White,
borderRadius: BorderRadius.all(Radius.circular(8))),
child: TextFormField(
textAlign: TextAlign.left,
cursorColor: CustomColors.kToDark,
maxLength: 30,
controller: _titleController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
counterText: "",
border: InputBorder.none,
isDense: true,
contentPadding: EdgeInsets.all(0))),
),
Use counterText: "" inside InputDecoration()

- 276
- 2
- 5
In case you are still looking for the answer in 2020 here goes:
decoration: InputDecoration(
counter: Spacer(),
labelText: "National ID #",
border: InputBorder.none,
hintText: 'e.g 01-1234567A12',
hintStyle: TextStyle(color: Colors.grey)),
In the TextField, use a Spacer()
as counter... hope this helps, i dont know if it breaks anything else but mine works fine.

- 2,455
- 13
- 33
- 37

- 21
- 2
Not pretty but works by removing the counter:
TextFormField(
buildCounter: (
BuildContext context, {
required int currentLength,
int? maxLength,
required bool isFocused,
}) => null,

- 15,847
- 14
- 87
- 146
Use a SizedBox with zero height and width:
TextField(
maxLength: 400,
decoration: InputDecoration(
counter: SizedBox(
width: 0,
height: 0,
),),)

- 119
- 10
As mentioned by @user10481267 in the best answer would be use buildCounter
property. This gives extreme flexibility and you can even decide dynamically to show the counter or not.
I was building a dynamic form with the required properties in JSON. My implementation is as follows:
TextFormField(
buildCounter: (BuildContext context,
{
int currentLength,
int maxLength,
bool isFocused}) {
if (isFocused)
return formFields[index]["max"] == null
? null
: Text(
'$currentLength / $maxLength',
semanticsLabel: 'character count',
);
else
return null;
},
maxLength: formFields[index]["max"] ?? 100,
decoration: new InputDecoration(
labelText: formFields[index]["hint"] ?? "",
fillColor: Colors.green,
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(15.0),
borderSide: new BorderSide(),
),
)
)

- 1,803
- 2
- 24
- 48