-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix : Resolved the Messaging and Calling Issue.
- Loading branch information
1 parent
9e517ac
commit b1e977e
Showing
9 changed files
with
123 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,53 @@ | ||
import 'package:mess_mgmt/Global/store/app_state_store.dart'; | ||
import 'package:mess_mgmt/features/auth/error%20handling/auth_error.dart'; | ||
import 'package:permission_handler/permission_handler.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
class ContactHelper { | ||
// Function to send a WhatsApp message | ||
static Future<void> sendWhatsAppMessage( | ||
String phoneNumber, String message) async { | ||
// final whatsappUrl = | ||
// "whatsapp://send?phone=$phoneNumber&text=Your Message here"; | ||
String whatsappUrl = | ||
"whatsapp://send?phone=${phoneNumber.trim()}&text=${Uri.encodeComponent(message)}"; | ||
|
||
// "whatsapp://send?phone=$phoneNumber&text=${Uri.encodeComponent(message)}"; | ||
if (await canLaunchUrl(Uri.parse(whatsappUrl))) { | ||
await launchUrl( | ||
Uri.parse(whatsappUrl), | ||
mode: LaunchMode.externalApplication, | ||
); | ||
} else { | ||
appState.authError = const AuthErrorUnknownIssue(); | ||
appState.authError = const MessageIssue(); | ||
} | ||
} | ||
|
||
// Function to send an SMS message | ||
static Future<void> sendSms(String phoneNumber, String message) async { | ||
final smsUrl = "sms:$phoneNumber?body=${Uri.encodeComponent(message)}"; | ||
if (await canLaunchUrl(Uri.parse(smsUrl))) { | ||
await launchUrl(Uri.parse(smsUrl)); | ||
} else { | ||
appState.authError = const AuthErrorUnknownIssue(); | ||
PermissionStatus status = await Permission.sms.request(); | ||
|
||
if (status.isGranted) { | ||
final smsUrl = "sms:$phoneNumber?body=${Uri.encodeComponent(message)}"; | ||
if (await canLaunchUrl(Uri.parse(smsUrl))) { | ||
await launchUrl(Uri.parse(smsUrl)); | ||
} else { | ||
appState.authError = const MessageIssue(); | ||
} | ||
} else if (status.isDenied) { | ||
} else if (status.isPermanentlyDenied) { | ||
await openAppSettings(); | ||
} | ||
} | ||
|
||
// Function to make a call | ||
static Future<void> makePhoneCall(String phoneNumber) async { | ||
final telUrl = "tel:$phoneNumber"; | ||
if (await canLaunchUrl(Uri.parse(telUrl))) { | ||
await launchUrl(Uri.parse(telUrl)); | ||
} else { | ||
appState.authError = const AuthErrorUnknownIssue(); | ||
PermissionStatus status = await Permission.phone.request(); | ||
|
||
if (status.isGranted) { | ||
final telUrl = "tel:$phoneNumber"; | ||
if (await canLaunchUrl(Uri.parse(telUrl))) { | ||
await launchUrl(Uri.parse(telUrl)); | ||
} else { | ||
appState.authError = const CallIssue(); | ||
|
||
} | ||
} else if (status.isDenied) { | ||
} else if (status.isPermanentlyDenied) { | ||
openAppSettings(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters