Skip to content

Commit 4ac6380

Browse files
committed
Merge branch 'main' of https://github.com/FlutterFlow/flutterflow-documentation into pinkesh/ff-ui
2 parents ca72af2 + 007a54b commit 4ac6380

25 files changed

+802
-120
lines changed

.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Place your StackBlitz environment variables here,
2+
# and they will be securely synced to your account.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"label": "State Management",
3+
"position": 1
4+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
slug: generated-code
3+
title: Generated Code
4+
tags: []
5+
toc_max_heading_level: 5
6+
sidebar_position: 5
7+
---
8+
# State Management
9+
10+
FlutterFlow manages state in several ways, depending on the scope.
11+
12+
Generally, state management is handled using the Provider package, which facilitates the provisioning of data models for components, pages, and the overall app state.
13+
14+
![state-management.avif](..%2F..%2F..%2Fstatic%2Fimg%2Fstate-management.avif)
15+
16+
## Page & Component Models
17+
18+
In FlutterFlow, both component widget models and page models share a uniform structure, enhancing consistency throughout the framework. They include local state fields to store data specific to the component, such as sizes or user inputs. These models are also equipped with initialization and disposal methods: `initState` for setup when the widget initializes, and `dispose` for resource cleanup when the widget is no longer needed.
19+
20+
Additionally, they provide space for action blocks, which are a set of actions that performs a specific task and can be reused in different parts of the app, and helper methods for extra functionalities needed by the component. This consistent structure across models helps efficiently manage the state and interactions of various components within the app.
21+
22+
## Page State
23+
24+
Variables used exclusively within a page—such as a text field validator or the value of a checkbox—are stored in the Model of each page. These variables can be accessed by other component children on the same page. For instance, on a page with a form, tapping a button in one component may need to access the value of a text field in a different component.
25+
26+
Variables within a page are tracked through StatefulWidgets and are encapsulated into that page’s Model.
27+
28+
## Component State
29+
30+
Similar to page state, component variables are accessible within the component where they are defined. Each component has a corresponding Model and Widget class. Variables may be passed in from their parent as parameters. Additionally, you can access component state values from its parent Page widget.
31+
32+
This accessibility is possible because the Model of a component is instantiated within the parent Page model. It utilizes the Provider method `context.read()`, which returns any existing model in the tree before instantiating a new one. Thus, any updates to the state in the component model will reflect in the parent’s instance of that component model.
33+
34+
One of the helper methods in `flutter_flow_model.dart` is `wrapWithModel()`. This method wraps the child in a Provider model to make it accessible to the child and sets a callback function, which is generally used to call `setState()` in the parent page and update any changed values. We use this wrapper around widgets that need to access the data included in the model.
35+
36+
For example, if a page includes a component with a text field and later on the page there is a button needing access to the text field’s value, the button would be wrapped with ```wrapWithModel()```, including the text field component’s Model as a parameter.
37+
38+
It’s important to note that components cannot directly access variables of other components on the same page. However, you can pass a variable from ComponentA as a parameter to ComponentB in their parent Page. This ensures that ComponentB receives all updates from ComponentA as expected.
39+
40+
## Variables
41+
42+
Variables required across multiple pages of the app, such as a username, should be added to the App State. Refer to `lib/app_state.dart`.
43+
44+
All defined variables within the app state are components of the `FFAppState` class, which functions as a ChangeNotifier. This means listeners can subscribe and receive notifications when any changes occur.
45+
46+
On each page that requires access to app state variables, the method ```context.watch<AppState>()``` is called to initialize a listener for that page. This ```watch()``` method, provided by the Provider package, facilitates access to inherited widgets and acts as an effective wrapper.
47+
48+
## Persisting App State
49+
50+
When an app state variable is created, selecting the "Persisted" option enables FlutterFlow to save it on the device using the [shared_preferences package](https://pub.dev/packages/shared_preferences). This ensures the variable remains available even after the app is restarted, making it ideal for persisting settings such as login status or a user's choice between light and dark modes.
51+
52+
If the "Secure Persisted Fields" option is enabled in the app state settings, FlutterFlow utilizes the [flutter_secure_storage package](https://pub.dev/packages/flutter_secure_storage) to encrypt the data. This package leverages platform-specific implementations for data encryption, utilizing Keychain on iOS, KeyStore on Android, and libsecret on Linux.
53+
54+
## Global State
55+
56+
Global state variables are pieces of information related to the device that are accessible throughout the FlutterFlow app.
57+
58+
These include:
59+
60+
- Screen size
61+
- Platform (mobile, web, Android, iOS)
62+
- Keyboard visibility
63+
- Current time
64+
65+
These variables are found in the "Global Properties" section and are automatically added by FlutterFlow, not generated by users. Users can utilize App State variables for their own global use cases.
66+
67+
Global properties are retrieved through methods defined in `flutter_flow_utils.dart`. Typically, these methods utilize built-in Flutter libraries, such as `dart:io`, to gather the necessary information.
68+
69+
## Constants
70+
71+
For values that do not change throughout the app, such as API keys or environment flags, we utilize the `FFAppConstants` class, which can be found in `lib/app_constants.dart`. This is an abstract class, meaning it cannot be directly instantiated. Instead, it serves as a namespace for static constants, allowing these values to be organized and accessed consistently across the application.

docs/intro/ff-ui/builder.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ In the [Canvas Area](canvas), you can see a preview of your mobile device's scre
2424

2525
## 4. Properties Panel
2626

27-
The [Properties Panel](properties-panel) is present on the right side of the canvas. It displays all the properties you can customize for the selected widget or page.
27+
The Properties Panel lets you modify both the visual appearance and interactive behavior of UI elements on the canvas. It allows you to add Actions, set up a Backend Query, add Animations and more.
113 KB
Binary file not shown.
34.3 KB
Binary file not shown.

docs/intro/ff-ui/imgs/storyboard.avif

150 KB
Binary file not shown.
26.9 KB
Binary file not shown.

docs/intro/ff-ui/navigation-menu.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ From here, you can go to the [dashboard](#) to manage your projects. This includ
1616

1717
## 2. Widget Palette
1818

19-
The [Widget Palette](#) gives you access to all the widgets that can be added to the app.
19+
The [Widget Palette](widget-palette) gives you access to all the widgets that can be added to the app.
2020

2121
## 3. Page Selector
2222

@@ -36,7 +36,7 @@ The [Widget Tree](#) panel gives you a high-level overview of all the widgets yo
3636

3737
## 5. Storyboard
3838

39-
The [storyboard](#) helps you visualize your entire app's design and navigation in a single interface.
39+
The [storyboard](storyboard) helps you visualize your entire app's design and navigation in a single interface.
4040

4141
## 6. Firestore
4242

docs/intro/ff-ui/properties-panel.md

Lines changed: 0 additions & 102 deletions
This file was deleted.

0 commit comments

Comments
 (0)