shareFile method
Shares a local file with whatsapp.
- Text: Is the
text
of the message. - FilePath: Is the List of paths which can be prefilled.
- Phone: is the
phone
contact number to share with.
Implementation
Future<bool?> shareFile({
required List<String> filePath,
required String phone,
@Deprecated("No support for text along with files, this field is ignored")
String? text,
Package package = Package.whatsapp,
}) async {
assert(filePath.isNotEmpty);
assert(phone.isNotEmpty);
if (filePath.isEmpty) {
throw FlutterError('FilePath cannot be Empty');
} else if (phone.isEmpty) {
throw FlutterError('Phone cannot be Empty');
}
String _package;
_package = package.index == 0 ? "com.whatsapp" : "com.whatsapp.w4b";
final bool? success = await methodChannel
.invokeMethod('shareFile', <String, dynamic>{
'title': ' ',
'text': ' ',
'filePath': filePath,
'chooserTitle': ' ',
'phone': phone,
'package': _package,
});
return success;
}