There is a problem with errorWidget. It is not used when exception like Exception: Could not instantiate image codec.. Steps to reproduce: valid url with invalid content
this is a big problem for me, hope it fixed early~
I also have the problem,please fix quickly
I also have this problem
I/flutter (13051): The following _Exception was thrown resolving an image codec:
I/flutter (13051): Exception: Could not instantiate image codec.
I/flutter (13051):
I/flutter (13051): When the exception was thrown, this was the stack:
I/flutter (13051): #0 _futurize (dart:ui/painting.dart:4397:5)
I/flutter (13051): #1 instantiateImageCodec (dart:ui/painting.dart:1718:10)
I/flutter (13051): #2 PaintingBinding.instantiateImageCodec (package:flutter/src/painting/binding.dart:88:12)
I/flutter (13051): #3 FileImage._loadAsync (package:flutter/src/painting/image_provider.dart:653:24)
I/flutter (13051): <asynchronous suspension>
I/flutter (13051): #4 FileImage.load (package:flutter/src/painting/image_provider.dart:638:14)
I/flutter (13051): #5 ImageProvider.resolve.<anonymous closure>.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:327:17)
I/flutter (13051): #6 ImageCache.putIfAbsent (package:flutter/src/painting/image_cache.dart:197:22)
I/flutter (13051): #7 ImageProvider.resolve.<anonymous closure>.<anonymous closure> (package:flutter/src/painting/image_provider.dart:325:84)
I/flutter (13051): #8 SynchronousFuture.then (package:flutter/src/foundation/synchronous_future.dart:41:29)
I/flutter (13051): #9 ImageProvider.resolve.<anonymous closure> (package:flutter/src/painting/image_provider.dart:323:11)
I/flutter (13051): #13 ImageProvider.resolve (package:flutter/src/painting/image_provider.dart:315:16)
I/flutter (13051): #14 _ImageState._resolveImage (package:flutter/src/widgets/image.dart:1010:20)
I/flutter (13051): #15 _ImageState.didChangeDependencies (package:flutter/src/widgets/image.dart:967:5)
I/flutter (13051): #16 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4482:12)
I/flutter (13051): #17 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4307:5)
I/flutter (13051): #18 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3297:14)
I/flutter (13051): #19 Element.updateChild (package:flutter/src/widgets/framework.dart:3091:12)
I/flutter (13051): #20 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:5575:14)
I/flutter (13051): #21 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3297:14)
I/flutter (13051): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:3091:12)
I/flutter (13051): #23 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:5326:32)
I/flutter (13051): #24 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:5694:17)
I/flutter (13051): #25 Element.updateChild (package:flutter/src/widgets/framework.dart:3080:15)
I/flutter (13051): #26 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4349:16)
I/flutter (13051): #27 Element.rebuild (package:flutter/src/widgets/framework.dart:4053:5)
I/flutter (13051): #28 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2532:33)
I/flutter (13051): #29 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:796:20)
I/flutter (13051): #30 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
I/flutter (13051): #31 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1109:15)
I/flutter (13051): #32 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1048:9)
I/flutter (13051): #33 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:964:5)
I/flutter (13051): #37 _invoke (dart:ui/hooks.dart:260:10)
I/flutter (13051): #38 _drawFrame (dart:ui/hooks.dart:218:3)
I/flutter (13051): (elided 6 frames from package dart:async)
I use CustomCacheManager.
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:http/http.dart' as http;
import 'package:path/path.dart' as p;
import 'package:path_provider/path_provider.dart';
class CustomCacheManager extends BaseCacheManager {
static const key = "libCachedImageData";
static CustomCacheManager _instance;
factory CustomCacheManager() {
if (_instance == null) _instance = CustomCacheManager._();
return _instance;
}
CustomCacheManager._() : super(key, fileFetcher: _customHttpGetter);
Future<String> getFilePath() async {
var directory = await getTemporaryDirectory();
return p.join(directory.path, key);
}
static Future<FileFetcherResponse> _customHttpGetter(String url,
{Map<String, String> headers}) async {
final response = await http.get(url, headers: headers);
if (response.headers['content-type']?.startsWith('image/') == false) {
throw Exception('Invalid content type');
}
return HttpFileFetcherResponse(response);
}
}
Interesting idea to give the cachemanager a parameter of supported content types.
Any fix would help. Please...
It should be fixed in 2.3.0-beta, would be nice if any of you can validate.
I can confirm it works in 2.3.0-beta
When will 2.3.0 be released?
It is depending on a fix in Flutter 1.19, so I'm waiting for the next stable release of the Flutter SDK. That is the only reason it is still a RC version.
Interesting idea to give the cachemanager a parameter of supported content types.
Agreed.
Seems I'm having similar issue with some of our url's such as:
http://airit.org.au/airit/images/P/std_5813.jpg
Which return 200 but HTML rather than image content-type.
2.3.0-beta does appear to display errorWidget however.
Hi guys,
I'm having a problem related to this issue.
Exception:
Non-fatal Exception: java.lang.Exception: Bad state: LocalFile: '/data/user/0/com.example.app/cache/libCachedImageData/8ba13070-e817-11ea-91d6-3529a262a8eb.png' is empty and cannot be loaded as an image.
at FileImage._loadAsync(FileImage.java:883)
It's happening when the application tries to load several images. I have a list view, and this happens when I made a scroll.
I've read this is going to be fixed in the 2.3.0 version.
but, I'm using the pre-release version published on https://pub.dev, and It happens the same.
cached_network_image: ^2.3.0-rc
[✓] Flutter (Channel stable, 1.20.2, on Mac OS X 10.15.5 19F101)
• Flutter version 1.20.2 at /Users/lgonzalez/development/flutter-1.20.2
• Framework revision bbfbf1770c (2 weeks ago), 2020-08-13 08:33:09 -0700
• Engine revision 9d5b21729f
• Dart version 2.9.1
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/lgonzalez/Library/Android/sdk
• Platform android-29, build-tools 29.0.2
• ANDROID_HOME = /Users/lgonzalez/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 11.3.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 11.3.1, Build version 11C504
• CocoaPods version 1.9.1
[✓] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 48.1.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] VS Code (version 1.48.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.13.2
[!] Connected device
! No devices available
! Doctor found issues in 1 category.
Regards!
Also facing the same issue when using CachedImageProvider in a list view. I'm trying the new version. Will get back if the issue persists for me
any update, anyone solved this issue or found solution?
Most helpful comment
this is a big problem for me, hope it fixed early~