flutter中给TextSpan设置垂直居中
可以使用Baseline Widget来确保TextSpan的垂直居中。
示例代码:
Baseline(
baselineType: TextBaseline.alphabetic,
baseline: 0,
child: Text.rich(
TextSpan(
children: [
TextSpan(
text: 'Hello ',
style: TextStyle(fontSize: 24, color: Colors.black),
),
TextSpan(
text: 'Flutter',
style: TextStyle(fontSize: 36, color: Colors.blue),
),
],
),
),
)
在Baseline Widget中,设置baselineType为TextBaseline.alphabetic,baseline为0,然后将TextSpan作为child传入,就可以保证TextSpan的垂直居中了。
原文地址: https://www.cveoy.top/t/topic/bWbu 著作权归作者所有。请勿转载和采集!