Skip to content

Instantly share code, notes, and snippets.

@anka
Created November 27, 2019 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anka/d6472f87dd7118426133ee0cb915888c to your computer and use it in GitHub Desktop.
Save anka/d6472f87dd7118426133ee0cb915888c to your computer and use it in GitHub Desktop.
Dart class implementation to share files with platform-specific code using a MethodChannel
/// The Share class provides capabilities to share
/// content with platform-specific sharing dialogs
/// using a method channel.
class Share {
static const MethodChannel _channel = const MethodChannel('jademind.com/share');
/// Share a file with other apps.
///
/// Pass a [rect] to indicate the position a share
/// action was initiated from.
static Future<void> file(String subject, String filename, String filepath, String mimeType, {Rect rect}) async {
Map argsMap = Map<String, dynamic>();
argsMap.addAll({'subject': '$subject', 'filename': '$filename', 'filepath': '$filepath', 'mimeType': '$mimeType'});
if (rect != null) {
argsMap.addAll({'x': rect.left, 'y': rect.top});
argsMap.addAll({'width': rect.width, 'height': rect.height,
});
}
_channel.invokeMethod('share-file', argsMap);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment