Home > Mobile >  Assertion failed: field is String||field is FieldPath||field==FieldPath.documentId "Supported [
Assertion failed: field is String||field is FieldPath||field==FieldPath.documentId "Supported [

Time:06-17

I am trying to read from my firestore database. I am getting this error:

Error: Assertion failed: file:///C:/Users/Desktop/flutter/.pub-cache/hosted/pub.dartlang.org/cloud_firestore-3.1.14/lib/src/query.dart:311:7
field is String || field is FieldPath || field == FieldPath.documentId
"Supported [field] types are [String] and [FieldPath]."

This is the method ran when trying to read the database:

Future ReadUserinDatabase(String email) async {
  DatabaseUser Users = FirebaseFirestore.instance
      .collection('Users')
      .where('Email' == email) as DatabaseUser;

  print(Users.UID);
}

The DatabaseUser class:

class DatabaseUser {
  final String CustomerID;
  final String Email;
  final String Role;
  final String Activity;
  final String UID;

  DatabaseUser(
      {required this.Email,
      required this.CustomerID,
      required this.Role,
      required this.Activity,
      required this.UID});

  Map<String, dynamic> toJson() => {
        'CustomerID': CustomerID,
        'Email': Email,
        'Role': Role,
        'Activity': Activity,
        'UID': UID
      };

  static DatabaseUser fromJson(Map<String, dynamic> json) => DatabaseUser(
      Email: json['Email'],
      CustomerID: json['CustomerID'],
      Role: json['Role'],
      Activity: json['Activity'],
      UID: json['UID']);
}

I need to keep the user to pass the Role and UID so I can display specific things depending on their Role when they log in. Please Help!

CodePudding user response:

You cannot use == inside the where() method, instead use isEqualTo

Future ReadUserinDatabase(String email) async {
  DatabaseUser Users = FirebaseFirestore.instance
      .collection('Users')
      .where('Email', isEqualTo:  email) as DatabaseUser;

  print(Users.UID);
}

  • Related