Skip to content

fix: clear a running resize when its listener cancels - #553

Open
nilsreichardt wants to merge 1 commit into
Baseflow:mainfrom
nilsreichardt:fix/remove-resize-on-cancel
Open

nilsreichardt wants to merge 1 commit into
Baseflow:mainfrom
nilsreichardt:fix/remove-resize-on-cancel

Conversation

@nilsreichardt

Copy link
Copy Markdown

✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Bug fix.

⤵️ What is the current behavior?

getImageFile with maxWidth or maxHeight shares one stream per resized key through _runningResizes and removes it after yield*. When a listener cancels, for example at a download error, the generator stops at the yield* and never reaches that line. The finished stream stays in the map, so the next call for the same url and size ends without a file or an error.

With CachedNetworkImage the image then stays on its placeholder until the app restarts. Flutter's ImageCache keeps the completer that never completes and hands it to every later widget for that image.

🆕 What is the new behavior (if this is a feature change)?

The stream is removed in a finally, so a cancelled listener cleans it up too. The next call downloads the image again.

💥 Does this PR introduce a breaking change?

No

🐛 Recommendations for testing

The new test fails on main with Bad state: No element and passes with the fix. flutter analyze and the full flutter test suite pass.

📝 Links to relevant issues/docs

Fixes #439. Also reported as Baseflow/flutter_cached_network_image#901 and Baseflow/flutter_cached_network_image#980.

#548 also moves this cleanup into a finally as part of per-caller cancellation. This PR is the minimal fix for the current code.

🤔 Checklist before submitting

  • All projects build
  • Follows style guide lines (code style guide)
  • Relevant documentation was updated
  • Rebased onto current main
  • Version bumped and dated CHANGELOG entry added

🤖 Generated with Claude Code

getImageFile removed the shared resize stream only after yield* had
completed. A listener that cancelled, for example on a download error,
skipped that line, so the next call for the same url and size got the
finished stream and ended without a file or an error.

Fixes Baseflow#439

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If image (DOES NOT EXIST) AND (maxWidth/maxHeight) ARE set, the stream never closes

1 participant