我正在尝试创建一个简单的手势检测器,在开始时带有一些文本和一个图标,但是在尝试将图标居中时我似乎撞到了墙(是的,已经尝试了一行,但我需要一些宽度可以做到的东西不要超出内容),这是我目前所拥有的:
Container(
color: Colors.white,
child: GestureDetector(
onTap: () => setState(() {
playerNames.remove(name);
}),
child: RichText(
text: TextSpan(children: [
WidgetSpan(
child: Icon(
Icons.clear,
size: MediaQuery.of(context).size.height * 0.02,
),
),
WidgetSpan(
child: AutoSizeText(
name,
maxLines: 1,
style: new TextStyle(
fontSize:
MediaQuery.of(context).size.height * 0.021,
color: Color.fromRGBO(0, 0, 0, 0.71)),
),
)
]),
)),
)
最佳答案
试试 InlineSpan 在 TextSpan 里面
TextSpan(
style: TextStyle(fontSize: 24, color: Colors.black),
children: <InlineSpan>[
TextSpan(text: 'hello'),
WidgetSpan(
alignment: ui.PlaceholderAlignment.middle,
child: Text( 'Jack',
style: TextStyle(fontSize: 40, color: Colors.white),
),
),
TextSpan(text: ' doctor'),
]
),
关于flutter - 在富文本抖动中使用图标时,如何垂直对齐图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61489662/