Flutter Share Plus:在 WhatsApp 上分享图像和文本

5

我正在尝试为我的Flutter应用程序实现一个功能,使得当用户点击特定按钮时,可以通过邮件、WhatsApp等分享图像和文本。

我使用了share_plus插件和screenshot插件。

到目前为止,当我通过电子邮件分享时,它可以正常工作,但是当我尝试通过WhatsApp分享图像+文本时,就无法正常工作了。 它只会分享文本,而图像始终缺失。 当我删除文本并仅分享图像时,在WhatsApp上一切都很顺利。

请问能否帮助我解决这个问题?非常感谢!

import 'package:flutter/material.dart';
import 'package:share_plus/share_plus.dart';
import 'package:path_provider/path_provider.dart';
import 'dart:typed_data';
import 'package:screenshot/screenshot.dart';
import 'dart:io';
class InfoScreen extends StatelessWidget {
  final controller = ScreenshotController();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Info'),
        flexibleSpace: Container(
          decoration: BoxDecoration(
            gradient: LinearGradient(
                colors: [Color(0xffFBD23E), Color(0xffF6BE03)],
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter),
          ),
        ),
      ),
      body: Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(
              colors: [Color(0xffFEFDFD), Color(0xffBDBDB2)],
              begin: Alignment.topLeft,
              end: Alignment.bottomRight),
        ),
        child: Column(
          children: <Widget>[
ButtonTheme(
              minWidth: 10000,
              height: 45,
              child: Padding(
                padding: EdgeInsets.fromLTRB(15, 2, 15, 15),
                child: Align(
                  alignment: Alignment.topCenter,
                  child: RaisedButton(
                    onPressed: () async {
                      final image = await controller
                          .captureFromWidget(buildImageStartseite());
                      saveAndShare(image);
                    },
                    color: Colors.white,
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.only(
                        bottomLeft: Radius.circular(12.0),
                        bottomRight: Radius.circular(12.0),
                      ),
                    ),
                    highlightColor: Color(0xffB4B4B3),
                    splashColor: Colors.transparent,
                    child: Text(
                      'Press to share',
                      textAlign: TextAlign.center,
                      style: TextStyle(fontSize: 17, color: Color(0xff232323)),
                    ),
                  ),
                ),
              ),
            ),
],
        ),
      ),
    );
  }


  Future saveAndShare(Uint8List bytes) async {
    final directory = await getApplicationDocumentsDirectory();
    final image = File('${directory.path}/Shared_picture.png');
    image.writeAsBytesSync(bytes);
    final text =
        'I'm sharing this with you!';
    await Share.shareFiles([image.path], text: text);
  }
}

我也遇到了同样的问题,你找到解决方法了吗? - JAG
我猜这是一个常见的问题。使用Share Plus插件时,无法同时分享文本和图像。 - Berkin
它在安卓上运行正常,但在iOS上无法运行。 - Muhammad Shafique
我也遇到了同样的问题@Berkin,你找到任何解决方法了吗? - Mofidul Islam
我也遇到了这个问题@Berkin,你解决了吗?或者有什么解决方法吗? - Kaushik Bhingradiya
到这里遇到了同样的问题,但是目前还没有找到解决方案。 - Damandroid
1个回答

1

这是 share_plus 插件的已知问题,除了将图像和文本分开发送之外,没有其他已知的解决方法。正如在问题票中提到的那样,文件和文本不能同时在 WhatsApp 上共享。这是由于 Facebook 在其消息应用程序上的实现限制,正如在线程中讨论的那样。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接