想要做一個類似于手機編輯短信的樣式柴梆,輸入框的高度隨內(nèi)容增加陨溅,換行并且適應(yīng)高度。
FLutter中的 textField有一個屬性是maxLines绍在,初始值是1门扇,就是不管輸入多少內(nèi)容都只有一行不會換行雹有,但是注意到當(dāng)設(shè)置為null的時候就是行數(shù)不受限制
image
image
當(dāng)maxLines值為null時,keyboardType的值就是TextInputType.multiline臼寄。這樣輸入框的高度動態(tài)的變化霸奕。這時的輸入框是沒有高度限制的,若要有個最大高度吉拳,在外層包裹一個Container质帅,設(shè)置maxHeight和minHeigh即可。
Container(
constraints: BoxConstraints(
maxHeight: 200.0,
minHeight: 50.0,
),
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.all(Radius.circular(10))
),
padding: EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
child: TextField(
controller: _remarkTextController,
maxLines: null,
keyboardType: TextInputType.multiline,
autofocus: true,
decoration: InputDecoration.collapsed(
hintText: "備注",
),
),
)
er.gif
小伙伴們可以試試哦