firebase / firebase/flutterfire

🐛 [cloud_firestore] Future collection converter

Open
#17,237 0 comments 0 reactions 0 assignees View on GitHub
Needs Attention plugin: cloud_firestore type: enhancement
Dominant language
Dart
Stars
9.3k
Forks
4.1k
Avg merge
1d 19h
Merged PRs (30d)
53

Description

## Collection converters support for `Future`

I want to request that `withConverter` supports a `Future` for its `fromFirestore` argument.

### Use case
In some cases, like mine, one entity/data object has another one embedded.

Imagine a collection `users` and a collection `events`. Documents in collection `events` have one reference to a document in `users`.

In my Flutter app, there is class `User` and a class `Event`. Class `Event` has a member `user` that holds a `User` object.
- Class `User` does have `fromFirebase` constructor and `toFirebase` method.
- Class `Event` has a `toFirebase` method but **cannot have a `fromFirebase` constructor**: instantiating an `Event` class requires not only retrieving data from `events` collection, but also awaiting to resolve a document from `users` collection once I got the document from `events` and have access to its associated `user`.

If I could use a [`Future` factory function](https://stackoverflow.com/a/59304510/2173380) to construct my `Event` object, I would be able to use `fromFirebase` and leverage type safe conversions.

Hope to have explained myself and my use case, and even though I don't think this will be implemented, I just wanted to say that it would be really useful :)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.