whatsapp_share
Flutter 앱에서 WhatsApp로 특정 연락처에게 메시지, 링크 또는 파일을 공유하는 간단한 방법입니다.
Flutter에서 특정 WhatsApp 연락처에 텍스트, 링크, 이미지, 파일 공유하기
{"sdk":"flutter"}{"sdk":"flutter"}아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
A Flutter plugin for Android providing a simple way to share a message, link or local files to specific WhatsApp contact.
First, add this to your package's pubspec.yaml file:
dependencies:
whatsapp_share: ^1.1.1
Now in your Dart code, you can use:
import 'package:whatsapp_share/whatsapp_share.dart';
Add if not exists one row to the ios/podfile after target runner:
...
target 'Runner' do
use_frameworks!
...
If you pretends to use the file share, you need to configure the file provider, this will give access to the files turning possible to share with other applications.
Add to AndroidManifest.xml:
<application>
...
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
</provider>
</application>
Obs: You can change the android:name if you have an extension of file provider.
Add res/xml/provider_paths.xml:
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="."/>
</paths>
If you want to learn more about file provider you can access:
Here is an snippets app displaying the two whatsapp share methods .
Future<void> isInstalled() async {
final val = await WhatsappShare.isInstalled(
package: Package.businessWhatsapp
);
print('Whatsapp Business is installed: $val');
}
If whatsapp is not installed, please do not call WhatsappShare.share() and WhatsappShare.shareFile()
Future<void> share() async {
await WhatsappShare.share(
text: 'Whatsapp share text',
linkUrl: 'https://flutter.dev/',
phone: '911234567890',
);
}
_image1.path contains path of the file which is shared to the whatsapp.
Future<void> shareFile() async {
await WhatsappShare.shareFile(
phone: '911234567890',
filePath: [_image1.path, _image2.path],
);
}