创建一个将显示很长段落的小部件
Create a widget that will display a very long paragraph
我想创建一个很长的屏幕段落。
小部件必须是可滚动的,因为它的末尾有一个按钮。
class CloseForm extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
backgroundColor: Colors.black,
body: SingleChildScrollView(
child: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(height: 20.0),
Text("TEXT 1"),
Text("TEXT 2"),
Text("TEXT 3"),
Text("TEXT 4"),
SizedBox(height: 250.0),
Center(
child: ButtonTheme(
child: RaisedButton(
onPressed: () => print("Connect"),
elevation: 2.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Text(
"Accepter",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.w600),
),
color: Color(0xFF5ABA9F),
),
),
),
],
),
),
),
);
}
}
如果继续使用文本小部件插入每一行,这将非常累人我只想知道是否有可能一步插入整个段落,谢谢
对于文本小部件,您可以指定 maxLines
属性。
像这样:
Text(longParagraphTextContent,
maxLines: 10,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12,
color: Color(0xdddddd),
fontWeight: FontWeight.bold)),
],
您可以只使用一个文本小部件并使用“\n”换行,而不是使用太多文本小部件。
最好的方法是使用 maxlines 属性 正如 Didier 所说
我想创建一个很长的屏幕段落。 小部件必须是可滚动的,因为它的末尾有一个按钮。
class CloseForm extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
extendBody: true,
backgroundColor: Colors.black,
body: SingleChildScrollView(
child: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
children: [
SizedBox(height: 20.0),
Text("TEXT 1"),
Text("TEXT 2"),
Text("TEXT 3"),
Text("TEXT 4"),
SizedBox(height: 250.0),
Center(
child: ButtonTheme(
child: RaisedButton(
onPressed: () => print("Connect"),
elevation: 2.0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Text(
"Accepter",
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.w600),
),
color: Color(0xFF5ABA9F),
),
),
),
],
),
),
),
);
}
}
如果继续使用文本小部件插入每一行,这将非常累人我只想知道是否有可能一步插入整个段落,谢谢
对于文本小部件,您可以指定 maxLines
属性。
像这样:
Text(longParagraphTextContent,
maxLines: 10,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12,
color: Color(0xdddddd),
fontWeight: FontWeight.bold)),
],
您可以只使用一个文本小部件并使用“\n”换行,而不是使用太多文本小部件。
最好的方法是使用 maxlines 属性 正如 Didier 所说