Flutter调用相册闪退出现image from picker that was not requested

Flutter调用相册闪退出现image from picker that was not requested

最近突然在调用相册的时候,在选择的时候突然闪退了,控制台出现

image from picker that was not requested
  • 1

升级image_picker最新版本也没用,emmmmmmm
经过分析,后来发现在用image_picker插件的同时,又使用image_saver的插件,导致这两个插件冲突,删除image_saver这个保存图片的插件库之后,用自己写的保存图片到本地的方法之后可以正常选择图片了。

Future<Uint8List> capturePng() async{
    try{
      RenderRepaintBoundary boundary = _globalKey.currentContext.findRenderObject();
      var image = await boundary.toImage(pixelRatio: 3);
      ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
      Uint8List pngBytes = byteData.buffer.asUint8List();
      return pngBytes;
    }catch (e){
      print(e);
    }
    return null;
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
void _click() async{
    var data = await capturePng();
    //var bs64 = base64Encode(data);
    String dir = (await getApplicationDocumentsDirectory()).path;
    File file = File(
        "$dir/" + DateTime.now().millisecondsSinceEpoch.toString() + ".png");
    var _result = await file.writeAsBytes(data);
    print(_result);
    if(_result != null){
      ToastUtil.showNormal("保存成功!");
    }else{
      ToastUtil.showNormal("保存失败!");
    }
  }
posted @ 2020-09-24 21:53  小周同学、  阅读(222)  评论(0)    收藏  举报