You can use the [deeplink_x](https://pub.dev/packages/deeplink_x) plugin to easily open deep links, including WhatsApp actions, with fallback options.
Support: **Android, iOS, MacOS, Windows**
Steps:
**1.Add deeplink_x to your pubspec.yaml**
```yaml
dependencies:
deeplink_x: ^1.0.1 # Replace with the latest version from pub.dev
```
**2. Import the package and initialize**
```dart
import 'package:deeplink_x/deeplink_x.dart';
void main() {
final deeplinkX = DeeplinkX();
// You can now use _deeplinkX to launch actions
}
```
**Share Text via WhatsApp**
```dart
final isLaunched = await deeplinkX.launchAction(
WhatsApp.shareText(
text: 'sample', // Replace with your message
fallbackToStore: false, // Optional: fallback to WhatsApp store page or web
),
);
```
**Open Chat with a Phone Number and Predefined Message**
```dart
final isLaunched = await deeplinkX.launchAction(
WhatsApp.chat(
phoneNumber: '1234567890', // Replace with a valid number
message: 'sample', // Replace with your message
fallbackToStore: false, // Optional: fallback behavior
),
);
```
**Note**
• fallbackToStore: When set to true, it will open the store if WhatsApp is not installed. If false, it will fallback to WhatsApp Web.
Present in both answers;
Present only in the new answer;
Present only in the old answer;