withConverter<U extends Object?> method

Query<U> withConverter<U extends Object?>({
  1. required FromFirestore<U> fromFirestore,
  2. required ToFirestore<U> toFirestore,
})

Returns a query that converts documents with fromFirestore and toFirestore (type U). Filters, ordering and limits are kept. Use withoutConverter to go back to raw maps.

The filters still compare the raw stored fields, not the converted objects.

final Query<String> names = firestore
    .collection('cities')
    .withConverter<String>(
      fromFirestore: (snapshot, options) => snapshot['name'] as String,
      toFirestore: (name, options) => {'name': name},
    );
final QuerySnapshot<String> snapshot = await names.get();
print(snapshot.docs.map((doc) => doc.data()).toList());

Implementation

Query<U> withConverter<U extends Object?>({
  required FromFirestore<U> fromFirestore,
  required ToFirestore<U> toFirestore,
}) {
  return Query<U>._(
    query,
    firestore,
    FirestoreDataConverter<U>.from(
      fromFirestore: fromFirestore,
      toFirestore: toFirestore,
    ),
  );
}