在 Flutter 中为元素添加 id
Add id to element in Flutter
测试人员需要在 flutter Elements 上有一个 id。我正在查看文档,这是我发现的
https://api.dart.dev/stable/2.10.2/dart-html/Element/id.html
但我不知道该怎么做。例如我试试
Padding(
id: "some id",
// ...
)
当然这不起作用。有没有办法为测试自动化添加一个 id?
谢谢
您需要使用相关小部件的关键属性。你可以看看this example.
child: Text(
'Go to next route',
key: Key('next_route_key'),
),
或者对于 FloatingActionButton:
floatingActionButton: FloatingActionButton(
// Provide a Key to this button. This allows finding this
// specific button inside the test suite, and tapping it.
key: Key('increment'),
onPressed: () => plusClickSink.add(null),
tooltip: 'Increment',
child: Icon(Icons.add),
),
您需要将键添加到您的小部件中,例如,如果我想测试何时使用 API 并将卡片渲染到 ListView 构建器中,我可以找到带有键的卡片
这 link 就是您所需要的:https://flutter.dev/docs/cookbook/testing/widget/finders
PD:你找错文档了,搜索Flutter的文档,没有Dart
测试人员需要在 flutter Elements 上有一个 id。我正在查看文档,这是我发现的
https://api.dart.dev/stable/2.10.2/dart-html/Element/id.html
但我不知道该怎么做。例如我试试
Padding(
id: "some id",
// ...
)
当然这不起作用。有没有办法为测试自动化添加一个 id?
谢谢
您需要使用相关小部件的关键属性。你可以看看this example.
child: Text(
'Go to next route',
key: Key('next_route_key'),
),
或者对于 FloatingActionButton:
floatingActionButton: FloatingActionButton(
// Provide a Key to this button. This allows finding this
// specific button inside the test suite, and tapping it.
key: Key('increment'),
onPressed: () => plusClickSink.add(null),
tooltip: 'Increment',
child: Icon(Icons.add),
),
您需要将键添加到您的小部件中,例如,如果我想测试何时使用 API 并将卡片渲染到 ListView 构建器中,我可以找到带有键的卡片
这 link 就是您所需要的:https://flutter.dev/docs/cookbook/testing/widget/finders
PD:你找错文档了,搜索Flutter的文档,没有Dart