Skip to content

Get Collections

Efra Espada edited this page Feb 22, 2024 · 1 revision

The get method is used to retrieve data from a collection. In this example, it's being used to fetch data from a collection named chatsCollection.

In the first option:

List<Chat> chats = await chatsCollection.get();

The get method is called directly on chatsCollection to retrieve documents from the collection. The variable chats will contain a list of chats.

In the second option:

final chats = await chatsCollection.get<Chat>();

Type inference is used to explicitly specify that the retrieved data should be of type Chat. This enhances code clarity and type safety. The variable chats will also contain a list of chats.

Both options achieve the same goal of fetching data from the chatsCollection, but the second option is more explicit in specifying the expected data type, which improves code readability and type safety.