在下划线上方显示带有填充的文本

问题描述

有没有办法在 Flutter 中实现以下结果,其中文本下方的下划线将被溢出它的字母周围的填充很好地隐藏,例如“g”、“q”、“y”等?

>

模拟器(当前):

Emulator view

设计(期望):

Designed and desired view

字体:斯巴达

解决方法

我发现实现这一目标的最佳方法是使用文本笔触和堆栈来创建下划线效果。代码如下:

print("\n".join(map(str,my_list)))

以及结果截图

Results

,

编辑

第一个看起来工作但不好看,第二个工作正常但p字不太好。 当您不想添加下划线时,只需编写decoration:TextDecoration.none。

    Text.rich(
      TextSpan(
        text: 'For ',style: TextStyle(decoration: TextDecoration.underline,fontSize: 25),children: <TextSpan>[
          TextSpan(text: 'g',style:TextStyle(decoration: TextDecoration.none)),TextSpan( text: ' ',style:TextStyle(decoration: TextDecoration.underline,decorationThickness: 1)),TextSpan( text: ' p',style:TextStyle(decoration: TextDecoration.none,)),TextSpan( text: 'assword?',style:TextStyle(decoration: TextDecoration.underline)),//you can add more text span here
        ],),Row(
      children: <Widget>[
        Text('For',fontSize: 25)),Text('g',style: TextStyle(decoration: TextDecoration.none,Text('ot',Text(' ',Text('p',Text('assword',],)

Working example image

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...