0
votes

How can I fix this?

I want to login with id and password, but I get the following error:

E/flutter ( 985): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: 'package:cloud_firestore_platform_interface/src/platform_interface/platform_interface_document_snapshot.dart': Failed assertion: line 69 pos 12: 'field is String || field is FieldPath': Supported [field] types are [String] and [FieldPath]

adminlogin() {
FirebaseFirestore.instance.collection('Admins').get().then((snapshot) {
  snapshot.docs.forEach((result) {
    if (result.get(['id']) != AdminID_controller.text.trim()) {
      // ignore: deprecated_member_use
      Scaffold.of(context)
          .showSnackBar(SnackBar(content: Text("id is incorrect")));
    } else if (result.get(['password']) !=
        PasswordAdmin_controller.text.trim()) {
      Scaffold.of(context)
          .showSnackBar(SnackBar(content: Text("Password is incorrect")));
    } else {
      Scaffold.of(context).showSnackBar(
          SnackBar(content: Text(" welcome" + result.get(['name']))));
    }
  });
});
}
1

1 Answers

1
votes

Your problem is with this statement: result.get(['id']). The get function of the QueryDocumentSnapshot class is meant to take a String or FieldPath as the documentation states. You are passing a List instead by adding the brackets. Remove the brackets.

result.get('id')

The reason you're not getting a static analysis error is because the parameter of the get function is declared as dynamic so that it can take either a String or FieldPath object. Functions with dynamic parameters are usually done so that they can take objects of different types in the same position. Another example would be the jsonEncode function. However, it's import to pay attention to what data types the documentation states they can actually take.