I'm quite newbie in Flutter, I have wrote a simple app which opens the gallery, so the user will pick an image, but both on emulator and physical device i get the same error:
════════ Exception caught by image resource service ════════
following assertion was thrown resolving an image codec: Unable to load asset: /data/user/0/com.example.upload_image_example/cache /image_picker915145764706640017.jpg
Image provider: AssetImage(bundle: null, name: "/data/user/0/com.example.upload_image_example/cache/image_picker915145764706640017.jpg") Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#c486d(), name: "/data/user/0/com.example.upload_image_example/cache/image_picker915145764706640017.jpg", scale: 1.0)
I have checked the path, the photo indeed exists in this path.
I have updated the pubspec.yaml for using other images in my assets directory. but the problem arrives when i pick a photo with the image picker:
var photo = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
imageFile = photo;
});
Widget _ImageView() {
if (imageFile == null) {
return CircleAvatar(
radius: 80.0,
backgroundImage: AssetImage('assets/images/avatar_blank.jpeg'),
);
} else {
return CircleAvatar(
radius: 80.0,
backgroundImage: AssetImage(imageFile.path), // <---- HERE I receive the ERROR!!
);
}
}
What am I doing wrong?
Does anybody have some suggestion?