Flutter 设置Text文本的行高和间距

8 min read
class TextHeightTest extends StatefulWidget {
  @override
  _TextHeightTestState createState() => _TextHeightTestState();
}
 
class _TextHeightTestState extends State<TextHeightTest> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('字体行高间距'),
      ),
      body: Center(
        child: Text(
          '过去两天,南方阴雨显著增加,并伴随有强对流天气。昨天在春雷声声中,进入了惊蛰节气,监测显示,江淮西部、江南大部、华南北部等地出现中雨或大雨。',
          style: TextStyle(
            fontSize: 18.0,
            color: Colors.black54,
            height: 1.0, //1倍行高
          ),
        ),
      ),
    );
  }
}

如果还需要设置字与字之间的间距,就在style中再加入一个wordSpacing。