Reputation: 331
This is for a music player application that I'am working on. I am using audioplayers plugin to collect all local files. This is my code for displaying the Thumbnail
...Container(
margin: EdgeInsets.symmetric(horizontal: 40, vertical: 60),
decoration: BoxDecoration(
shape: BoxShape.circle,
color: dark,
image: DecorationImage(
image: loadThumbNail(File(path)),
fit: BoxFit.fitHeight,
),
),
),...
...ImageProvider loadThumbNail(File f) {
ImageProvider img;
try {
img = f.existsSync() ? FileImage(f) : AssetImage(path);
} catch (e) {
img = AssetImage(path);
}
return img;
}
The code works. It loads the default thumbnail if thumbnail doesn't exist. The problem seems to be for just one. How is this happening?
This is the error message
════════ Exception caught by image resource service ════════════════════════════════════════════════
The following _Exception was thrown resolving an image codec:
Exception: Could not instantiate image codec.
When the exception was thrown, this was the stack:
#0 _futurize (dart:ui/painting.dart:4419:5)
#1 instantiateImageCodec (dart:ui/painting.dart:1722:10)
#2 PaintingBinding.instantiateImageCodec (package:flutter/src/painting/binding.dart:88:12)
#3 FileImage._loadAsync (package:flutter/src/painting/image_provider.dart:864:24)
<asynchronous suspension>
...
Path: /storage/emulated/0/Android/data/com.android.providers.media/albumthumbs/1572310783227
════════════════════════════════════════════════════════════════════════════════════════════════════
The funny thing is that the app does not crash and no red screen appears. The thumbnail area just becomes blank. Should I just leave it like this or dig into this more?
Thats it I give up. I tried to use onError property, it did work, however the default image remained even for songs with a valid thumbnail.
Upvotes: 0
Views: 955
Reputation: 900
The problem is the path you are providing is not an image path that why this error happens and if you are using a release app then no red screen will be shown Flutters apps doesn't crash if the assets are missing. You can provide more code if you want it to fix or you can leave as it is.
Upvotes: 1