allUsers method

Future<List<UserModel>> allUsers()

This method retrieves all user records from Firestore. @return A Future that resolves to a list of UserModel objects containing user details. @throws String if there is an error fetching the user records. @throws String if there are no user records found. @throws String if there is an error fetching the user records.

Implementation

Future<List<UserModel>> allUsers() async {
  try {
    final snapshot = await _db.collection("users").get();
    final users = snapshot.docs.map((e) => UserModel.fromSnapshot(e))
        .toList();
    return users;
  } on FirebaseAuthException catch (e) {
    final result = TExceptions.fromCode(e.code);
    throw result.message;
  } on FirebaseException catch (e) {
    throw e.message.toString();
  } catch (e) {
    debugPrint('Error: $e');
    throw 'Something went wrong. Please Try Again. Details: $e';
  }
}