How to limit number of characters in TextFormField?
use maxLength
TextFormField(
controller: _deskripsiController,
onFieldSubmitted: (String value){
setState(() {
_deskripsiController.text = value;
});
},
decoration: const InputDecoration(
border: const UnderlineInputBorder(),
labelText: "Deskripsi",
),
maxLength: 8,
)
Use inputFormatters
property. The following code would limit the textFormField to 42 in length :
new TextFormField(
inputFormatters: [
new LengthLimitingTextInputFormatter(42),
],
);
UPDATE: Import the package first. import 'package:flutter/services.dart';