searchContacts method
Searches for contacts matching the given query.
query
- The search term to match against contact names.
withProperties
- Include phone numbers, emails, etc.
sorted
- Sort results alphabetically.
Implementation
@override
Future<List<Contact>> searchContacts(
String query, {
bool withProperties = false,
bool sorted = true,
}) async {
try {
final result = await methodChannel.invokeMethod<List<dynamic>>(
'searchContacts',
{
'query': query,
'withProperties': withProperties,
'sorted': sorted,
},
);
return result
?.map<Contact>(
(dynamic item) => Contact.fromJson(_safeMapCast(item)),
)
.toList() ??
<Contact>[];
} on PlatformException catch (e) {
throw Exception('Failed to search contacts: ${e.message}');
}
}