Issue
I’m getting the error The method ‘fromSnapshot’ isn’t defined for the type ‘Rx’ and I am not sure why. Here is the code for the model:
class AgentsModel {
AgentsModel.fromSnapshot(DocumentSnapshot snapshot)
: cellPhone = snapshot['cellPhone'] ?? null,
fName = snapshot['fName'] ?? null,
lName = snapshot['lName'] ?? null,
email = snapshot['email'] ?? null;
}
Here is the auth_controller code:
var agentsModel = AgentsModel().obs;
_initializeAgentsModel(String userId) async {
agentsModel.value =
await _db.collection(agentsCollection)
.doc(userId)
.get()
.then((doc) => agentsModel.fromSnapshot(doc));
}
I don’t know enough about what I am doing to know why I am getting this error but I know that agentsModel is declared with .obs on the end. The error is marked on ".fromSnapshot(doc)".
agentsModel.value will be observed since agentsModel is observable and it will contain the data passed back from .fromSnapshot(doc) so I don’t understand why this is a problem.
Does anyone have any ideas?
Solution
fromSnapshot()
is a named constructor, not a method on an object.
Therefore, replace agentsModel.fromSnapshot(doc)
with AgentsModel.fromSnapshot(doc)
Answered By – S. M. JAHANGIR
Answer Checked By – Cary Denson (FlutterFixes Admin)