PlatformException (PlatformException(分享回调错误,之前的分享表没有回调,您等待吗

omb*_*iro 6 share flutter

PlatformException (PlatformException(Share callback error, prior share-sheet did not call back, did you await it就我而言,使用以下代码时出现以下错误:

\n
final XFile file = XFile(path);\nawait Share.shareXFiles([file],\n
Run Code Online (Sandbox Code Playgroud)\n

但如果我使用如下所示的已弃用方法(传递列表),则图像共享效果完美:

\n
await Share.shareFiles([path],\nsubject: subject,\ntext: text,\nsharePositionOrigin: box.localToGlobal(Offset.zero) & box.size);\n
Run Code Online (Sandbox Code Playgroud)\n

shareFiles被标记为已弃用,但工作正常,在遵循文档并使用时shareXFiles,会抛出平台异常错误:

\n

我的环境:

\n

Flutter 3.7.10 \xe2\x80\xa2 通道稳定 \xe2\x80\xa2 https://github.com/flutter/flutter.git \nFramework \xe2\x80\xa2 修订版 4b12645012(9 天前) \xe2\x80 \xa2 2023-04-03 17:46:48 -0700\n引擎 \xe2\x80\xa2 修订版 ec975089ac\n工具 \xe2\x80\xa2 Dart 2.19.6 \xe2\x80\xa2 DevTools 2.20.1

\n

Jin*_*Gor 0

我通过将 share_plus 版本从 7.0.2 降级到 7.0.0 解决了这个问题。

  final directoryPath = (await getTemporaryDirectory()).path;
  final imagePath = '$directoryPath/qrimg.png';
  final imageFile = await File(imagePath).create(recursive: true);
  imageFile.writeAsBytesSync(byteData.buffer.asUint8List());

  final file = XFile(imagePath);
  await Share.shareXFiles([file]);
Run Code Online (Sandbox Code Playgroud)

Flutter SDK - 3.7.11 Android 版本 12