当我获得移动设备图库的图像时,为什么会出现错误:无法加载资产?

我正在使用image_picker包来处理图像,然后在选择它时显示它,但是有时它可以正常工作,有时应用程序崩溃,当我在调用堆栈部分中查看调试窗口时,得到了这个错误:FlutterError(无法加载资产:/storage/emulated/0/Android/data/com.example.produmax/files/Pictures/scaled_product.jpg

FlutterError(无法加载资产:/storage/emulated/0/Android/data/com.example.produmax/files/Pictures/scaled_product.jpg)

这是我用来处理图像的代码

_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(() { });
}

这是显示图像的代码:

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'),fit: BoxFit.cover,);
  }
}

这是我使用函数_seleccionarFoto()和_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,],
qzheng123 回答:当我获得移动设备图库的图像时,为什么会出现错误:无法加载资产?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3169888.html

大家都在问