Skip to content

fix: prevent image decode future from completing twice - #520

Open
dao-wkm wants to merge 1 commit into
Baseflow:developfrom
dao-wkm:fix/decode-image-completer
Open

fix: prevent image decode future from completing twice#520
dao-wkm wants to merge 1 commit into
Baseflow:developfrom
dao-wkm:fix/decode-image-completer

Conversation

@dao-wkm

@dao-wkm dao-wkm commented Aug 27, 2026

Copy link
Copy Markdown

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

Bug fix.

⤵️ What is the current behavior?

When ImageCacheManager resizes a multi-frame image, such as an animated PNG,
_decodeImage keeps its ImageStreamListener registered after receiving the
first frame.

Subsequent frames call Completer.complete(...) again, causing:

StateError: Bad state: Future already completed

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

_decodeImage now removes its listener after the first frame and guards
success/error completion with Completer.isCompleted.
Animated PNGs can be resized without throwing Future already completed.

💥 Does this PR introduce a breaking change?

No.

🐛 Recommendations for testing

  1. Use a CacheManager with ImageCacheManager.
  2. Request a resized animated PNG by passing maxWidth and/or maxHeight.
  3. Confirm that subsequent animation frames do not throw an exception.
    Example APNG:
    https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png
    A local APNG fixture is recommended for an automated regression test.
CachedNetworkImage(
      imageUrl: 'https://upload.wikimedia.org/wikipedia/commons/1/14/Animated_PNG_example_bouncing_beach_ball.png',
      width: 100,
      height: 100,
      maxWidthDiskCache: 256,
      maxHeightDiskCache: 256,
)

📝 Links to relevant issues/docs

Fixes #400

🤔 Checklist before submitting

  • All projects build
  • Follows style guide lines (code style guide)
  • Relevant documentation was updated
  • Rebased onto current develop

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.

Bad state: Future already completed

1 participant