[英]Flutter - How to show text and icon in one line in row?
我正在使用带有三个子小部件的行小部件:文本图标文本
我希望它们全部水平显示在同一水平的单行中,如果文本增加则下降到新行。
我正在为 Row 小部件使用以下代码,但最后一个 Text 小部件未正确对齐
文本放置应从“ Tap
”下方开始,并且“ on the right hand
”未对齐
Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Tap ',
style: TextStyle(
fontSize: 17,
),
),
Icon(Icons.add),
Expanded(
child: Text(
'on the right hand corner to start a new chat.',
style: TextStyle(
fontSize: 17,
),
),
)
],
)
使用Text.rich
和WidgetSpan
将图标放在文本中(内联)
Text.rich(
TextSpan(
style: TextStyle(
fontSize: 17,
),
children: [
TextSpan(
text: 'Tap',
),
WidgetSpan(
child: Icon(Icons.add),
),
TextSpan(
text: 'on the right hand corner to start a new chat.',
)
],
),
)
Flutter 有 WidgetSpan() 来在 RichText() 中添加一个小部件。
RichText(
text: TextSpan(
children: [
TextSpan(
text: "Click ",
),
WidgetSpan(
child: Icon(Icons.add, size: 14),
),
TextSpan(
text: " to add",
),
],
),
)
上面的代码将产生:
点击 > 添加
您可以像对待普通小部件一样对待 WidgetSpan 的子项。
你需要把 sinlein 线crossAxisAlignment: CrossAxisAlignment.start放在 Row 里面
Row (
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(Icons.add, size: 14),
Expanded(
child: Text("your multiline text "),
),
),
],
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.