isNameExist method

  1. @override
Future<bool> isNameExist(
  1. String collectionId, {
  2. required String value,
  3. String name = 'name',
})
override

Implementation

@override
Future<bool> isNameExist(
  String collectionId, {
  required String value,
  String name = 'name',
}) async {
  await initialize();
  logger.finest('after');
  assert(_db != null);
  CollectionReference collectionRef = _db!.collection(collectionId);
  Query<Object?> query = collectionRef.where(name, isEqualTo: value);

  QuerySnapshot<Object?> snapshot = await query.get();

  List<Map<String, dynamic>> retvalList = snapshot.docs.map((doc) {
    //logger.finest(doc.data()!.toString());
    return doc.data()! as Map<String, dynamic>;
  }).toList();

  if (retvalList.isEmpty) {
    return false;
  }
  return true;
}