flutter_share_me 1.0.0 copy "flutter_share_me: ^1.0.0" to clipboard
flutter_share_me: ^1.0.0 copied to clipboard

outdated

Flutter Plugin for sharing contents to social media.You can use it share to Facebook , WhatsApp , Twitter And System Share UI. Support Url and Text.

example/lib/main.dart

import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter_share_me/flutter_share_me.dart';
import 'package:image_picker/image_picker.dart';
import 'package:path_provider/path_provider.dart';

enum Share { facebook, twitter, whatsapp, whatsapp_business, share_system }

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String msg = 'hello,this is my github:https://github.com/lizhuoyuan';
  File? file;
  ImagePicker picker = ImagePicker();

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Container(
          width: double.infinity,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: <Widget>[
              SizedBox(height: 30),
              ElevatedButton(onPressed: pickImage, child: Text('Pick Image')),
              ElevatedButton(
                  onPressed: () => onButtonTap(Share.twitter), child: Text('share to twitter')),
              ElevatedButton(
                onPressed: () => onButtonTap(Share.whatsapp),
                child: Text('share to WhatsApp'),
              ),
              ElevatedButton(
                onPressed: () => onButtonTap(Share.whatsapp_business),
                child: Text('share to WhatsApp  Business'),
              ),
              ElevatedButton(
                onPressed: () => onButtonTap(Share.facebook),
                child: Text('share to  FaceBook'),
              ),
              ElevatedButton(
                onPressed: () => onButtonTap(Share.share_system),
                child: Text('share to System'),
              ),
            ],
          ),
        ),
      ),
    );
  }

  void pickImage() async {
    XFile? xFile = await picker.pickImage(source: ImageSource.camera);
    print(xFile);
    Uint8List u = await xFile!.readAsBytes();
    await getFile();
    if (!file!.existsSync()) {
      file!.createSync();
      print('create file:$file');
    }
    file!.writeAsBytesSync(u);
    if (file!.existsSync()) {
      print('image save success,path:${file!.path}');
    }
  }

  Future<void> getFile() async {
    Directory tempDir = await getTemporaryDirectory();
    file = File('${tempDir.path}/img${DateTime.now()}.png');
  }

  Future<void> onButtonTap(Share share) async {
    String msg =
        'Flutter share is great!!\n Check out full example at https://pub.dev/packages/flutter_share_me';
    String url = 'https://pub.dev/packages/flutter_share_me';

    String? response;
    FlutterShareMe flutterShareMe = FlutterShareMe();
    switch (share) {
      case Share.facebook:
        response = await flutterShareMe.shareToFacebook(url: url, msg: msg);
        break;
      case Share.twitter:
        response = await flutterShareMe.shareToTwitter(url: url, msg: msg);
        break;
      case Share.whatsapp:
        response = await flutterShareMe.shareToWhatsApp(msg: msg, imagePath: file!.path);
        break;
      case Share.whatsapp_business:
        response = await flutterShareMe.shareToWhatsApp(msg: msg);

        break;
      case Share.share_system:
        response = await flutterShareMe.shareToSystem(msg: msg);

        break;
    }

    print(response);
  }
}
183
likes
0
pub points
96%
popularity

Publisher

unverified uploader

Flutter Plugin for sharing contents to social media.You can use it share to Facebook , WhatsApp , Twitter And System Share UI. Support Url and Text.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on flutter_share_me