[英]Is there a way to dynamically change the Flutter TextField's maxLines?
我有一個像這樣的TextField:
new Flexible(
fit: FlexFit.loose,
child: new Container(
alignment: FractionalOffset.topLeft,
child: new TextField(
decoration: new InputDecoration(
hintText: 'Add a note',
),
maxLines: 1,
onChanged: (value) => _showSaveOptions(value),
),
),
),
我想讓我的TextField開始將maxLines
設置為1,但是當我輸入時,我希望maxLines增加,以便所有文本保留在頁面上,我不必向上滾動。 但是,我也不想從設置為5或10的maxLines
開始,因為空TextField占用了更多的空間。 我想要實現的行為的一個示例是在Google表單中的長答案文本選項中,它以一行開頭: 並在我輸入時展開:
我已經考慮將maxLines
設置為一個計數器,每當用戶點擊一個換行符時該計數器就會遞增,但是如何確定用戶何時填滿一行呢?
它看起來像一個文本區域。 你可以試試maxLines
maxLines:8
TextField(
maxLines: 8,
decoration: InputDecoration(hintText: "Enter your text here", border: OutlineInputBorder(),
labelText: 'Post Body'),
),
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.