share method
Implementation
@override
Future<bool> share({
WhatsApp type = WhatsApp.standard,
String? phone,
String? text,
XFile? file,
}) async {
// Desktop platforms
if (Platform.isMacOS || Platform.isWindows || Platform.isLinux) {
return await super.share(
type: type,
phone: phone,
text: text,
file: file,
);
}
// Mobile platforms
if (Platform.isAndroid || Platform.isIOS) {
String? contentType;
if (file != null) {
final bytes = await file.readAsBytes();
contentType = lookupMimeType(file.path, headerBytes: bytes.toList());
}
final shared = await methodChannel.invokeMethod<int>('share', {
'packageName': type.packageName,
'phone': phone?.removeNonNumber(),
'text': text,
'file': file?.path,
'contentType': contentType,
});
return shared == 1;
}
throw UnimplementedError('Unknown platform ${Platform.operatingSystem}');
}