TextField.maxLines
seems to be an option to limit the height of the Widget, not to limit the number of lines that can be input.
Is there a way to limit the number of inputable lines itself?
CodePudding user response:
Method1: You can set maxLines
along with maxLength
.
If you don't want to show counter text at TextField
bottom then add empty counterText
in InputDecoration
.
TextField(
maxLength: 10,
maxLines: 2,
decoration: InputDecoration(
counterText: ''
),
)
Method2: You can use inputFormatters
property:
import 'package:flutter/services.dart';
TextFormField(
inputFormatters: [
LengthLimitingTextInputFormatter(10),
]
)
CodePudding user response:
You can set define maxLines with maxLength eg. TextField(maxLines: 4, maxLength: 500)