概述
I am using row widget with three child widgets:
Text
Icon
Text
I want all of them to appear in single line same level horizontally and drop to new line if text increases.
I am using below code for Row widget but last Text widget is not aligned correctly
The text dropping should start below the "Tap" and "on the right hand" is not aligned
Row(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
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,
),
),
)
],
)
解决方案
Use Text.rich with WidgetSpan to put icon inside text (inline)
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显示图标_Flutter-如何在一行中显示文本和图标?的全部内容,希望文章能够帮你解决flutter显示图标_Flutter-如何在一行中显示文本和图标?所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复