Skip to content

Error loading images using CachedNetworkImage #39

Closed

Description

@ThinkDigitalSoftware

I/flutter (27693): The following NoSuchMethodError was thrown resolving an image codec:
I/flutter (27693): The method 'containsKey' was called on null.
I/flutter (27693): Receiver: null
I/flutter (27693): Tried calling:
I/flutter (27693): containsKey("https://www.theimageurl.com/theimage.jpg")
I/flutter (27693):
I/flutter (27693): When the exception was thrown, this was the stack:
I/flutter (27693): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5)
I/flutter (27693): #1 CacheManager.getFile (package:flutter_cache_manager/flutter_cache_manager.dart:190:21)
I/flutter (27693):
I/flutter (27693): #2 CachedNetworkImageProvider._loadAsync (package:cached_network_image/cached_network_image.dart:472:35)
I/flutter (27693):
I/flutter (27693): #3 CachedNetworkImageProvider.load (package:cached_network_image/cached_network_image.dart:462:16)
I/flutter (27693): #4 ImageProvider.resolve.. (package:flutter/src/painting/image_provider.dart:266:86)
I/flutter (27693): #5 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:143:20)
I/flutter (27693): #6 ImageProvider.resolve. (package:flutter/src/painting/image_provider.dart:266:63)
I/flutter (27693): #7 SynchronousFuture.then (package:flutter/src/foundation/synchronous_future.dart:38:29)
I/flutter (27693): #8 ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:264:30)
I/flutter (27693): #9 _ImageProviderResolver.resolve (package:cached_network_image/cached_network_image.dart:193:29)
I/flutter (27693): #10 _CachedNetworkImageState._resolveImage (package:cached_network_image/cached_network_image.dart:284:20)
I/flutter (27693): #11 _CachedNetworkImageState.didChangeDependencies (package:cached_network_image/cached_network_image.dart:261:5)
I/flutter (27693): #12 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3780:12)
I/flutter (27693): #13 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3630:5)
...

Many images load fine, but on occasion, some fail. The error is thrown from CacheManager on the third line of this function.

Future<File> getFile(String url, {Map<String, String> headers}) async {
    String log = "[Flutter Cache Manager] Loading $url";

    if (!_cacheData.containsKey(url)) {
      await synchronized(_lock, () {
        if (!_cacheData.containsKey(url)) {
          _cacheData[url] = new CacheObject(url);
        }
      });
    }
    ...

Activity

  1. ThinkDigitalSoftware commented on Aug 28, 2018

    @ThinkDigitalSoftware
    Author

    I've also noticed that the image attempting to be loaded is the same image that's already attempted, so it should come from the cache. I have , for example, 15 buildings I'm downloading images for, 4 of them have the same image as their profile photo. 3 will load the identical photo and cachemanager will have an issue with the fourth. _cacheData is also showing up null when the call is made

  2. renefloor commented on Aug 30, 2018

    @renefloor
    Contributor

    Fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions