FlutterFlow Docs
Search…
Database
The Database action allows you to create, update or delete a record from a Firestore Collection.
Creating, updating, and deleting a Todo item

Prerequisites

Before getting started with this section:

Types of Database action

There are three types of actions you can perform on a Firestore document.
  1. 1.
    ​Create Document: Creates a new record inside the specified Firestore Collection.
  2. 2.
    ​Update Document: Updates the specified field value of the existing document.
  3. 3.
    ​Delete Document: Deletes record inside the specified Firestore Collection.

1. Defining Create Document action

Go to your project page on FlutterFlow and follow the steps below to define the Action to any widget.
  • Select the Widget (e.g. Button) on which you want to define the action.
  • Select Actions from the Properties panel (the right menu), and click Open. This will open an Action flow Editor in a new popup window.
    • Click on + Add Action.
    • On the right side, search and select the Database action and then select Create Record.
    • Set the Collection to your collection name (e.g. todo).
    • Under the Set Fields section, click on the + Field button.
    • Click on the Field name.
      • Scroll down to find the Value Source dropdown and change it to From Variable.
      • Find the Source dropdown and change it to Widget State.
      • Find the Available Options dropdown and set it to the Name of the TextField.
    • Similarly, add the field for the other UI elements such as description and date.
Defining Create Document Action
Now, when a user taps the Add button when running the app, it will create a document in a collection.
Adding record

2. Defining Update Document action

Go to your project page on FlutterFlow and follow the steps below to define the Action to any widget.
  • Select the Widget (e.g. Button) on which you want to define the action.
  • Select Actions from the Properties panel (the right menu), and click Open. This will open an Action flow Editor in a new popup window.
    • Click on + Add Action.
    • On the right side, search and select the Database -> Update Record action.
    • Set the Source to the Parameter Name that holds the record.
    • Set the Available Options to reference.
    • Under the Set Fields section, click on the + Add Field button.
    • Click on the Field name.
      • Scroll down to find the Value Source dropdown and change it to From Variable.
      • Find the Source dropdown and change it to Widget State.
      • Find the Available Options dropdown and set it to the Name of the TextField.
    • Similarly, add the field for the other UI elements such as description and date.
Defining Update Document action
The following visual demonstrates updating the record:
Updating record

3. Defining Delete Document action

Go to your project page on FlutterFlow and follow the steps below to define the Action to any widget.
  • Select the Widget (e.g. Button) on which you want to define the action.
  • Select Actions from the Properties panel (the right menu), and click Open. This will open an Action flow Editor in a new popup window.
    • Click on + Add Action.
    • On the right side, search and select the Database -> Delete Record action.
    • Set the Source to the [collection] Record (from ListView).
    • Set the Available Options to reference.
    • Click Close.
Defining Delete Document action
The following visual demonstrates deleting the record:
Deleting record

References

FlutterFlow uses the cloud_firestore package to interact with the Firestore Database, to know more about how the CRUD operations are performed using this package check out their Docs.
If you want to navigate to a different page of the app once a backend call action completes, use the Navigate action. Check out this page to know how to add multiple actions.
Copy link
On this page
Types of Database action
1. Defining Create Document action
2. Defining Update Document action
3. Defining Delete Document action
References