feat: add loading widget support for image and avatar components - #2342
Merged
usmanvrtx merged 3 commits intoAug 13, 2026
Merged
Conversation
TheNoumanDev
requested changes
Aug 13, 2026
TheNoumanDev
left a comment
Member
There was a problem hiding this comment.
Following is Claude Review, please go though each point and see if it make sense, fix it, and if doesn't reply on it, Thanks
🔧 What we're fixing (the two that actually bite)
- #1 — Permanent spinner on empty source (widget/image.dart:132)
- Empty/absent source now shows loadingWidget forever, because that branch is the terminal "no image" state, not a real loading state — no fetch is pending to replace it.
- Fix: keep the empty-source branch as a neutral blank placeholder; only show loadingWidget on the real network-loading path.
- #2 — Loading widget rebuilt every frame (widget/image.dart:293)
- The placeholder callback calls buildWidgetFromDefinition(...) on every rebuild → animated loaders reset, and any id in the loader gets re-registered in scope repeatedly.
- Avatar already does it right (builds once, reuses). Fix: build once and reuse here too.
📋 The remaining points (lower priority, worth cleaning up)
- #3 — Redirect blocking silently dropped (image.dart:288, avatar.dart:316) — if a caller supplies networkCacheManager and allowRedirect:false, the redirect guard is bypassed. Only reachable programmatically today, but it voids a security setting.
- #4 — networkCacheManager YAML setter is a no-op (image.dart:73, avatar.dart:82) — BaseCacheManager can't be built from YAML, so any YAML value becomes null silently. Document as native-only or remove.
- #5 — Avatar lost {super.key} (avatar.dart:27) — now the only EnsembleWidget subclass that can't take a key. No caller passes one today, so latent — looks like accidental collateral; revert.
- #6 — BackgroundImage params are dead plumbing (model.dart:62) — loadingWidget/cacheManager were added to the model but getBackgroundImage never passes them, so they're always null. Wire up or drop.
usmanvrtx
force-pushed
the
feat/loading-widget-image-avatar
branch
from
August 13, 2026 13:09
394f038 to
cbf9616
Compare
TheNoumanDev
approved these changes
Aug 13, 2026
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.
Description
This PR adds a
loadingWidgetproperty to theImageandAvatarcomponents so developers can display a custom widget while a network image is loading. Previously only a colored placeholder box could be shown during the loading state. It also introduces anetworkCacheManageroption that lets developers supply a custom cache manager for network image requests.Related Issue
N/A
Type of Change
What Has Changed
loadingWidgetandnetworkCacheManagerfields, getters, and setters to theEnsembleImageandAvatarcontrollersloadingWidgetis set, it is built through the scope manager and shown as the placeholder while a network image loads; otherwise the existing colored placeholder is used_buildLoadingPlaceholder/_buildLoadingWidgethelpers inwidget/image.dartBackgroundImagemodel withloadingWidgetandcacheManagersupportloadingWidgetthrough the shared frameworkImagewidget's placeholder buildernetworkCacheManagersupport so a customBaseCacheManagercan be passed for network image loadingHow to Test
loadingWidgetto anImageorAvatardefinition and load a slow network image — the custom widget should render while loadingplaceholderColorplaceholder still renders whenloadingWidgetis not setnetworkCacheManagerand confirm network images use itflutter test modules/ensemble/test/widget/image_widget_test.dartScreenshots / Videos
N/A
Checklist
flutter analyzeand addressed any new warningsflutter testand all tests pass