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
363ea406
Unverified
Commit
363ea406
authored
Dec 14, 2021
by
Juanjo Tugores
Committed by
GitHub
Dec 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve the error message when calling `Image.file` on web (#94568)
parent
ed1d075a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
image.dart
packages/flutter/lib/src/widgets/image.dart
+8
-1
image_test.dart
packages/flutter/test/widgets/image_test.dart
+17
-0
No files found.
packages/flutter/lib/src/widgets/image.dart
View file @
363ea406
...
...
@@ -464,7 +464,14 @@ class Image extends StatefulWidget {
this
.
filterQuality
=
FilterQuality
.
low
,
int
?
cacheWidth
,
int
?
cacheHeight
,
})
:
image
=
ResizeImage
.
resizeIfNeeded
(
cacheWidth
,
cacheHeight
,
FileImage
(
file
,
scale:
scale
)),
})
:
// FileImage is not supported on Flutter Web therefore neither this method.
assert
(
!
kIsWeb
,
'Image.file is not supported on Flutter Web. '
'Consider using either Image.asset or Image.network instead.'
,
),
image
=
ResizeImage
.
resizeIfNeeded
(
cacheWidth
,
cacheHeight
,
FileImage
(
file
,
scale:
scale
)),
loadingBuilder
=
null
,
assert
(
alignment
!=
null
),
assert
(
repeat
!=
null
),
...
...
packages/flutter/test/widgets/image_test.dart
View file @
363ea406
...
...
@@ -7,6 +7,7 @@
@Tags
(<
String
>[
'reduced-test-set'
])
import
'dart:async'
;
import
'dart:io'
;
import
'dart:math'
as
math
;
import
'dart:typed_data'
;
import
'dart:ui'
as
ui
;
...
...
@@ -1956,6 +1957,22 @@ void main() {
matchesGoldenFile
(
'image_test.missing.2.png'
),
);
},
skip:
kIsWeb
);
// https://github.com/flutter/flutter/issues/74935 (broken assets not being reported on web)
testWidgets
(
'Image.file throws a non-implemented error on web'
,
(
WidgetTester
tester
)
async
{
const
String
expectedError
=
'Image.file is not supported on Flutter Web. '
'Consider using either Image.asset or Image.network instead.'
;
final
Uri
uri
=
Uri
.
parse
(
'/home/flutter/dash.png'
);
final
File
file
=
File
.
fromUri
(
uri
);
expect
(
()
=>
Image
.
file
(
file
),
kIsWeb
// Web does not support file access, expect AssertionError
?
throwsA
(
predicate
((
AssertionError
e
)
=>
e
.
message
==
expectedError
))
// AOT supports file access, expect constructor to succeed
:
isNot
(
throwsA
(
anything
)),
);
});
}
@immutable
...
...
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