withConverter<R> method
Query<R>
withConverter<R>({
- FromFirestore<
R> ? fromFirestore, - 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
_i2.Query<R> withConverter<R>({_i2.FromFirestore<R>? fromFirestore, _i2.ToFirestore<R>? toFirestore}) =>
(super.noSuchMethod(Invocation.method(#withConverter, [], {#fromFirestore: fromFirestore, #toFirestore: toFirestore}),
returnValue: _FakeQuery<R>()) as _i2.Query<R>);