futureWithSearch method

Future<List<T>> futureWithSearch({
  1. required String searchField,
  2. required String search,
})

Future that resolves to documents filtered by a single field.

Returns a Future that resolves to documents matching the specified field value. More efficient than fetching all documents and filtering locally.

Usage

final activeUsers = await userCollection.futureWithSearch(
  searchField: 'isActive',
  search: true,
);
print('Found ${activeUsers.length} active users');

Performance

  • Creates a Firestore query with a where clause
  • More efficient than local filtering
  • Consider adding indexes for frequently searched fields

Implementation

Future<List<T>> futureWithSearch({required String searchField,required String search}) async {
  final QuerySnapshot snapshots = await _getCollection.where(searchField,isEqualTo: search).limit(limit).get();
  return _snapshots(snapshots);
}