Flutter RichText没有显示 [英] Flutter RichText is not showing

查看:74
本文介绍了Flutter RichText没有显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在每个 https://api.flutter.dev/flutter/widgets/RichText-class.html 在脚手架中.我看不到我什么也看不到.调试工具显示,丰富文本确实存在于小部件层次结构中(尽管我看不到其中的TextSpans,大概是它们在其中).

I have a regular normal rich text widget in a Centered per https://api.flutter.dev/flutter/widgets/RichText-class.html within a Scaffold. I can't see it. I can't see anything. The debug tools show that the Rich Text is indeed there in the widget heirarchy (though I can't see the TextSpans within it, presumably they're in there.)

Scaffold(body: Center(child:
  RichText(
    text: TextSpan(
      text: 'Hello ',
      style: DefaultTextStyle.of(context).style,
      children: <TextSpan>[
        TextSpan(text: 'bold', style: TextStyle(fontWeight: FontWeight.bold)),
        TextSpan(text: ' world!'),
      ],
    ),
  ),
));

推荐答案

我尝试了一个Android构建,以查看这是否是特定于linux桌面构建的错误.不是!它也在这里发生.但是,手机的对比度非常高,以至于我几乎看不到其中的文字,即白色对白色".事实证明,与文本"小部件不同, RichText文本的默认颜色是白色,与主题背景相同,因此该文本将不可见.

I tried an android build to see whether this was a bug specific to linux desktop builds. It wasn't! It's happening here too. However, the contrast ratio of my phone is high enough that I can just barely see the text in there, White on Off White. It turns out that, unlike the Text widget, the default color for RichText text is white, same as the theme's background, so the text wont be visible.

(应用程序是否有可能响应系统范围内的黑暗模式主题?不是.切换主题不会有任何影响.)

(Is it possible the app is responding to the system-wide dark mode theme? Nope. Switching theme doesn't affect anything.)

那么,为什么这是默认颜色?因为 DefaultTextStyle 不好,我猜错了吗?使用 Theme.of(context).textTheme.bodyText1 ,您将获得期望的结果.

So, WHY is this the default color? Because DefaultTextStyle is bad and wrong I guess? Use Theme.of(context).textTheme.bodyText1 and you will get the results you expect.

这篇关于Flutter RichText没有显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