shareFile method

Future<void> shareFile (
  1. List<int> fileByte,
  2. String fileName,
  3. String mimeType,
  4. {String shareTitle: 'Share with',
  5. String appToShare: '',
  6. String captionText: ''}
)

Implementation

static Future<void> shareFile(
  List<int> fileByte, //The byte format of the file see example on how to obtain
  String fileName, //The file name.
  String mimeType, // The type of text your sharing  ie text/txt image/png etc
  {
    String shareTitle = 'Share with', // The title that appears in the share pop up
    String appToShare = '', //The app you want to use to share with, if blank will pop up the share choose ie 'com.whatsapp'
    String captionText = '' //Caption text to share with.
  }) async {
  Map argsMap = <String, String>{
    'shareTitle': '$shareTitle',
    'fileName': '$fileName',
    'mimeType': '$mimeType',
    'captionText': '$captionText',
    'appToShare': '$appToShare'
  };

  //Get the temp directory path and create a new file
  final tempDir = await getTemporaryDirectory();
  final file = await new File('${tempDir.path}/$fileName').create();
  await file.writeAsBytes(fileByte);

  _channel.invokeMethod('shareFile', argsMap);
}