flutter - 通过 android 和 ios 中的几个按钮在社交媒体上分享链接

标签 flutter hyperlink share

这是三个社交媒体按钮。 我只想通过 Android 和 ios 中的这些按钮在社交媒体上分享链接。

enter image description here

我用了flutter_share_me插入。但这个插件有两个问题。

1.)此插件仅针对 Android 设备定义,不适用于 ios。

2.)它不是为 Instagram 定义的。

代码:

对于 Facebook:

IconButton(
             icon: Image.asset("assets/icons/facebook_logo.png",fit:BoxFit.fill,color: Colors.white,),
             onPressed: (){
                 FlutterShareMe().shareToFacebbok(url: appUrl,  msg: "Babilok");

               }     
             ),

推特:

IconButton(
             icon: Image.asset("assets/icons/twitter_logo1.png",fit:BoxFit.fill,color: Colors.white,),
             onPressed: (){
                 FlutterShareMe().shareToTwitter(url: appUrl,  msg: "Babilok");

               }     
             ),

对于 Instagram:

IconButton(
             icon: Image.asset("assets/icons/instagram_logo.png",fit:BoxFit.fill,color: Colors.white,),
             onPressed: (){
                ?????????.....

               }     
             ),

最佳答案

您可以使用这个插件flutter_social_content_share

这个插件在 iOS 和 Android 上都可以正常工作。

/// SHARE ON FACEBOOK CALL
  shareOnFacebook() async {
    String result = await FlutterSocialContentShare.share(
        type: ShareType.facebookWithoutImage,
        url: "https://www.apple.com",
        quote: "captions");
    print(result);
  }

  /// SHARE ON INSTAGRAM CALL
  shareOnInstagram() async {
    String result = await FlutterSocialContentShare.share(
        type: ShareType.instagramWithImageUrl,
        imageUrl:
            "https://post.healthline.com/wp-content/uploads/2020/09/healthy-eating-ingredients-732x549-thumbnail-732x549.jpg");
    print(result);
  }

  /// SHARE ON WHATSAPP CALL
  shareWatsapp() async {
    String result = await FlutterSocialContentShare.shareOnWhatsapp(
        number: "xxxxxx", text: "Text appears here");
    print(result);
  }

  /// SHARE ON EMAIL CALL
  shareEmail() async {
    String result = await FlutterSocialContentShare.shareOnEmail(
        recipients: ["<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a2dadadada8cdadadae2c5cfc3cbce8cc1cdcf" rel="noreferrer noopener nofollow">[email protected]</a>"],
        subject: "Subject appears here",
        body: "Body appears here",
        isHTML: true); //default isHTML: False
    print(result);
  }

  /// SHARE ON SMS CALL
  shareSMS() async {
    String result = await FlutterSocialContentShare.shareOnSMS(
        recipients: ["xxxxxx"], text: "Text appears here");
    print(result);
  }

  ///Build Context
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Column(
          children: <Widget>[
            Text('Running on: $_platformVersion\n'),
            RaisedButton(
              child: Text("Share to facebook button"),
              color: Colors.red,
              onPressed: () {
                shareOnFacebook();
              },
            ),
            RaisedButton(
              child: Text("Share to instagram button"),
              color: Colors.red,
              onPressed: () {
                shareOnInstagram();
              },
            ),
            RaisedButton(
              child: Text("Share to whatsapp button"),
              color: Colors.red,
              onPressed: () {
                shareWatsapp();
              },
            ),
            RaisedButton(
              child: Text("Share to email button"),
              color: Colors.red,
              onPressed: () {
                shareEmail();
              },
            ),
            RaisedButton(
              child: Text("Share to sms button"),
              color: Colors.red,
              onPressed: () {
                shareSMS();
              },
            ),
          ],
        ),
      ),
    );
  }

关于flutter - 通过 android 和 ios 中的几个按钮在社交媒体上分享链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58299384/

相关文章:

android - 如何在 Flutter 中重新创建此布局?

javascript - 单击 float div 中的链接不起作用

html - 使用谷歌工具缩小后的 css 图像链接

xcode - Swift 2 - 使用 UIActivityViewController 分享视频

c++ - 在两个文件之间共享 C++ 结构

flutter - 在视频上放置文字-Flutter-web

android - 我如何使用StreamBuilder而不出现这个轻微的null错误

ios - Flutter:如何在安装/卸载期间删除 FlutterSecureStorage 项目

iphone - 我的 iPhone 应用程序可以正常运行的链接吗?

java - 在 Android 上将 Bitmap() 分享到推特、 Facebook 、邮件