gpt4 book ai didi

flutter - 有没有一种简单的方法可以在 Flutter 测试中找到从 RichText 构建的特定文本?

转载 作者:IT老高 更新时间:2023-10-28 12:44:21 24 4
gpt4 key购买 nike

例如,我可能在当前小部件树中有一个 RichText,看起来像

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

我尝试使用 find.text('Hello bold world!') 但它不起作用,因为它不是文本。

最佳答案

最简单的解决方案是在 RichText 上放一个键并以这种方式读取。

如果由于某种原因这不合适,您可以使用 find.byWidgetPredicate 并传递一个匹配 RichText 小部件的函数,该小部件的 text.toPlainText() 返回您想要的字符串。

关于flutter - 有没有一种简单的方法可以在 Flutter 测试中找到从 RichText 构建的特定文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41152320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com