custom_social_share 1.0.8 copy "custom_social_share: ^1.0.8" to clipboard
custom_social_share: ^1.0.8 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"));
                          },
                        ),
                    ],
                  ),
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
2
likes
140
pub points
76%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on custom_social_share