open_social_share 1.0.3 copy "open_social_share: ^1.0.3" to clipboard
open_social_share: ^1.0.3 copied to clipboard

A fork of the open_social_share open for everyone to update and improve.

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:open_social_share/open_social_share.dart';
import 'package:open_social_share/models/models.dart';

void main() {
  runApp(
    const MaterialApp(
      home: MyApp(),
      debugShowCheckedModeBanner: false,
    ),
  );
}

class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  List<String?>? videoUrls = [];
  List<String?>? imageUrls = [];
  final _picker = ImagePicker();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Social Media share plugin example'),
        centerTitle: true,
      ),
      body: Center(
        child: SingleChildScrollView(
          padding: const EdgeInsets.symmetric(horizontal: 16.0),
          physics: const ClampingScrollPhysics(),
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const Padding(
                padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'Basic share',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  var video =
                      await _picker.pickVideo(source: ImageSource.gallery);

                  if (video != null) {
                    OpenSocialShare.F.shareFileToFacebook(
                      filePath: video.path,
                      dstPath: '/OpenSocialShareExample/Facebook/',
                      fileProviderPath: '.social.share.fileprovider',
                      fileType: AssetType.video,
                    );
                  }
                },
                child: const Text('Share file to facebook'),
              ),
              ElevatedButton(
                onPressed: () {
                  OpenSocialShare.F.shareFeedContentToFacebook(
                    link: "https://pub.dev",
                    linkName: "pub",
                    hashtag: "flutter_pub",
                  );
                },
                child: const Text('Share feed content to facebook'),
              ),
              ElevatedButton(
                onPressed: () {
                  OpenSocialShare.F.shareLinkContentToFacebook(
                    contentUrl: "https://pub.dev",
                  );
                },
                child: const Text('Share link content to facebook'),
              ),
              ElevatedButton(
                onPressed: () async {
                  var texture =
                      await _picker.pickImage(source: ImageSource.gallery);

                  if (texture != null) {
                    OpenSocialShare.F.shareCameraEffectToFacebook(
                      cameraEffectTextures: CameraEffectTextures(
                        textureKey: 'texture_key',
                        textureUrl: texture.path,
                      ),
                      cameraEffectArguments: const CameraEffectArguments(
                        argumentKey: 'argument_key',
                        argumentValue: 'argument_value',
                        argumentList: [],
                      ),
                      hashtag: '#helloworld',
                      contentUrl: 'https://pub.dev',
                    );
                  }
                },
                child: const Text('Share camera effect to facebook'),
              ),
              const Padding(
                padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'Media content share',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  imageUrls = (await _picker.pickMultiImage())
                      .map((image) => image.path)
                      .toList();
                  videoUrls =
                      (await _pickFile(FileType.video, allowMultiple: true))
                          ?.paths;

                  OpenSocialShare.F.shareMediaContentFileToFacebook(
                    imageUrls: imageUrls,
                    videoUrls: videoUrls,
                    fileProviderPath: '.social.share.fileprovider',
                  );
                },
                child: const Text('Share media content file to facebook'),
              ),
              const Padding(
                padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'Facebook story share',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  var image =
                      await _picker.pickImage(source: ImageSource.gallery);

                  OpenSocialShare.F.shareBackgroundAssetFileToFacebookStory(
                    appId: '3258588111079263',
                    filePath: image?.path,
                    fileProviderPath: '.social.share.fileprovider',
                    fileType: AssetType.image,
                  );
                },
                child: const Text(
                  'Share background asset file to facebook story',
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  var image =
                      await _picker.pickImage(source: ImageSource.gallery);

                  OpenSocialShare.F.shareStickerAssetToFacebookStory(
                    appId: '3258588111079263',
                    stickerPath: image?.path,
                    fileProviderPath: '.social.share.fileprovider',
                  );
                },
                child: const Text(
                    'Share sticker background asset to facebook story'),
              ),
              Padding(
                padding: const EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'Facebook story share ${Platform.isAndroid ? 'using ShareStoryContent' : ''}',
                  style: const TextStyle(fontSize: 20.0),
                ),
              ),
              Visibility(
                visible: Platform.isAndroid,
                child: ElevatedButton(
                  onPressed: () async {
                    var image =
                        await _picker.pickImage(source: ImageSource.gallery);

                    OpenSocialShare.F
                        .shareBitmapImageBackgroundAssetToFacebookStory(
                      imagePath: image?.path,
                      fileProviderPath: '.social.share.fileprovider',
                    );
                  },
                  child: const Text(
                      'Share bitmap image background asset to facebook story'),
                ),
              ),
              Visibility(
                visible: Platform.isAndroid,
                child: ElevatedButton(
                  onPressed: () async {
                    var image =
                        await _picker.pickImage(source: ImageSource.gallery);

                    OpenSocialShare.F
                        .shareImageBackgroundAssetContentToFacebookStory(
                      photoBackgroundAssetPath: image?.path,
                      fileProviderPath: '.social.share.fileprovider',
                    );
                  },
                  child: const Text(
                      'Share photo background asset content to facebook story'),
                ),
              ),
              Visibility(
                visible: Platform.isAndroid,
                child: ElevatedButton(
                  onPressed: () async {
                    var video =
                        await _picker.pickVideo(source: ImageSource.gallery);

                    OpenSocialShare.F
                        .shareVideoBackgroundAssetContentToFacebookStory(
                      videoBackgroundAssetPath: video?.path,
                      fileProviderPath: '.social.share.fileprovider',
                    );
                  },
                  child: const Text(
                      'Share video background asset to facebook story'),
                ),
              ),
              Visibility(
                visible: Platform.isIOS,
                child: ElevatedButton(
                  onPressed: () async {
                    var images = await _picker.pickMultiImage();
                    var stickers = await _picker.pickMultiImage();

                    OpenSocialShare.F
                        .shareBackgroundImageAndStickerToFacebookStoryiOS(
                      photoBackgroundAssetPaths:
                          images.map((image) => image.path).toList(),
                      stickerAssetPaths:
                          stickers.map((image) => image.path).toList(),
                      appId: '3258588111079263',
                    );
                  },
                  child: const Text(
                      'Share background image and sticker asset to facebook story iOS'),
                ),
              ),
              const Padding(
                padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'Facebook reels share',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  XFile? sticker;
                  if (Platform.isAndroid) {
                    sticker =
                        await _picker.pickImage(source: ImageSource.gallery);
                  }
                  var video = await _pickFile(FileType.video);

                  OpenSocialShare.F.shareVideoToFacebookReels(
                    filePath: video?.paths[0],
                    fileProviderPath: '.social.share.fileprovider',
                    appId: '3258588111079263',
                    stickerPath: sticker?.path,
                  );
                },
                child: const Text(
                    'Share video asset (and sticker on Android) to facebook reels'),
              ),
              const Padding(
                padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'Instagram share',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  var video =
                      await _picker.pickImage(source: ImageSource.gallery);

                  if (video != null) {
                    OpenSocialShare.I.shareFileToInstagram(
                      filePath: video.path,
                      fileProviderPath: '.social.share.fileprovider',
                      fileType: AssetType.image,
                    );
                  }
                },
                child: const Text('Share file to instagram'),
              ),
              ElevatedButton(
                onPressed: () async {
                  OpenSocialShare.I.sendMessageToInstagram(
                    message: 'Hello world',
                  );
                },
                child: const Text('Send message to instagram'),
              ),
              const Padding(
                padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'Messenger share',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  var video =
                      await _picker.pickVideo(source: ImageSource.gallery);

                  OpenSocialShare.M
                      .shareFileToMessenger(
                    filePath: video?.path,
                    fileProviderPath: '.social.share.fileprovider',
                    fileType: AssetType.video,
                    hashtag: '#helloworld',
                    contentUrl: 'https://pub.dev',
                  )
                      .catchError((err) {
                    print('Share file to messenger error $err');
                  });
                },
                child: const Text('Share file to messenger'),
              ),
              ElevatedButton(
                onPressed: () async {
                  OpenSocialShare.M.sendMessageToMessenger(
                    message: 'https://pub.dev',
                    quote: 'Hello world',
                    hashtag: '#hello',
                  );
                },
                child: const Text('Send message to messenger'),
              ),
              ElevatedButton(
                onPressed: () async {
                  OpenSocialShare.M.shareLinkContentToMessenger(
                    contentUrl: 'https://pub.dev',
                    quote: 'Hello world',
                    hashtag: '#hello',
                  );
                },
                child: const Text('Share link content to messenger'),
              ),
              const Padding(
                padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'Telegram share',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  OpenSocialShare.T.sendMessageToTelegram(
                    message: 'Hello world',
                  );
                },
                child: const Text('Send message to Telegram'),
              ),
              ElevatedButton(
                onPressed: () async {
                  OpenSocialShare.T.openTelegramDirectMessage(
                    username: 'user_name',
                  );
                },
                child: const Text('Open Telegram direct message'),
              ),
              ElevatedButton(
                onPressed: () async {
                  OpenSocialShare.T.openTelegramChannelViaShareLink(
                    inviteLink: 'your_invite_link',
                  );
                },
                child: const Text('Open Telegram group via invite link'),
              ),
              ElevatedButton(
                onPressed: () async {
                  var file = await _pickFile(FileType.any);

                  OpenSocialShare.T.shareFileToTelegram(
                    filePath: file?.paths[0],
                    fileProviderPath: '.social.share.fileprovider',
                    fileType: AssetType.any,
                    message: 'Hello friend',
                  );
                },
                child: const Text('Share file to Telegram'),
              ),
              const Padding(
                padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'WhatsApp share',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  var file = await _pickFile(FileType.any);

                  OpenSocialShare.W.shareFileToWhatsApp(
                    filePath: file?.paths[0],
                    fileType: AssetType.pdf,
                    fileProviderPath: '.social.share.fileprovider',
                    message: 'Hello friend',
                  );
                },
                child: const Text('Share file to WhatsApp'),
              ),
              ElevatedButton(
                onPressed: () async {
                  OpenSocialShare.W.sendMessageToWhatsApp(
                    message: 'https://pub.dev',
                    phoneNumber: "receiver_phone_number",
                  );
                },
                child: const Text('Send message to WhatsApp'),
              ),
              const Padding(
                padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'Twitter share',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  OpenSocialShare.TW.createTwitterTweet(
                    title: 'Hello world',
                    attachedUrl: "https://pub.dev",
                    hashtags: [
                      'hello',
                      'world',
                    ],
                    via: 'abc',
                    related: ['twitter', 'twitterapi'],
                  );
                },
                child: const Text('Create Twitter tweet'),
              ),
              ElevatedButton(
                onPressed: () async {
                  var file =
                      await _picker.pickImage(source: ImageSource.gallery);

                  OpenSocialShare.TW.shareFileToTwitter(
                    filePath: file?.path,
                    fileProviderPath: '.social.share.fileprovider',
                    fileType: AssetType.image,
                    iOSConsumerKey: 'abc',
                    iOSSecretKey: 'xyz',
                    title: "Hello world",
                  );
                },
                child: const Text('Share file to Twitter'),
              ),
              const Padding(
                padding: EdgeInsets.only(top: 24.0, bottom: 8.0),
                child: Text(
                  'TikTok share',
                  style: TextStyle(fontSize: 20.0),
                ),
              ),
              ElevatedButton(
                onPressed: () async {
                  var res = await _picker.pickMultiImage();

                  OpenSocialShare.TI.shareFilesToTikTok(
                    fileUrls: res.map((e) => e.path).toList(),
                    fileType: AssetType.image,
                    fileProviderPath: '.social.share.fileprovider',
                  );
                },
                child: const Text('Share files to TikTok'),
              ),
              ElevatedButton(
                onPressed: () async {
                  OpenSocialShare.TI.openTikTokUserPage(
                    username: 'username',
                  );
                },
                child: const Text('Open TikTok user page'),
              ),
              const SizedBox(height: 24.0),
            ],
          ),
        ),
      ),
    );
  }

  Future<FilePickerResult?> _pickFile(FileType type,
      {bool allowMultiple = false}) async {
    return await FilePicker.platform
        .pickFiles(allowMultiple: allowMultiple, type: type);
  }
}
0
likes
0
pub points
65%
popularity

Publisher

unverified uploader

A fork of the open_social_share open for everyone to update and improve.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on open_social_share