makePhoneCall static method
Future<bool>
makePhoneCall(
- String phoneNumber, {
- BuildContext? context,
- bool showConfirmation = false,
Gọi điện thoại trực tiếp
Implementation
static Future<bool> makePhoneCall(
String phoneNumber, {
BuildContext? context,
bool showConfirmation = false,
}) async {
try {
// Clean phone number (remove spaces, dashes, parentheses)
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;
}
// Show confirmation dialog if needed
if (showConfirmation && context != null) {
final confirmed = await _showConfirmDialog(context, cleanNumber);
if (!confirmed) return false;
}
final uri = Uri.parse('tel:$cleanNumber');
if (await canLaunchUrl(uri)) {
await launchUrl(uri);
return true;
} else {
if (context != null && context.mounted) {
_showError(context, 'Không thể gọi số điện thoại này');
}
return false;
}
} catch (e) {
if (context != null && context.mounted) {
_showError(context, 'Lỗi: $e');
}
return false;
}
}