feat: widget finders add widgetWithImage method (#89020)
This commit is contained in:
parent
a7bc0484bd
commit
7df68b906c
@ -183,6 +183,30 @@ class CommonFinders {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Looks for widgets that contain an [Image] descendant displaying [ImageProvider]
|
||||||
|
/// `image` in it.
|
||||||
|
///
|
||||||
|
/// ## Sample code
|
||||||
|
///
|
||||||
|
/// ```dart
|
||||||
|
/// // Suppose you have a button with image in it:
|
||||||
|
/// Button(
|
||||||
|
/// child: Image.file(filePath)
|
||||||
|
/// )
|
||||||
|
///
|
||||||
|
/// // You can find and tap on it like this:
|
||||||
|
/// tester.tap(find.widgetWithImage(Button, FileImage(filePath)));
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// If the `skipOffstage` argument is true (the default), then this skips
|
||||||
|
/// nodes that are [Offstage] or that are from inactive [Route]s.
|
||||||
|
Finder widgetWithImage(Type widgetType, ImageProvider image, { bool skipOffstage = true }) {
|
||||||
|
return find.ancestor(
|
||||||
|
of: find.image(image),
|
||||||
|
matching: find.byType(widgetType),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Finds widgets by searching for elements with a particular type.
|
/// Finds widgets by searching for elements with a particular type.
|
||||||
///
|
///
|
||||||
/// This does not do subclass tests, so for example
|
/// This does not do subclass tests, so for example
|
||||||
|
@ -16,6 +16,13 @@ void main() {
|
|||||||
));
|
));
|
||||||
expect(find.image(FileImage(File('test'), scale: 1.0)), findsOneWidget);
|
expect(find.image(FileImage(File('test'), scale: 1.0)), findsOneWidget);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
testWidgets('finds Button widgets with Image', (WidgetTester tester) async {
|
||||||
|
await tester.pumpWidget(_boilerplate(
|
||||||
|
ElevatedButton(onPressed: null, child: Image(image: FileImage(File('test'), scale: 1.0)),)
|
||||||
|
));
|
||||||
|
expect(find.widgetWithImage(ElevatedButton, FileImage(File('test'), scale: 1.0)), findsOneWidget);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
group('text', () {
|
group('text', () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user