sendSMS static method
Gửi SMS
Implementation
static Future<bool> sendSMS(
String phoneNumber, {
String? message,
BuildContext? context,
}) async {
try {
final cleanNumber = _cleanPhoneNumber(phoneNumber);
if (cleanNumber.isEmpty) {
if (context != null && context.mounted) {
_showError(context, 'Số điện thoại không hợp lệ');
}
return false;
}
String smsUri = 'sms:$cleanNumber';
if (message != null && message.isNotEmpty) {
smsUri += '?body=${Uri.encodeComponent(message)}';
}
final uri = Uri.parse(smsUri);
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
return true;
} else {
if (context != null && context.mounted) {
_showError(context, 'Không thể gửi SMS');
}
return false;
}
} catch (e) {
if (context != null && context.mounted) {
_showError(context, 'Lỗi: $e');
}
return false;
}
}