giorgio79
giorgio79

Reputation: 4189

How to pass a FireStore DocumentSnapshot to json_serializable fromJson?

I am trying to pass a Firebase / Firestore DocumentSnapshot to a json_serializable fromSnapshot, but having some issues. I found some sample code referenced here FireStore fromSnapshot vs fromMap for reading DocumentSnapshot? from a now defunct google codelab, but getting an error message Generative constructors can't redirect to a factory constructor. (Documentation)

Here is the sample:

  MyClass.fromSnapshot(DocumentSnapshot snapshot)
      : this.fromJson(snapshot.data, reference: snapshot.reference);

  factory MyClass.fromJson(snapshot.data as Map<String, dynamic> json) =>
      _$MyClassFromJson(json);

Any tips how to get this to work? Seemed like a simple transformation.

Upvotes: 2

Views: 150

Answers (0)

Related Questions