existingCollection method
Returns a typed handle for a Firestore collection that already exists in the target project.
Unlike collection, this does not create a new collection. The handle resolves against existing project metadata during compilation. If the collection does not exist in the target project, compilation fails with a targeted error.
The optional fields parameter declares the expected schema. If omitted,
the handle uses whatever schema the existing collection already has.
final trips = app.existingCollection('trips');
app.editPageState('MyTrips', (state) {
state.ensureField('tripsList', listOf(trips));
});
Implementation
FirestoreCollectionHandle existingCollection(
String name, {
Map<String, DslType>? fields,
}) {
recordExistingReference(
name: name,
kind: 'collection',
referenceApi: 'existingCollection',
removeApi: 'removeCollection',
);
final handle = FirestoreCollectionHandle(
name,
fields ?? const <String, DslType>{},
description: 'Existing collection $name',
);
_existingCollectionRefs.add(handle);
return handle;
}