saveToContacts static method
Future<bool>
saveToContacts(
- String phoneNumber, {
- String? name,
- String? email,
- BuildContext? context,
Lưu số vào danh bạ (mở form thêm contact mới)
Implementation
static Future<bool> saveToContacts(
String phoneNumber, {
String? name,
String? email,
BuildContext? context,
}) async {
try {
final cleanNumber = _cleanPhoneNumber(phoneNumber);
// Create vCard format
if (name != null && name.isNotEmpty) {}
if (email != null && email.isNotEmpty) {}
// Try to open contacts with intent (Android specific)
// This may not work on all devices/platforms
if (context != null && context.mounted) {
_showInfo(
context,
'Số điện thoại: $cleanNumber${name != null ? "\nTên: $name" : ""}',
);
}
return true;
} catch (e) {
if (context != null && context.mounted) {
_showError(context, 'Lỗi: $e');
}
return false;
}
}