flutter 获取定位_定位到目标 widget

本文介绍了在Flutter测试环境中如何使用flutter_test包的find工具定位Widgets。包括通过find.text()找含特定文本的Widget,使用byKey()找指定Key的Widget,以及直接通过byWidget()找特定Widget实例。
摘要由CSDN通过智能技术生成

在测试环境下,为了定位 widgets,我们需要用到 Finder 类。我们可以编写自己的 finder 类,不过通常使用 flutter_test package 提供的工具来定位 widgets 更加方便。

To locate widgets in a test environment, use the Finder

classes. While it’s possible to write your own Finder classes,

it’s generally more convenient to locate widgets using the tools

provided by the flutter_test package.

运行 widget 测试,在执行 flutter run 的时候,你还可以与屏幕进行交互点击,

Flutter 工具会输出建议的 [Finder][]。

During a flutter run session on a widget test, you can also

interactively tap parts of the screen for the Flutter tool to

print the suggested [Finder].

下面,我们来看看 flutter_test package 提供的 find

常量并演示如何使用其所提供的 Finders。如需查看完整的 finders 的列表,请参阅 CommonFinders 文档。

This recipe looks at the find constant provided by

the flutter_test package, and demonstrates how

to work with some of the Finders it provides.

For a full list of available finders,

see the CommonFinders documentation.

如果你还不熟悉 Widget 测试和 Finder 类使用方法,请参阅 在 Flutter 里做集成测试。

If you’re unfamiliar with widget testing and the role of

Finder classes,

review the Introduction to widget testing reci

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值