FlutterFlow Docs
Search…
Document from Reference
This backend query would help you in retrieving information from a document reference. You will require the Document from Reference query if you have passed a document reference to a different page of the app and want to retrieve the actual document information from the reference.

Prerequisites

In order to use this backend query, you should have:
  • Completed all the steps of Firebase Setup for your project.
  • At least one Firestore Collection defined in your project.

Defining the Query

Go to your project page on FlutterFlow and follow the steps below to define a Document from Reference backend query:
  1. 1.
    Select the widget (or page) on which to apply the query.
  2. 2.
    Select Backend Query from the Properties panel (the right menu).
  3. 3.
    Select the Query Type as Document from Reference.
  4. 4.
    Choose a Collection from the dropdown to which the document reference belongs.
  5. 5.
    Select the Source as the record reference name.
Defining Document from Reference Backend Query (RobinDo app template)

Using Query Data

The document information retrieved from the backend query can now be set on the widgets present inside. Follow the steps below:
  1. 1.
    Select the widget (eg, Text) on which you want to set the record data.
  2. 2.
    From the Properties Panel, select Set from Variable.
  3. 3.
    Choose the Source as the record variable.
  4. 4.
    Under Available Options, select a field name.
  5. 5.
    You can also specify a Default Value (it is used if the record field is empty).
  6. 6.
    Click Save.
You can follow similar steps for using the record data on the other widgets as well.
Setting Query data to the Text widgets (RobinDo app template)

Code Overview

You can view the code that is generated by FlutterFlow in the background by going to the Developer Menu > View Code from the Tool Bar.
NOTE: This section is for users who might want to make some additional modifications to the generated code, or want to understand the code that is generated by FlutterFlow behind the scenes.
On adding the Document from Reference Backend Query, a code similar to the following will be generated:
1
StreamBuilder<ToDoListRecord>(
2
stream: ToDoListRecord.getDocument(widget.toDoNote),
3
builder: (context, snapshot) {
4
if (!snapshot.hasData) {
5
// widget to show while retrieving data
6
return Container();
7
}
8
final taskDetailsToDoListRecord = snapshot.data;
9
// return widget where record data can be used
10
return Scaffold();
11
}
12
)
Copied!
  • ​StreamBuilder helps in rebuilding the widget present inside it with the latest data. That means, whenever the document gets updated on the Firestore Collection it would reflect in the app automatically without any user interaction.
  • Here, stream is used to listen to any changes in the document, getDocument() method is used on the record to retrieve data.
  • builder is used to return a widget, snapshot.hasData can be used to verify whether the retrieving process is complete, and snapshot.data is used to retrieve the document information.

Reference

  • You can learn more about DocumentSnapshot from here.
  • FlutterFlow app templates using Document from Reference query: RobinDo, GeekChat, and many more.