saveWidget2Album static method

Future<SaveResult?> saveWidget2Album(
  1. GlobalKey<State<StatefulWidget>> key, {
  2. ImageByteFormat format = ImageByteFormat.png,
  3. String? fileName,
  4. int quality = 80,
})

将widget转为图片保存到相册,返回路径 key所在节点必须是RepaintBoundary节点,否则会报错,截取 RenderRepaintBoundary 的内容

Implementation

static Future<SaveResult?> saveWidget2Album(GlobalKey key, {ImageByteFormat format = ImageByteFormat.png,
  String? fileName, int quality = 80}) async {
  var bytes = await widget2image(key, format: format);
  if (bytes != null) {
    return await saveBytes2Album(bytes.buffer.asUint8List(), format: format, fileName: fileName, quality: quality);
    // final result = await ImageGallerySaver.saveImage(bytes.buffer.asUint8List(),
    //     name: fileName,
    //     quality: quality,
    //     isReturnImagePathOfIOS: true);
    // return result["filePath"] ;
  }else{
    return null;
  }
}