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
86fd222f
Unverified
Commit
86fd222f
authored
Aug 26, 2021
by
嘟囔
Committed by
GitHub
Aug 26, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add Image support to finder (#88761)
parent
426121c4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
0 deletions
+44
-0
finders.dart
packages/flutter_test/lib/src/finders.dart
+33
-0
finders_test.dart
packages/flutter_test/test/finders_test.dart
+11
-0
No files found.
packages/flutter_test/lib/src/finders.dart
View file @
86fd222f
...
...
@@ -103,6 +103,19 @@ class CommonFinders {
);
}
/// Finds [Image] and [FadeInImage] widgets containing `image` equal to the
/// `image` argument.
///
/// ## Sample code
///
/// ```dart
/// expect(find.image(FileImage(File(filePath))), findsOneWidget);
/// ```
///
/// If the `skipOffstage` argument is true (the default), then this skips
/// nodes that are [Offstage] or that are from inactive [Route]s.
Finder
image
(
ImageProvider
image
,
{
bool
skipOffstage
=
true
})
=>
_WidgetImageFinder
(
image
,
skipOffstage:
skipOffstage
);
/// Finds widgets by searching for one with a particular [Key].
///
/// ## Sample code
...
...
@@ -690,6 +703,26 @@ class _WidgetTypeFinder extends MatchFinder {
}
}
class
_WidgetImageFinder
extends
MatchFinder
{
_WidgetImageFinder
(
this
.
image
,
{
bool
skipOffstage
=
true
})
:
super
(
skipOffstage:
skipOffstage
);
final
ImageProvider
image
;
@override
String
get
description
=>
'image "
$image
"'
;
@override
bool
matches
(
Element
candidate
)
{
final
Widget
widget
=
candidate
.
widget
;
if
(
widget
is
Image
)
{
return
widget
.
image
==
image
;
}
else
if
(
widget
is
FadeInImage
)
{
return
widget
.
image
==
image
;
}
return
false
;
}
}
class
_WidgetIconFinder
extends
MatchFinder
{
_WidgetIconFinder
(
this
.
icon
,
{
bool
skipOffstage
=
true
})
:
super
(
skipOffstage:
skipOffstage
);
...
...
packages/flutter_test/test/finders_test.dart
View file @
86fd222f
...
...
@@ -2,11 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import
'dart:io'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/rendering.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
void
main
(
)
{
group
(
'image'
,
()
{
testWidgets
(
'finds Image widgets'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_boilerplate
(
Image
(
image:
FileImage
(
File
(
'test'
),
scale:
1.0
))
));
expect
(
find
.
image
(
FileImage
(
File
(
'test'
),
scale:
1.0
)),
findsOneWidget
);
});
});
group
(
'text'
,
()
{
testWidgets
(
'finds Text widgets'
,
(
WidgetTester
tester
)
async
{
await
tester
.
pumpWidget
(
_boilerplate
(
...
...
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