withConverter<R> method
Query<R>
withConverter<R>({
- required FromFirestore<
R> fromFirestore, - required ToFirestore<
R> toFirestore,
override
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
@override
Query<R> withConverter<R>({
required FromFirestore<R> fromFirestore,
required ToFirestore<R> toFirestore,
}) {
// TODO: implement withConverter
throw UnimplementedError();
}