FlutterFlow Docs
Search…
⌃K

CheckboxGroup

The CheckboxGroup widget is used to allow a user to select multiple items. The checkbox is displayed before the item name, which you can check/uncheck to make/remove the selection.
You can use the CheckboxGroup widget for implementing multiple selections such as repeating days for alarm, languages a user can speak, and allowing users to select pizza toppings.
CheckboxGroup

Adding CheckboxGroup

Here's an example of how you can use the CheckboxGroup widget in your project:
  • First, add the CheckboxGroup widget from the Form Elements tab or add it directly from the widget tree.
  • By default, the CheckboxGroup widget adds a single option named Option 1. To change the name, move to the properties panel (on the right side of your screen), and scroll down to the Define Options section. Find the Option 1 property and change the name.
  • To add more options, move to the properties panel, and scroll down to the Define Options section.
    • Click on the Add Option text.
    • Enter the name in Option 2 Text.
  • To remove the option, click on the cancel icon (
    ) displayed in the Option name property.
  • Click on the Set from Variable to show the options from a variable such as local state variable, API response variable, or Firestore Document.
Adding CheckboxGroup

Setting initial selection

Sometimes you might want to display the CheckboxGroup with some options already selected. For example, selecting the topping options that are already served with Pizza itself. You can do so by setting the initial selection for the CheckboxGroup.
If no options are selected, FlutterFlow selects the first options in the UI builder and leaves all the checkboxes unselected when you run the app.
Initially selected options
Based on your app, you might want to set the initial selection manually (i.e. manually entering the option name) or from variables such as local state variable, API response variable, or Firestore Document).

Setting initial selection manually

To set initial selection manually:
  • Select the CheckboxGroup from the widget tree or the canvas area.
  • Move to the properties panel (on the right side of your screen) and scroll down to the Initially Selected section.
  • Click on the Add Selected and enter the option name that you would like to display as selected. Note: Make sure you enter the correct name and it matches with the option name added inside the define options section.
  • Similarly, you can display the other option(s) as selected.
Setting the initial selection manually

Setting initial selection from variable

Let's see an example of setting the initial pizza toppings options using the local state variable.
First, create the local state variable with String datatype and mark it as List (i.e. List <String>), which looks like the below. To do so, find the instructions here.
To set the Initial options from Firestore Data, please follow the instructions here.
Local state variable
To set initial selection from local state variable:
  • Select the CheckboxGroup from the widget tree or the canvas area.
  • Move to the properties panel (on the right side of your screen) and scroll down to the Initially Selected section.
  • Click on the Set from Variable. This will open a new panel.
  • Set the Source to Local State.
  • Set the Available Options to the name of the variable.
  • Click Confirm.
Setting initial selection from variable

Showing initial options from Firestore Data

You may be using the Firstore to store your app data in the collection-document model. Let's see an example of showing the Repeat value of the Todo item inside the CheckboxGroup from the Firestore data.
Showing initial options from Firestore Data

1. Prerequisites

Before we fetch data from Firestore, ensure you incorporate all the prerequisites to have some data in Firestore.
A record/document inside the Todos collection should look similar to the following:
Sample todo document

2. Querying a single document

Querying a single document on a page helps you retrieve the document data that might contain the values to display on CheckboxGroup.
To query a single document on page:
  • Select a page.
  • Click on the Backend Query tab (on the right side of your screen).
  • Set the Query Type to Query Collection.
  • Please scroll down to find the Collection dropdown and change it to your collection.
  • Set the Query Type to Single Documents.
  • Click on the + Filter to find the exact document/record.
  • Find the Field Name, click the Unset, and select the field on which you would like to apply the filter.
  • Find the Relation dropdown, click on the Unset and choose the relation amongst the list.
  • Find the Value property and set it to an appropriate value.
  • Click Confirm.
Querying a single document

3. Showing selection in CheckboxGroup

To show options from document data into the CheckboxGroup:
  • Select the CheckboxGroup widget from the widget tree or the canvas area.
  • Move to the properties panel (on the right side of your screen) and scroll down to the Initially Selected section.
  • Click on the Set from Variable. This will open a new panel.
    • Find the Source dropdown, click on unset and select the [collection] Record (from PageName).
    • Under the Available Options, click on Unset and select the field that holds the options to be displayed inside the CheckboxGroup.
    • Click Confirm.
