如何使图标相对于RichText中的文本对齐?

发布于 2025-02-11 22:26:59 字数 859 浏览 1 评论 0原文

我有一个文本位于Richtext,n,我想在几点之后进行单击,文字旁边有一个图标。问题在于,图标与文本相对于文本无法正确对齐,当它的大小增加时,这一点尤其明显。如何使图标和文本在中心的同一行上?对齐中心无助

 RichText(
  textAlign: TextAlign.center,
  text: TextSpan(
    children: [
      TextSpan(text: 'Next ', style: richBotton),
      WidgetSpan(
          child: Icon(Icons.arrow_forward_ios, color: Colors.grey, size: 11,)
      ),
    ],
  ),
),

于样式

final richBotton = const  TextStyle(color: Color.fromARGB(255, 117, 117, 117), fontSize: 11,);  
final text = const TextStyle(color: Colors.grey, fontSize: 11); 

屏幕

  1. 我的代码
  2. callignment:packholdSeralignment.middle middle
  3. 使用对齐:占位型
  4. 对齐:loctholderalignment.bottom

I have a text located in RichText, n how much later I want to make it clickable, there is an icon next to the text. The problem is that the icon does not align correctly relative to the text, this is especially noticeable when its size increases. How do I make the icon and text to be on the same line in the center ? Align centered doesn't help

 RichText(
  textAlign: TextAlign.center,
  text: TextSpan(
    children: [
      TextSpan(text: 'Next ', style: richBotton),
      WidgetSpan(
          child: Icon(Icons.arrow_forward_ios, color: Colors.grey, size: 11,)
      ),
    ],
  ),
),

for styles

final richBotton = const  TextStyle(color: Color.fromARGB(255, 117, 117, 117), fontSize: 11,);  
final text = const TextStyle(color: Colors.grey, fontSize: 11); 

Screen

  1. My code
  2. With alignment: PlaceholderAlignment.Middle
  3. With alignment: PlaceholderAlignment.Top
  4. With alignment: PlaceholderAlignment.Bottom

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2025-02-18 22:26:59

您可以在widgetspan上包含对齐:loctholdSeralign.middle

RichText(
  textAlign: TextAlign.center,
  text: TextSpan(
    children: [
      TextSpan(
        text: 'Next ',
      ),
      WidgetSpan(
        alignment: PlaceholderAlignment.middle,
          child: Icon(
        Icons.arrow_forward_ios,
        color: Colors.grey,
        size: 11,
      )),
    ],
  ),
),

You can include alignment: PlaceholderAlignment.middle on WidgetSpan.

RichText(
  textAlign: TextAlign.center,
  text: TextSpan(
    children: [
      TextSpan(
        text: 'Next ',
      ),
      WidgetSpan(
        alignment: PlaceholderAlignment.middle,
          child: Icon(
        Icons.arrow_forward_ios,
        color: Colors.grey,
        size: 11,
      )),
    ],
  ),
),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文