shareXFiles method
Summons the platform's share sheet to share multiple files.
Implementation
@override
Future<ShareResult> shareXFiles(
List<XFile> files, {
String? subject,
String? text,
Rect? sharePositionOrigin,
List<String>? fileNameOverrides,
}) async {
assert(files.isNotEmpty);
assert(
fileNameOverrides == null || files.length == fileNameOverrides.length,
"fileNameOverrides list must have the same length as files list.",
);
final filesWithPath = await _getFiles(files, fileNameOverrides);
assert(filesWithPath.every((element) => element.path.isNotEmpty));
final mimeTypes = filesWithPath
.map((e) => e.mimeType ?? _mimeTypeForPath(e.path))
.toList();
final paths = filesWithPath.map((e) => e.path).toList();
assert(paths.length == mimeTypes.length);
assert(mimeTypes.every((element) => element.isNotEmpty));
final params = <String, dynamic>{
'paths': paths,
'mimeTypes': mimeTypes,
};
if (subject != null) params['subject'] = subject;
if (text != null) params['text'] = text;
if (sharePositionOrigin != null) {
params['originX'] = sharePositionOrigin.left;
params['originY'] = sharePositionOrigin.top;
params['originWidth'] = sharePositionOrigin.width;
params['originHeight'] = sharePositionOrigin.height;
}
final result = await channel.invokeMethod<String>('shareFiles', params) ??
'dev.fluttercommunity.plus/share/unavailable';
return ShareResult(result, _statusFromResult(result));
}