Baseflow / octo_image

A multifunctional Flutter image widget
https://baseflow.com/
MIT License
156 stars 23 forks source link

reportError throws assertion: setState() called after dispose() #1

Closed kw2019ltd closed 4 years ago

kw2019ltd commented 4 years ago

RESOLVED: Fixed in Flutter master branch on 18th of May 2020

getting below in logs with below example:

    return OctoImage(
      image: CachedNetworkImageProvider(url),
      placeholderBuilder: (context) =>
          context.watch<ThemeProvider>().isLightTheme
              ? CircularProgressIndicator(
                  backgroundColor: Theme.of(context).primaryColor,
                  valueColor: const AlwaysStoppedAnimation(Colors.white),
                )
              : CircularProgressIndicator(
                  backgroundColor: Theme.of(context).primaryColor,
                ),
      errorBuilder: (context, url, dynamic error) => _sizedContainer(
        Icon(
          Icons.error,
          color: Colors.red,
        ),
      ),
    );
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following assertion was thrown when reporting an error to an image listener:
setState() called after dispose(): _ImageState#8fa88(lifecycle state: defunct, not mounted, stream: ImageStream#ebcf8(MultiFrameImageStreamCompleter#209a4, [960×720] @ 1.0x, 1 listener), pixels: null, loadingProgress: null, frameNumber: null, wasSynchronouslyLoaded: false)

This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.

The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().

When the exception was thrown, this was the stack: 
#0      State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1197:9)
#1      State.setState (package:flutter/src/widgets/framework.dart:1232:6)
#2      _ImageState._getListener.<anonymous closure> (package:flutter/src/widgets/image.dart:1116:13)
#3      ImageStreamCompleter.reportError (package:flutter/src/painting/image_stream.dart:504:24)
#4      ImageStreamCompleter.setImage (package:flutter/src/painting/image_stream.dart:439:9)
...
════════════════════════════════════════════════════════════════════════════════════════════════════

════════ Exception caught by image resource service ════════════════════════════════════════════════
setState() called after dispose(): _ImageState#b0bda(lifecycle state: defunct, not mounted, stream: ImageStream#6f11d(MultiFrameImageStreamCompleter#366d4, [1632×1224] @ 1.0x, 1 listener), pixels: null, loadingProgress: null, frameNumber: null, wasSynchronouslyLoaded: false)
════════════════════════════════════════════════════════════════════════════════════════════════════
lunedam-git commented 4 years ago

Getting the same error as @kw2019ltd

Flutter Channel beta, v1.17.0, on Mac OS X 10.15.4 cached_network_image: ^2.0.0

renefloor commented 4 years ago

I'd guess it is related to this issue: https://github.com/flutter/flutter/issues/56454 Does it crash fill your console?

kw2019ltd commented 4 years ago

looks the same issue to me.

On Mon, May 11, 2020 at 9:42 AM Rene Floor notifications@github.com wrote:

I'd guess it is related to this issue: flutter/flutter#56454 https://github.com/flutter/flutter/issues/56454 Does it crash fill your console?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Baseflow/octo_image/issues/1#issuecomment-626503701, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALJEI6R7TVVEPNXTIBWK5MLRQ6M3TANCNFSM4M5E225Q .

lunedam-git commented 4 years ago

Certainly related to when items are scrolled beyond the viewport, yes. Using only CachedNetworkImage is fine but as soon as octo_image is added to the mix this problem kicks off.

kw2019ltd commented 4 years ago

Yes it was working fine before using the plugin now facing this error.

On Mon, May 11, 2020, 13:38 lunedam-git notifications@github.com wrote:

Certainly related to when items are scrolled beyond the viewport, yes. Using only CachedNetworkImage is fine but as soon as octo_image is added to the mix this problem kicks off.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Baseflow/octo_image/issues/1#issuecomment-626622669, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALJEI6QLT7DIIN5NAGRDMCDRQ7ITJANCNFSM4M5E225Q .

renefloor commented 4 years ago

Just made a PR on the Flutter repo, but that will at least take some time before it hits the stable branch: https://github.com/flutter/flutter/pull/57201

renefloor commented 4 years ago

PR on the Flutter repo was merged into master today, so this issue should be resolved now. Will take some time before it is available to you though (if you're not using the master channel).