Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 97371

Why do I get the error when I get an image of the mobile device's gallery: Unable to load asset?

$
0
0

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,
      ),
    ],
  ),


Viewing all articles
Browse latest Browse all 97371

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>