withConverter<R> abstract method

Query<R> withConverter<R>({
  1. required FromFirestore<R> fromFirestore,
  2. required ToFirestore<R> toFirestore,
})

Transforms a Query to manipulate a custom object instead of a Map<String, dynamic>.

This makes both read and write operations type-safe.

final personsRef = FirebaseFirestore
    .instance
    .collection('persons')
    .where('age', isGreaterThan: 0)
    .withConverter<Person>(
      fromFirestore: (snapshot, _) => Person.fromJson(snapshot.data()!),
      toFirestore: (person, _) => person.toJson(),
    );

Future<void> main() async {
  List<QuerySnapshot<Person>> persons = await personsRef.get().then((s) => s.docs);
}

Implementation

Query<R> withConverter<R>({
  required FromFirestore<R> fromFirestore,
  required ToFirestore<R> toFirestore,
});