Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
7df68b90
Unverified
Commit
7df68b90
authored
Aug 27, 2021
by
嘟囔
Committed by
GitHub
Aug 27, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: widget finders add widgetWithImage method (#89020)
parent
a7bc0484
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
finders.dart
packages/flutter_test/lib/src/finders.dart
+24
-0
finders_test.dart
packages/flutter_test/test/finders_test.dart
+7
-0
No files found.
packages/flutter_test/lib/src/finders.dart
View file @
7df68b90
...
...
@@ -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.
///
/// This does not do subclass tests, so for example
...
...
packages/flutter_test/test/finders_test.dart
View file @
7df68b90
...
...
@@ -16,6 +16,13 @@ void main() {
));
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'
,
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment