微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

尝试使用 flutter 中的 share_plus 包共享图片时,如何修复 Facebook ios 共享对话框崩溃?

如何解决尝试使用 flutter 中的 share_plus 包共享图片时,如何修复 Facebook ios 共享对话框崩溃?

我正在尝试向 Flutter 应用程序添加一项功能,该功能允许用户使用 share_plus 包将图片分享到其他应用程序。在 Android 中一切正常。将图片分享到 Facebook 以外的应用程序大部分时间都有效,除了某些照片(不确定是否相关),但每当我尝试将图片分享到我的 Facebook 新闻提要时,Facebook 预览对话框会短暂弹出然后崩溃,带我去返回 IOS 共享对话框。

我已根据需要将 Facebook 应用 ID 添加到 Info.plist。

相关代码如下:

  final picker = ImagePicker();
  String _imagePath;

  // Open image picker for the user's photo gallery or camera
  Future getimage(ImageSource source) async {
    var storageResult;
    String finalPath;
    final pickedFile = await picker.getimage(
      source: source,imageQuality: 10,);

    if (pickedFile != null) {
      // if the image source is camera,save the picture to the gallery before loading it to the app
      if (source == ImageSource.camera) {
        if (await Permission.storage.request().isGranted) {
          storageResult = await ImagegallerySaver.saveImage(
              await pickedFile.readAsBytes(),isReturnImagePathOfIOS: true);
          finalPath = storageResult["filePath"].split("file:///")[1];
        } else {
          return;
        }
      } else {
        finalPath = pickedFile.path;
      }
    }
    setState(() {
      _imagePath = finalPath;
    });
  }

  @override
  Widget build(BuildContext context) {
    Color primaryColor = Theme.of(context).primaryColor;
    TextStyle textStyle =
        Theme.of(context).textTheme.bodyText1.copyWith(color: primaryColor);

    // Show dialog asking if the user would like to share photos
    Future<void> _showPhotoDialog() async {
      return showDialog<void>(
        context: context,barrierdismissible: false,// user must tap button to close
        builder: (BuildContext context) {
          return PhotoShareDialog(
            galleryImageFunction: () => getimage(ImageSource.gallery),cameraimageFunction: () => getimage(ImageSource.camera),);
        },);
    }

    void _shareActivity(ShortDynamicLink shareLink) async {
      await _showPhotoDialog();
      if (_imagePath != null) {
        // Share with photo
        if (Platform.isIOS) {
          Share.shareFiles(
            [_imagePath],);
        } else {
          Share.shareFiles(
            [_imagePath],text: widget.shareText + " " + shareLink.shortUrl.toString(),subject: "Check out this adventure!",);
        }
        setState(() {
          _imagePath = null;
        });
      } else {
        // Share without photo
        Share.share(widget.shareText + " " + shareLink.shortUrl.toString(),subject: "Check out this adventure!");
      }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。