我如何测试它应该找到特定的图标,例如Icons.visibility? 这是我的测试:
testWidgets(
'Should find visibility_off icon',
(WidgetTester tester) async {
await _buildApp(tester);
await tester.pumpAndSettle();
expect(find.byWidget(Icon(Icons.visibility)), findsOneWidget);
});
答案 0 :(得分:2)
byIcon
对象上有一个Finder
方法。
https://api.flutter.dev/flutter/flutter_test/CommonFinders/byIcon.html
testWidgets('Should find visibility_off icon', (WidgetTester tester) async {
await _buildApp(tester);
await tester.pumpAndSettle();
expect(find.byIcon(Icons.visibility), findsOneWidget);
});