在
flutter
中遇到這樣一種情況鼠冕,當(dāng)設(shè)置TextField
的maxLines
的值大于1時(shí),其初始高度會(huì)隨著maxLines
的變化而變化嚼沿,完全不能像微信輸入框一樣高度可以隨著文字行數(shù)變化丈牢,查看api發(fā)現(xiàn)將maxLines
設(shè)置為null
,再將keyboardType
設(shè)置為TextInputType.multiline
涩哟,就會(huì)隨著高度變化而變化,但是這樣的效果就是沒(méi)有一個(gè)最大高度盼玄,故在外層包含一個(gè)Container
并設(shè)置其maxHeight
和minHeight
就可以完美解決。
代碼如下:
return Container(
color: Colors.red,
constraints: BoxConstraints(
maxHeight: 144.0,
maxWidth: _screenWidth(),
minHeight: 48.0,
minWidth: _screenWidth()),
padding: EdgeInsets.only(
left: 16.0, right: 16.0, top: 8.0, bottom: 4.0),
child: TextField(
maxLines: null,
keyboardType: TextInputType.multiline,
decoration: InputDecoration.collapsed(
hintText: "Write a comment",
),
),
);
double _screenWidth() {
return MediaQuery.of(context).size.width;
}
LinearProgressIndicator組件的使用
//LinearProgressIndicator本身不能設(shè)置高度潜腻,
// 可以包一層父容器設(shè)置高度來(lái)間接設(shè)置LinearProgressIndicator的高度
Container(
padding: EdgeInsets.all(20),
child: Container(
height: 30, //設(shè)置高度
child: LinearProgressIndicator(
//0~1的浮點(diǎn)數(shù)埃儿,用來(lái)表示進(jìn)度多少;
// 如果 value 為 null 或空,則顯示一個(gè)動(dòng)畫融涣,否則顯示一個(gè)定值
value: 0.8,
//animation類型的參數(shù)童番,用來(lái)設(shè)定進(jìn)度值的顏色精钮,默認(rèn)為主題色
valueColor:
new AlwaysStoppedAnimation<Color>(Colors.greenAccent),
backgroundColor: Color(0xfff0f0f0),//背景顏色
semanticsLabel: "這是semanticsLabel",
semanticsValue: "這是semanticsValue",
),
),
),