-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flutter_markdown] fix invalid URI's causing unhandled image errors #8058
[flutter_markdown] fix invalid URI's causing unhandled image errors #8058
Conversation
} | ||
} | ||
}; | ||
|
||
/// A default error widget builder for handling image errors. | ||
// ignore: prefer_function_declarations_over_variables | ||
final ImageErrorWidgetBuilder kDefaultImageErrorWidgetBuilder = ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The long term fix would be to provide an image error builder, next to the MarkdownWidget.imageBuilder
, do I do that from the get-go? Or do we change the API for the imageBuilder
to accept an error and stack trace?
return Image.file(File.fromUri(fileUri), width: width, height: height); | ||
try { | ||
return Image.file( | ||
File.fromUri(fileUri), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately File.fromUri
throws, so the errorBuilder
is not invoked in that case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be fixed by setting the value to a variable then returning it. I'm not 100% certain on that though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if that would work? Per the docs in https://api.dart.dev/dart-io/File/File.fromUri.html
If uri cannot reference a file this throws [UnsupportedError](https://api.dart.dev/dart-core/UnsupportedError-class.html)
This aligns with the second error reported in flutter/flutter#158428
Unsupported operation: Cannot extract a file path from a ttps URI
So that's why I added a try/catch here, since the Image.file() constructor won't be able to invoke its errorBuilder
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PTAL @stuartmorgan
…lutter#8058) This PR adds an error builder for images, so that any errors from those are caught. *List which issues are fixed by this PR. You must list at least one issue.* Fixes flutter/flutter#158428
This PR adds an error builder for images, so that any errors from those are caught.
List which issues are fixed by this PR. You must list at least one issue.
Fixes flutter/flutter#158428
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or this PR is exempt from CHANGELOG changes.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.