shareFile static method

Future<bool?> shareFile({
  1. required String title,
  2. required String filePath,
  3. String? text,
  4. String? chooserTitle,
  5. String fileType = '*/*',
})

Shares a local file with the app chooser.

  • Title: It's the title of the message. Used as email subject if sharing with mail apps. The title cannot be null.
  • Text: It's the text of the message.
  • FilePath: It's the filePath to include with the message.
  • ChooserTitle (Just for Android): It's the chooserTitle of the app chooser popup. If null, the system default title will be used.
  • FileType (Just for Android): It's the fileType that will be sent in the chooser popup. If null, the system default title will be used.

Implementation

static Future<bool?> shareFile(
    {required String title,
    required String filePath,
    String? text,
    String? chooserTitle,
    String fileType = '*/*'}) async {
  assert(title.isNotEmpty);
  assert(filePath.isNotEmpty);

  if (title.isEmpty) {
    throw FlutterError('Title cannot be null');
  } else if (filePath.isEmpty) {
    throw FlutterError('FilePath cannot be null');
  }

  final success =
      await _channel.invokeMethod('shareFile', <String, dynamic>{
    'title': title,
    'text': text,
    'filePath': filePath,
    'fileType': fileType,
    'chooserTitle': chooserTitle,
  });

  return success;
}