I am using the image_picker package to process the image and then show it when it has been chosen but sometimes it works correctly and at other times the application crashes and when I look at the debug window in the Call stack part I get this error: FlutterError (Unable to load asset: /storage/emulated/0/Android/data/com.example.produmax/files/Pictures/scaled_product.jpg
FlutterError (Unable to load asset: /storage/emulated/0/Android/data/com.example.produmax/files/Pictures/scaled_product.jpg)
This is the code I use to process the image
_seleccionarFoto () async {
await _procesarImagen(ImageSource.gallery);
}
_tomarFoto () async {
await _procesarImagen(ImageSource.camera);
}
_procesarImagen(ImageSource tipo) async {
foto = await ImagePicker.pickImage(
source: tipo
);
if (foto != null) {
_producto.imagePath = null;
}
setState(() { });
}
And this is the code to display the image:
Widget _mostrarFoto() {
if (_producto.imagePath != null) {
final String url = utils.completeUrl(_producto.imagePath);
return FadeInImage(
image: NetworkImage(url),
placeholder: AssetImage('assets/jar-loading.gif'),
height: ScreenUtil.instance.setHeight(300.0),
fit: BoxFit.contain
);
} else {
return Image(
image: AssetImage( foto?.path ?? 'assets/no-image.png'),
height: ScreenUtil.instance.setHeight(300.0),
fit: BoxFit.cover,
);
}
}
and this is where I use the functions _seleccionarFoto() and _tomarFoto()
return Scaffold(
key: _scaffoldKey,
appBar: AppBar(
title: _producto == null ? Text('Agregar producto') : Text('Editar producto'),
centerTitle: true,
actions: <Widget>[
IconButton(
icon: Icon(Icons.photo_size_select_actual),
onPressed: _seleccionarFoto,
),
IconButton(
icon: Icon(Icons.camera_alt),
onPressed: _tomarFoto,
),
],
),