custom_social_share 1.0.9 copy "custom_social_share: ^1.0.9" to clipboard
custom_social_share: ^1.0.9 copied to clipboard

Flutter plugin for sharing text content to most popular social media apps.

example/lib/main.dart

import 'package:custom_social_share/custom_social_share.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

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

class _MyAppState extends State<MyApp> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData.from(
          colorScheme: const ColorScheme.light(), useMaterial3: true),
      darkTheme: ThemeData.from(
          colorScheme: const ColorScheme.dark(), useMaterial3: true),
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  const HomeScreen({super.key});

  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  final _share = CustomSocialShare();

  final _msg = 'Hii from new plugin https://www.google.com with link';
  var _onlyInstalled = false;
  var _installedApps = <ShareWith>[];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Flutter Social Share'),
      ),
      body: Column(
        children: [
          SwitchListTile.adaptive(
            title: const Text('Only installed app'),
            value: _onlyInstalled,
            onChanged: (bool value) {
              _onlyInstalled = value;
              setState(() {});

              if (value) {
                WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
                  _share.getInstalledAppsForShare().then((value) {
                    debugPrint("_MyAppState.build: $value");
                    _installedApps = value;
                    setState(() {});
                  });
                });
              }
            },
            secondary: const Icon(Icons.install_mobile),
          ),
          Expanded(
            child: SingleChildScrollView(
              child: IntrinsicWidth(
                child: SafeArea(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    children: [
                      ElevatedButton(
                        child: const Text('Copy'),
                        onPressed: () {
                          _share.copy(_msg).then((value) {
                            ScaffoldMessenger.of(context).showSnackBar(
                                const SnackBar(
                                    content:
                                        Text('Copied to your clipboard !')));
                          });
                        },
                      ),
                      ElevatedButton(
                        child: const Text('All'),
                        onPressed: () {
                          _share.toAll(_msg).then((value) =>
                              debugPrint("_MyAppState.build: $value"));
                        },
                      ),
                      ElevatedButton(
                        child: const Text('Custom App'),
                        onPressed: () {
                          _share
                              .customApp(
                                  'com.google.android.apps.dynamite', _msg)
                              .then((value) =>
                                  debugPrint("_MyAppState.build: $value"));
                        },
                      ),
                      for (var item in (_onlyInstalled
                          ? _installedApps
                          : ShareWith.values))
                        ElevatedButton(
                          child: Text(item.name),
                          onPressed: () {
                            _share.to(item, _msg).then((value) =>
                                debugPrint("_MyAppState.build: $value"));
                          },
                        ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
6
likes
160
points
801
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin for sharing text content to most popular social media apps.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on custom_social_share