Repository navigation
Conversation
Use ui.decodeImageFromPixelsSync (Flutter 3.41+) so BlurHash and BlurHashImage can show the blurhash in the very first frame instead of flashing the placeholder color. The API throws on the web and when Impeller is disabled, so failures are caught, remembered, and decoding falls back to the existing asynchronous path. - Add blurHashDecodeImageSync, which returns null when unsupported - blurHashDecodeImage uses the sync API internally when possible - Raise the minimum Flutter version to 3.41 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Flutter 3.41 added
ui.decodeImageFromPixelsSync. It returns aui.Imageright away instead of through a callback. This PR uses it so the blurhash can show up in the first frame. Today,BlurHashshowscolorfor at least one frame whiledecodeImageFromPixelsfinishes, and that flash is visible in lists and on page transitions.The sync API only works with Impeller:
UnimplementedErrorStringfrom the engineThe package catches either error and falls back to the existing async path (
decodeImageFromPixels, or the BMP codec on the web). After the first failure it stops trying the sync API, so it doesn't throw on every decode.Changes
blurHashDecodeImageSync: returns aui.Image?, ornullwhen sync decoding isn't supported. It still throws on an invalid hash, like the other decode functions.BlurHashwidget: tries the sync decode first and renders it directly. If that fails, it uses the existingFutureBuilderpath.onDecodedstill fires asynchronously, as before.BlurHashImage: returns aSynchronousFuturewhen sync decoding works, so the image is available immediately.blurHashDecodeImage: uses the sync API internally when possible. Its signature and behavior are unchanged.blurHashDecodeandoptimizedBlurHashDecodenow wrap private sync functions. Both were already synchronous insideFuture.value, and their public API is unchanged.Dart can't check whether a top-level function exists at compile time, so this PR raises the constraint to
flutter: ">=3.41.0"/sdk: ">=3.11.0 <4.0.0". This probably deserves a minor version bump (e.g. 0.10.0). I leftversion:unchanged and put the changes under an "Unreleased" heading in the CHANGELOG.Testing
flutter analyze: no issuesflutter test(Skia): all tests pass,blurHashDecodeImageSyncreturnsnull, and decoding falls back to asyncflutter test --enable-impeller: all tests pass, the sync decode returns an image, andBlurHashrenders anImagein the first frameUnrelated issue
BlurHashState._decodeImagecalls_image.whenComplete(...), and that returns a new future nobody listens to. With an invalid hash, this produces an unhandled async error. The behavior already exists and this PR doesn't change it. I can fix it in a separate PR.🤖 Generated with Claude Code