Showing selection in CheckboxGroup

Saving selection to Firestore Document

You would probably use the CheckboxGroup inside the Form and save its selection to your backend database when the form is submitted.
Let's see an example of saving the CheckboxGroup selection inside the Firestore document.
Saving selection to Firestore Document

1. Prerequisites

To save the CheckboxGroup selection inside the Firestore document, make sure you incorporate all the mentioned prerequisites.
To store the list of selected options, the collection schema must contain a field with String datatype and it must be a List (i.e. List<String>).
Collection schema

2. Passing selection into the document field

You can pass the CheckboxGroup selection inside the document field by adding the action that creates or updates the document, such as Create Document or Update Document.
Here are the steps in detail:
  • Select the Widget (e.g. Button) on which you want to add 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 the + Add Action.
    • On the right side, search and select Create Document or Update Document.
    • If you select Create Document.
      • Set the Collection to your collection name (e.g. todo).
    • If you select Update Document, set the document reference to update.
      • If you have access to the document, set the Source to the actual document and Available Options to reference.
    • Under the Set Fields section, click on the + Field button.
    • Click on the Field name until you see the fields that store the CheckboxGroup selection.
      • Set the List Update Type to Set Value.
      • Set the Source to Widget State.
      • Set the Available Options to CheckboxGroup.
    • Similarly, add the field for the other UI elements.
Passing selection into the document field

Clear/Select all items

You might want to allow users to clear or select all items in one go. You can do so by adding the following action.

Customization

You can use the Properties Panel to customize the appearance of your widget.

Set padding around the checkbox

To create empty space around the checkbox:
  • Select the CheckboxGroup from the widget tree or the canvas area.
  • Move to the properties panel and find the Item Padding property.
  • Set the padding for the L(Left), T(Top), R(Right), and B(Bottom) sides. Use the
    Lock button to change all values at the same time. Unlocking will allow you to modify each value separately.
Set padding around the checkbox

Changing checkbox color

To change the checkbox color:
  • Select the CheckboxGroup from the widget tree or the canvas area.
  • Move to the properties panel and scroll down to the Checkbox Style section.
  • To change the active color (i.e. color when the checkbox is selected), find the Active Color property, click on the box next to the already selected color, select the color, and then click Use Color or click on Unset and enter a Hex Code directly. You can also choose the color by clicking the Palette and Simple button.
  • the Similarly you can change the check color (i.e color of the done/tickmark icon inside the checkbox).
Changing checkbox color

Customizing checkbox border

To customize the checkbox border:
  • Select the CheckboxGroup from the widget tree or the canvas area.
  • Move to the properties panel and scroll down to the Checkbox Style section.
  • To change the checkbox border color, find the Check Border Color property, click on the box next to the already selected color, select the color, and then click Use Color or click on Unset and enter a Hex Code directly. You can also choose the color by clicking the Palette and Simple button.
  • To adjust the border corner, find the Border Radius property and enter the values in the TL (Top left), TR (top right), BL (bottom left), and BR (bottom right) boxes. Use the
    Lock button to change all values at the same time. Unlocking will allow you to modify each value separately.
Customizing checkbox border

Customizing Label

To customize the label:
  • Select the CheckboxGroup from the widget tree or the canvas area.
  • Move to the properties panel and scroll down to the Label Style section.
  • To create some space around the label, find the Label Padding property and set the padding for the L(Left), T(Top), R(Right), and B(Bottom) sides. Use the
    Lock button to change all values at the same time. Unlocking will allow you to modify each value separately.
  • To change the label style, find the Label Text Style property and change the style as per instruction here.
Customizing Label

Add padding

Here are the instructions on how to add padding.

Adjust the alignment

Here are the instructions on adjusting the alignment.

Set color dynamically

See how to set a color from variable to any color property of this widget.

Trigger action on change

Show/Hide widget

Please find the instructions to show/hide the widget here.
Last modified 2mo ago