You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/resources/control-flow/functions/utility-functions.md
+87Lines changed: 87 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,6 +100,10 @@ To add inline function, open the Set from Variable dialog wherever it's possible
100
100
101
101
For example, we may want to quickly calculate the discount amount of a product where the discount is 18% of the MRP of the product. The expression would be `cost - (cost * discount)`.
102
102
103
+
:::tip
104
+
Looking for more power and flexibility? Use a new [**Code Expression**](#code-expression). It’s a more advanced version of Inline Functions that lets you access FlutterFlow generated resources without passing them as arguments. You also get real-time autocomplete and inline error checking for faster, more accurate logic.
105
+
:::
106
+
103
107
**Precedence of operations**
104
108
105
109
Inline Function for math operations follow typical precedence (e.g., multiplication/division before addition/subtraction), but parentheses can change the order.
@@ -162,6 +166,74 @@ Here are some common expressions you can use for your business logic:
162
166
|`int.parse(s)`| Convert the **String** into an **integer.**|`int.parse(stringValue)`|`int`|
163
167
164
168
169
+
## Code Expression
170
+
171
+
**Code Expression** lets you write short Dart code directly in widget property fields and action flows in FlutterFlow. It’s a more powerful version of [**Inline Function**](#inline-function-code-expressions), allowing you to directly access FlutterFlow generated classes, global variables, widget properties, parameters, and more without needing to manually pass them as inputs.
172
+
173
+
Code Expressions also support real-time autocomplete, making it easy to discover available fields as you type. For example, when you type `FFAppState().`, it will suggest all available app state variables along with their types.
174
+
175
+
In addition, inline validation provides immediate feedback as you write, helping you catch syntax errors or invalid property references.
176
+
177
+
:::tip
178
+
- To explore what you can access within a code expression, refer to the [**Common Examples**](../../../ff-concepts/adding-customization/common-examples.md) page.
179
+
- Press `^ + Space` (or `Ctrl + Space`) while typing to see suggestions for what you can access in your code expression.
180
+
- You can access values inside custom structs. For example, you can use `FFAppState().localDeviceInfo.osVersion` if that field exists in your app state.
181
+
- To use code expressions better, it's helpful to understand how FlutterFlow builds your project behind the scenes. You can check the [**State Management**](../../../generated-code/state-mgmt-gen-code.md) page and other **Generated Code** sections to learn how everything is set up.
182
+
183
+
:::
184
+
185
+
Here are a couple of examples showing how to access App State and Page State within a code expression:
186
+
187
+
-**App State Access:** For example, to check if dark mode is enabled using an App State variable:
This accesses the global`enableDarkMode` boolean stored in`FFAppState`, and returns a string based on its value.
194
+
195
+
-**Page and Component State Access:** For example, to access a page or component state variable like `searchText`, you start with`_model.` and then select the variable from the autocomplete suggestions.
196
+
197
+
```jsx
198
+
_model.searchText.isEmpty ? '' : 'Searching for "${_model.searchText}"'
199
+
```
200
+
201
+
This expression checks if the `searchText`variable (defined as a page state) is empty, and returns an appropriate message. The`_model` object refers to the current page’s generated state model.
202
+
203
+
Here's an example of adding a Code Expression:
204
+
205
+
<div style={{
206
+
position: 'relative',
207
+
paddingBottom: 'calc(56.67989417989418%+41px)', // Keeps the aspect ratio and additional padding
To use a Code Expression when triggering actions in FlutterFlow (i.e., inside an Action Flow), you can use the **Execute Custom Code** action. This allows you to run a Dart expression when something happens, such as tapping a button or after a page loads.
@@ -170,3 +242,18 @@ You can also use custom functions to handle slightly more complex calculations o
170
242
:::info
171
243
Learn more about [**Custom Functions**](../../../ff-concepts/adding-customization/custom-functions.md).
172
244
:::
245
+
246
+
## FAQS
247
+
<details>
248
+
<summary>
249
+
How is a Code Expression different from an Inline Function?
250
+
</summary>
251
+
<p>
252
+
Code Expressions are a more advanced and flexible version of **Inline Functions.
253
+
254
+
With Inline Functions, you had to manually pass values as arguments. In contrast, Code Expressions let you directly reference FlutterFlow generated resources (such as `FFAppState()`, `_model`, context, and more) without needing to pass them in.
255
+
256
+
You can write any valid Dart expression in a code expression, even multi-line logic using anonymous functions. Plus, Code Expressions support real-time autocomplete and inline error validation, making it much easier to discover available variables and avoid mistakes.
0 commit comments