所以我有一個來自谷歌翻譯的翻譯小部件,它一切正常。當輸入文本被翻譯時,結果是文本的形式(不是文本欄位)。如果我寫了一個很長的段落進行翻譯,我可以keyboardType: TextInputType.multiline, maxLines: null,為文本欄位實作“ ”,但我不知道如何對文本執行相同的操作。文本小部件也有一些東西嗎?
目前,翻譯器小部件如下所示:

我希望灰色區域有多行,我可以在其中滾動。
代碼:
Widget build(BuildContext context) {
return Container(
height: 350.0,
color: Colors.white,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Container(
margin: EdgeInsets.only(left: 16.0),
child: TextField(
keyboardType: TextInputType.multiline,
maxLines: null,
focusNode: this.widget.focusNode,
controller: this._textEditingController,
onChanged: this._onTextChanged,
decoration: InputDecoration(
contentPadding: const EdgeInsets.symmetric(vertical: 10),
border: InputBorder.none,
suffixIcon: RawMaterialButton(
onPressed: () {
if (this._textEditingController.text != "") {
this.setState(() {
this._textEditingController.clear();
this._textTranslated = "";
});
} else {
this.widget.onCloseClicked(false);
}
},
child: new Icon(
Icons.close,
color: Colors.grey,
),
shape: new CircleBorder(),
),
),
),
),
),
Divider(),
Flexible(
child: Container(
color: Colors.grey,
margin: EdgeInsets.only(left: 16.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
this._textTranslated,
softWrap: true,
style: TextStyle(color: Colors.blue[700], fontSize: 20),
),
),
),
),
],
),
);
}
uj5u.com熱心網友回復:
你可以將你的包裹Text在一個SingleChildScrollView:
Flexible(
child: SingleChildScrollView(
child: Container(
color: Colors.grey,
margin: EdgeInsets.only(left: 16.0),
child: Align(
alignment: Alignment.centerLeft,
child: Text(
this._textTranslated,
softWrap: true,
style: TextStyle(color: Colors.blue[700], fontSize: 20),
),
),
),
),
),
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/354855.html
上一篇:如何在容器下方連續書寫文本
