I am new to flutter. I am using the following to pick the image from the gallery. At first time, I am getting the mentioned exception. After getting the exception, If I resize the image, I don't face any issue for loading the image. I am not sure what makes the issue.
GetImage
final pickedFile = await picker.getImage(source: ImageSource.gallery );
setState(() {
if(pickedFile != null){
_image=File(pickedFile.path);
print(_image.path);
}else{
print("no Image selected");
}
});
Show Image
class CameraChild extends StatelessWidget{
String imagePath = null;
CameraChild(File image){
if(image != null){
imagePath = image.path;
}
}
@override
Widget build(BuildContext context){
AssetImage assetImage;
if(imagePath == null){
assetImage=AssetImage('images/camera_child.png');
}else{
assetImage=AssetImage(imagePath);
}
Image image = new Image(image: assetImage, width: 90, height: 90,);
//return Container(child: image,);
return Container(
child: ClipRRect(
borderRadius: BorderRadius.circular(45),
child: image,
),
);
}
}
Exception:
════════ Exception caught by image resource service ════════════════════════════════════════════════ The following assertion was thrown resolving an image codec: Unable to load asset: /data/user/0/com.sixdrops.drmom/cache/image_picker1457837975547141122.jpg
When the exception was thrown, this was the stack: #0 PlatformAssetBundle.load (package:flutter/src/services/asset_bundle.dart:225:7)
#1 AssetBundleImageProvider._loadAsync (package:flutter/src/painting/image_provider.dart:668:31) #2 AssetBundleImageProvider.load (package:flutter/src/painting/image_provider.dart:651:14) #3 ImageProvider.resolveStreamForKey. (package:flutter/src/painting/image_provider.dart:504:13) ... Image provider: AssetImage(bundle: null, name: "/data/user/0/com.sixdrops.drmom/cache/image_picker1457837975547141122.jpg") Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#2ea2b(), name: "/data/user/0/com.sixdrops.drmom/cache/image_picker1457837975547141122.jpg", scale: 1.0) ════════════════════════════════════════════════════════════════════════════════════════════════════ W/System (24478): Ignoring header X-Firebase-Locale because its value was null. W/System (24478): Ignoring header X-Firebase-Locale because its value was null. W/System (24478): Ignoring header X-Firebase-Locale because its value was null.