• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Flutter的Text控件显示纯英文时高度和汉字不一致的问题

武飞扬头像
gaoyp
帮助1

调整前:

学新通

调整后:

学新通

解决方案:

strutStyle: StrutStyle(

        forceStrutHeight: true,

        leading: 0.5,

),

解决原理:

中文和英文字体默认的leading不一样。

StrutStyle的leading属性是指字体的倍数,比如:0.5就是0.5*字体的高度,而且这个高度要分成两半,上下各分一半。

参考:

https://juejin.cn/post/7034416015442345991

学新通

全部代码:

Widget _buildChosenTags() {
  List<String> tags = ['全是汉字', 'all english', '汉字 english','全是汉字', 'all english', '汉字 english'];
  return Container(
    padding:EdgeInsets.all(8),
    child: Wrap(
      runSpacing: 15,
      spacing: 10,
      children: tags.map((String title) {
        return Container(
          padding: EdgeInsets.symmetric(vertical: 0, horizontal: 0),
          decoration: BoxDecoration(
            border: Border.all(color: Colors.blueAccent, width: 0.5),
            borderRadius: BorderRadius.all(Radius.circular(2)),
          ),
          child: Text(
            title,
            //解决全英文的标签和中文标签高度不一致的问题
            strutStyle: StrutStyle(
              //forceStrutHeight: true,
              //leading: 0.5,
            ),
            style: TextStyle(fontSize: 16, color: Colors.grey),
          ),
        );
      }).toList(),
    ),
  );
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbkfek
系列文章
更多 icon
同类精品
更多 icon
继续加载