first commit
This commit is contained in:
4
lib/custom_social_share.dart
Normal file
4
lib/custom_social_share.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
library custom_social_share;
|
||||
|
||||
export 'src/custom_social_share.dart';
|
||||
export 'src/enums.dart';
|
33
lib/src/custom_social_share.dart
Normal file
33
lib/src/custom_social_share.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'custom_social_share_platform_interface.dart';
|
||||
import 'enums.dart';
|
||||
|
||||
/// CustomSocialShare to copy content to clipboard and share text
|
||||
class CustomSocialShare {
|
||||
/// copy text [content] to clipboard
|
||||
Future<void> copy(String content) {
|
||||
return CustomSocialSharePlatform.instance.copy(content);
|
||||
}
|
||||
|
||||
/// open system UI to share text [content]
|
||||
Future<bool> toAll(String content) {
|
||||
return CustomSocialSharePlatform.instance.toAll(content);
|
||||
}
|
||||
|
||||
/// share text [content] with social apps
|
||||
/// [shareWith] is [ShareWith] different type of default apps
|
||||
Future<bool> to(ShareWith shareWith, String content) {
|
||||
return CustomSocialSharePlatform.instance.to(shareWith, content);
|
||||
}
|
||||
|
||||
/// return list of default [ShareWith] installed apps
|
||||
Future<List<ShareWith>> getInstalledAppsForShare() async {
|
||||
return CustomSocialSharePlatform.instance.getInstalledAppsForShare();
|
||||
}
|
||||
|
||||
/// custom app share only for Android
|
||||
/// [package] is android application id
|
||||
/// text [content] to share
|
||||
Future<bool> customApp(String package, String content) {
|
||||
return CustomSocialSharePlatform.instance.customApp(package, content);
|
||||
}
|
||||
}
|
60
lib/src/custom_social_share_method_channel.dart
Normal file
60
lib/src/custom_social_share_method_channel.dart
Normal file
@@ -0,0 +1,60 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'custom_social_share_platform_interface.dart';
|
||||
import 'enums.dart';
|
||||
|
||||
/// An implementation of [CustomSocialSharePlatform] that uses method channels.
|
||||
class MethodChannelCustomSocialShare extends CustomSocialSharePlatform {
|
||||
/// The method channel used to interact with the native platform.
|
||||
@visibleForTesting
|
||||
final methodChannel = const MethodChannel('custom_social_share');
|
||||
|
||||
@override
|
||||
Future<void> copy(String content) {
|
||||
return Clipboard.setData(ClipboardData(text: content));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> toAll(String content) {
|
||||
return methodChannel.invokeMethod<bool>('toAll',
|
||||
{"content": content}).then<bool>((bool? value) => value ?? false);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> to(ShareWith shareWith, String content) {
|
||||
return methodChannel.invokeMethod<bool>(shareWith.name,
|
||||
{"content": content}).then<bool>((bool? value) => value ?? false);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<ShareWith>> getInstalledAppsForShare() {
|
||||
return methodChannel
|
||||
.invokeMapMethod<String, bool>('getInstalledApps')
|
||||
.then((map) {
|
||||
if (map == null) return [];
|
||||
map.removeWhere((key, value) => !value);
|
||||
return map.keys
|
||||
.map((e) {
|
||||
try {
|
||||
ShareWith.values.byName(e);
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.whereType<ShareWith>()
|
||||
.toList();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> customApp(String package, String content) {
|
||||
if (!Platform.isAndroid) return Future.value(false);
|
||||
return methodChannel.invokeMethod<bool>('customApp', {
|
||||
"package": package,
|
||||
"content": content
|
||||
}).then<bool>((bool? value) => value ?? false);
|
||||
}
|
||||
}
|
55
lib/src/custom_social_share_platform_interface.dart
Normal file
55
lib/src/custom_social_share_platform_interface.dart
Normal file
@@ -0,0 +1,55 @@
|
||||
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
|
||||
|
||||
import 'custom_social_share_method_channel.dart';
|
||||
import 'enums.dart';
|
||||
|
||||
abstract class CustomSocialSharePlatform extends PlatformInterface {
|
||||
/// Constructs a CustomSocialSharePlatform.
|
||||
CustomSocialSharePlatform() : super(token: _token);
|
||||
|
||||
static final Object _token = Object();
|
||||
|
||||
static CustomSocialSharePlatform _instance = MethodChannelCustomSocialShare();
|
||||
|
||||
/// The default instance of [CustomSocialSharePlatform] to use.
|
||||
///
|
||||
/// Defaults to [MethodChannelCustomSocialShare].
|
||||
static CustomSocialSharePlatform get instance => _instance;
|
||||
|
||||
/// Platform-specific implementations should set this with their own
|
||||
/// platform-specific class that extends [CustomSocialSharePlatform] when
|
||||
/// they register themselves.
|
||||
static set instance(CustomSocialSharePlatform instance) {
|
||||
PlatformInterface.verifyToken(instance, _token);
|
||||
_instance = instance;
|
||||
}
|
||||
|
||||
/// copy text [content] to clipboard
|
||||
Future<void> copy(String content) {
|
||||
throw UnimplementedError('copy() has not been implemented.');
|
||||
}
|
||||
|
||||
/// open system UI to share text [content]
|
||||
Future<bool> toAll(String content) {
|
||||
throw UnimplementedError('toAll() has not been implemented.');
|
||||
}
|
||||
|
||||
/// share text [content] with social apps
|
||||
/// [shareWith] is [ShareWith] different type of default apps
|
||||
Future<bool> to(ShareWith shareWith, String content) {
|
||||
throw UnimplementedError('to() has not been implemented.');
|
||||
}
|
||||
|
||||
/// return list of default [ShareWith] installed apps
|
||||
Future<List<ShareWith>> getInstalledAppsForShare() {
|
||||
throw UnimplementedError(
|
||||
'getInstalledAppsForShare() has not been implemented.');
|
||||
}
|
||||
|
||||
/// custom app share only for Android
|
||||
/// [package] is android application id
|
||||
/// text [content] to share
|
||||
Future<bool> customApp(String package, String content) {
|
||||
throw UnimplementedError('customApp() has not been implemented.');
|
||||
}
|
||||
}
|
22
lib/src/enums.dart
Normal file
22
lib/src/enums.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
/// number of apps to share content
|
||||
enum ShareWith {
|
||||
sms,
|
||||
email,
|
||||
facebook,
|
||||
facebookLite,
|
||||
facebookMessenger,
|
||||
facebookMessengerLite,
|
||||
instagram,
|
||||
line,
|
||||
linkedin,
|
||||
reddit,
|
||||
skype,
|
||||
slack,
|
||||
snapchat,
|
||||
telegram,
|
||||
x,
|
||||
viber,
|
||||
wechat,
|
||||
whatsapp,
|
||||
threads,
|
||||
}
|
Reference in New Issue
Block a user