Skip to content

Commit e88b536

Browse files
Generated Code update: secure keys (#283)
* add secure storage initial info * add flutter secure storage info * add private env value info. * Add private cloud func diagram * fix references --------- Co-authored-by: pinkeshmars <[email protected]>
1 parent 9a5e107 commit e88b536

File tree

13 files changed

+76
-31
lines changed

13 files changed

+76
-31
lines changed

docs/generated-code/component-gen-code.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: Components
2+
title: Component Model
33
slug: /generated-code/component-model
4-
sidebar_position: 6
4+
sidebar_position: 5
55
---
66

77
# Generated Code: Components

docs/generated-code/ff-app-state.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: FFAppState
3-
sidebar_position: 2
3+
sidebar_position: 4
44
---
55

66
# FFAppState

docs/generated-code/pages-generated-code.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Pages
2+
title: Page Model
33
slug: /generated-code/page-model
44
sidebar_position: 5
55
---

docs/ff-concepts/state-management/generated-code.md renamed to docs/generated-code/state-mgmt-gen-code.md

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
---
2-
slug: /concepts/state-management/generated-code
3-
title: Generated Code
2+
slug: /generated-code/state-management
3+
title: FlutterFlow State Management
44
description: Learn about the state management used in FlutterFlow's generated code.
55
tags: [Generated Code, Concepts, State Management]
6-
toc_max_heading_level: 5
7-
sidebar_position: 2
6+
toc_max_heading_level: 4
7+
sidebar_position: 3
88
keywords: [FlutterFlow, Generated Code, State Management, Concepts]
99
---
1010

11-
# State Management
11+
# FlutterFlow State Management
12+
13+
:::warning[Correct topic?]
14+
This document explains the generated code behind the state management approaches used in FlutterFlow. If you're looking for guidance on adding state variables in FlutterFlow, refer to the **[State Variables](../ff-concepts/state-management/state-variables.md)** documentation.
15+
:::
1216

1317
FlutterFlow manages state in several ways, depending on the scope.
1418

15-
Generally, state management is handled using the Provider package, which facilitates the provisioning of data models for components, pages, and the overall app state.
19+
Generally, state management is handled using the [Provider](https://pub.dev/packages/provider) package, which facilitates the provisioning of data models for components, pages, and the overall app state.
1620

17-
![state-management.avif](../../../static/img/state-management.avif)
21+
![state-management.avif](../../static/img/state-management.avif)
1822

1923
## Page & Component Models
2024

@@ -24,13 +28,13 @@ Additionally, they provide space for action blocks, which are a set of actions t
2428

2529
## Page State
2630

27-
[Variables](../../resources/ui/pages/page-lifecycle.md) 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.
31+
[Variables](../resources/ui/pages/page-lifecycle.md) 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.
2832

2933
Variables within a page are tracked through `StatefulWidget` and are encapsulated into that page’s Model.
3034

3135
## Component State
3236

33-
Similar to page state, [**Component State variables**](../../resources/ui/components/component-lifecycle.md) 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.
37+
Similar to page state, [**Component State variables**](../resources/ui/components/component-lifecycle.md) 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.
3438

3539
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.
3640

@@ -40,6 +44,13 @@ For example, if a page includes a component with a text field and later on the p
4044

4145
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.
4246

47+
## App State
48+
49+
:::info[FFAppState]
50+
The generated code behind FlutterFlow's App State class is explained in the **[FFAppState](ff-app-state.md)** documentation.
51+
52+
:::
53+
4354
## Variables
4455

4556
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`.
@@ -50,9 +61,18 @@ On each page that requires access to app state variables, the method ```context.
5061

5162
## Persisting App State
5263

53-
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.
64+
When an app state variable is created, selecting the "Persisted" option enables FlutterFlow to save it on the device using the [**Shared Preferences**](https://pub.dev/packages/shared_preferences) package. 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.
65+
66+
If the "**Secure Persisted Fields**" option is enabled in the app state settings, FlutterFlow utilizes the [**Flutter Secure Storage**](https://pub.dev/packages/flutter_secure_storage) package to encrypt the data.
67+
68+
:::tip[Platform Differences]
69+
If the platform is **Android**, then `flutter_secure_storage` stores data in [**`encryptedSharedPreference`**](https://developer.android.com/reference/androidx/security/crypto/EncryptedSharedPreferences), which are shared preferences that encrypt keys and values. It handles [**AES Encryption**](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard) to generate a secret key encrypted with [**RSA**](https://en.wikipedia.org/wiki/RSA_(cryptosystem)) and stored in [**KeyStore**](https://developer.android.com/reference/java/security/KeyStore).
70+
71+
For the **iOS** platform, it uses the [**KeyChain**](https://developer.apple.com/documentation/security/keychain_services) which is an iOS-specific secure storage used to store and access cryptographic keys only in your app.
72+
73+
In the case of the **Web**, it uses the [**Web Cryptography**](https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API) (Web Crypto) API.
74+
:::
5475

55-
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.
5676

5777
## Global State
5878

docs/marketplace/creators-hub/submission-criteria.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ Building a solid app template goes beyond surface-level design. It's about creat
334334
- **Criteria:** Implement state management effectively to ensure data is updated and reflected correctly across your application.
335335
- **Why it Matters:** Proper state management is crucial for building responsive and dynamic Flutter apps. It helps prevent data inconsistencies, improves performance, and makes your code easier to maintain.
336336
- **What To Do:**
337-
- **Choose the right state management scope:** FlutterFlow supports (1) [App State](../../resources/data-representation/app-state.md) (2) [Page State](../../resources/ui/pages/page-lifecycle.md#page-state) and (3) [Component State](../../ff-concepts/state-management/generated-code.md#component-state) variables. Familiarize yourself with these options and scope any state variables to where they are needed. For instance, do not use App State to control the value of a checkbox within a component.
337+
- **Choose the right state management scope:** FlutterFlow supports (1) [App State](../../resources/data-representation/app-state.md) (2) [Page State](../../resources/ui/pages/page-lifecycle.md#page-state) and (3) [Component State](../../resources/ui/components/component-lifecycle.md#creating-a-component-state) variables. Familiarize yourself with these options and scope any state variables to where they are needed. For instance, do not use App State to control the value of a checkbox within a component.
338338
- **Rebuild efficiently:** Ensure changes to state rebuild only the necessary scope for efficiency.
339339

340340
#### 5.10 Organized Widget Tree

docs/resources/control-flow/backend-logic/api/create-test-api-calls.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ The PUT and PATCH API calls can be defined similarly; make sure you enter a vali
122122
You can create a group of API calls that share the same base URL. Grouping the API calls helps you add all request headers (e.g., auth token) at once, and they will be automatically added for all the API calls inside the group.
123123

124124
:::warning
125-
For [**private APIs**](rest-api.md#making-an-api-call-private), headers defined within the group will not be automatically included. You'll need to manually add headers for APIs marked as private.
125+
For [**private APIs**](rest-api.md#private-api-calls), headers defined within the group will not be automatically included. You'll need to manually add headers for APIs marked as private.
126126
:::
127127

128128
To create the API Group:
288 KB
Loading

docs/resources/control-flow/backend-logic/api/rest-api.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,16 +639,16 @@ To use a predefined JSON Path, first, select your API response. Then, set the **
639639

640640
You can make the API call private and change the proxy settings using advanced settings.
641641

642-
### Making an API call private
642+
### Private API Calls
643643

644644
Making an API call private is helpful if it uses tokens or secrets you don't want to expose in your app. Enabling this setting will route this API call securely via the Firebase Cloud Functions.
645645

646-
To make the API call private, open the **Advanced Settings** tab, turn on the **Make Private** toggle, Click **Save,** and then **Deploy APIs**.
646+
![private-cloud-func.png](imgs/private-cloud-func.png)
647647

648-
Optionally, you can force a user to be authenticated via the Firebase authentication to make this API call. To do so, turn on the **Require Authentication** toggle.
648+
To make an API Call Private, open the **Advanced Settings** tab, turn on the **Make Private** toggle, Click **Save,** and then **Deploy APIs**.
649649

650+
Optionally, you can force a user to be authenticated via the Firebase authentication to make this API call. To do so, turn on the **Require Authentication** toggle.
650651

651-
:::info
652652

653653
Private APIs are deployed as [**Cloud Functions**](https://firebase.google.com/docs/functions) within your Firebase project. While deploying, you can configure the following options:
654654

@@ -659,7 +659,7 @@ Private APIs are deployed as [**Cloud Functions**](https://firebase.google.com/d
659659

660660
**Note**: To minimize costs, you can set the **Min Instances** value to 0. For detailed pricing information, refer to the [**Cloud Functions Pricing page**](https://cloud.google.com/functions/pricing-overview).
661661

662-
:::
662+
663663

664664
<div style={{
665665
position: 'relative',

docs/resources/data-representation/app-state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ App state variables are specific variables that hold the current state of an app
1616

1717
App state variables should be used in scenarios where the same data needs to be accessed and modified from multiple locations within the app. For instance, in a shopping cart app, items in a user's cart are usually accessible across different pages.
1818

19-
App state variables should not be used for temporary data that doesn't impact the overall state of the application. For instance, a user's temporary input in a form should not be stored in an app state variable. It would be more appropriate to use a [page state](../../resources/ui/pages/page-lifecycle.md#page-state) or [component state](../../ff-concepts/state-management/generated-code.md#component-state) variable instead.
19+
App state variables should not be used for temporary data that doesn't impact the overall state of the application. For instance, a user's temporary input in a form should not be stored in an app state variable. It would be more appropriate to use a [page state](../../resources/ui/pages/page-lifecycle.md#page-state) or [component state](../../generated-code/state-mgmt-gen-code.md#component-state) variable instead.
2020

2121
## App State Variables
2222

@@ -58,7 +58,7 @@ Head over to the left-side navigation menu and follow the steps below to create
5858
- **Persisted:** Whether this app state is saved to disk so that it can be loaded when the app is restarted. Otherwise the field will be reset on restart.
5959

6060
:::tip[Generated Code]
61-
Curious about what happens when the **Persisted** toggle is on? Check out the [**Generated Code**](../../ff-concepts/state-management/generated-code.md#persisting-app-state) guide.
61+
Curious about what happens when the **Persisted** toggle is on? Check out the [**Generated Code**](../../generated-code/state-mgmt-gen-code.md#persisting-app-state) guide.
6262
:::
6363

6464

docs/resources/data-representation/global-properties.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ A list of all the available global properties is as follows:
4848
- **Current Environment**: Gives you the current [development environment](../../testing-deployment-publishing/development-environments/development-environments.md) value.
4949

5050
:::tip[Generated Code]
51-
Learn more about the [**Generated Code**](../../ff-concepts/state-management/generated-code.md#global-state) behind Global Properties.
51+
Learn more about the [**Generated Code**](../../generated-code/state-mgmt-gen-code.md#global-state) behind Global Properties.
5252
:::
5353

5454
### Current Time

0 commit comments

Comments
 (0)