Skip to content

Commit ce35929

Browse files
authored
Access Variables in Config Files (#312)
* Access variables in config files * minor fixes * minor fixes * Address review comments
1 parent b1842dc commit ce35929

File tree

1 file changed

+80
-26
lines changed

1 file changed

+80
-26
lines changed

docs/ff-concepts/adding-customization/configuration-files.md

Lines changed: 80 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Here are the key configuration files you can edit:
1717

1818
- [**`AndroidManifest.xml`**](#androidmanifestxml-android) – Configures app permissions, metadata, and intent filters for Android.
1919
- [**`Info.plist`**](#infoplist-ios)– Manages iOS app settings, including permissions and configurations.
20-
- [**`Entitlements.plist`**](#entitlementsplist-ios) – Defines iOS app privileges like push notifications and Apple Pay.
20+
- [**`Entitlements.plist`**](#entitlementsplist-ios) – Defines iOS app privileges such as push notifications and Apple Pay.
2121
- [**`main.dart`**](#maindart-flutter) – The entry point of your Flutter app, where you can modify app-level logic.
2222
- [**ProGuard files**](#proguard-file-android) – Used for code shrinking and obfuscation in Android builds.
2323

2424
:::warning
2525

26-
While editing configuration files can unlock advanced functionality, it comes with risks. A small mistake (like a missing XML tag or a wrong key) can cause your app to fail compilation or crash at runtime. Incorrect changes might lead to App Store/Play Store rejections. So, it’s important to note your changes and thoroughly test your app after each edit.
26+
While editing configuration files can unlock advanced functionality, it comes with risks. A small mistake (e.g., a missing XML tag or a wrong key) can cause your app to fail compilation or crash at runtime. Incorrect changes might lead to App Store/Play Store rejections. So, it’s important to note your changes and thoroughly test your app after each edit.
2727

2828
In short, edit native code only when necessary, and do so carefully.
2929

@@ -35,7 +35,7 @@ FlutterFlow provides two main ways to modify native XML files: [**Add Individual
3535

3636
### Option 1: Add Individual Snippets
3737

38-
**Snippets** are small pieces of code that you can inject into the native files at predefined locations. Instead of opening the whole file to edit, you provide just the fragment you want to add, and FlutterFlow merges it into the file in the correct place. This is safer and easier for small additions like a permission line or a meta-data tag.
38+
**Snippets** are small pieces of code that you can inject into the native files at predefined locations. Instead of opening the whole file to edit, you provide just the fragment you want to add, and FlutterFlow merges it into the file in the correct place. This is safer and easier for small additions such as a permission line or a meta-data tag.
3939

4040
#### Snippet Placement for Android
4141

@@ -106,9 +106,7 @@ To add a snippet to native iOS files, navigate to **Custom Code** (from the left
106106

107107
:::tip
108108
- Snippet insertion isn't available for `main.dart`. Instead, you can directly modify the file using [**Manual Edit Mode**](#option-2-manual-edit-mode).
109-
- You will soon be able to use your Development [**Environment Values**](../../testing-deployment-publishing/development-environments/development-environments.md#environment-values) and [**Library Values**](../../resources/projects/libraries.md#library-values) inside snippets.
110-
111-
<!-- For more details, refer to the [**Include Variables in Native Code**](#include-variables-in-native-code) section. -->
109+
- You can also use your Development [**Environment Values**](../../testing-deployment-publishing/development-environments/development-environments.md#environment-values) and [**Library Values**](../../resources/projects/libraries.md#library-values) inside snippets. For more details, refer to the [**Include Variables in Native Code**](#include-variables-in-native-code) section.
112110
:::
113111

114112
### Option 2: Manual Edit Mode
@@ -150,36 +148,97 @@ Once unlocked, the file stays in manual editing mode until you lock it again. Re
150148
:::tip
151149

152150
- Don’t remove FlutterFlow’s existing entries unless you are sure. It’s safer to only add or modify necessary lines and leave the rest as is.
153-
- Use Manual Edit Mode for bulk or complex edits that the snippet can’t easily do, like reordering tags, removing something, or pasting in a large chunk of config. Always verify that the app still builds and runs after such edits.
154-
<!-- - You can also use your Development [**Environment Values**](../../testing-deployment-publishing/development-environments/development-environments.md#environment-values) and [**Library Values**](../../resources/projects/libraries.md#library-values) inside snippets. For more details, refer to the [**Include Variables in Native Code**](#include-variables-in-native-code) section. -->
151+
- Use Manual Edit Mode for bulk or complex edits that the snippet can’t easily do, such as reordering tags, removing something, or pasting in a large chunk of config. Always verify that the app still builds and runs after such edits.
152+
- You can also use your Development [**Environment Values**](../../testing-deployment-publishing/development-environments/development-environments.md#environment-values) and [**Library Values**](../../resources/projects/libraries.md#library-values) inside snippets. For more details, refer to the [**Include Variables in Native Code**](#include-variables-in-native-code) section.
155153
:::
156154

157-
<!-- ## Include Variables in Native Code
155+
## Include Variables in Native Code
158156

159157
When editing native files in FlutterFlow, you may need to include dynamic values, such as API keys, app configurations, or environment-specific settings. Instead of hardcoding these values directly in **`AndroidManifest.xml`**, **`Info.plist`**, or other native files, you can use FlutterFlow [**Environment Values**](../../testing-deployment-publishing/development-environments/development-environments.md#environment-values) and [**Library Values**](../../resources/projects/libraries.md#library-values) to keep your app flexible and secure.
160158

161-
FlutterFlow allows you to use placeholders in native files that get replaced with actual values during the app build process. These placeholders help in managing different environments (development, staging, production) and keeping sensitive data out of the codebase.
159+
To include a variable in a configuration file, start by creating a **file-level variable** and assigning it a value from either your **Environment Values** or **Library Values**. Then, reference this variable using a placeholder format (e.g., `{{apiToken}}`) within the configuration file. These placeholders in native files are automatically replaced with their actual values during the code generation process.
160+
161+
Here’s exactly how you do it:
162+
163+
<div style={{
164+
position: 'relative',
165+
paddingBottom: 'calc(56.67989417989418% + 41px)', // Keeps the aspect ratio and additional padding
166+
height: 0,
167+
width: '100%'}}>
168+
<iframe
169+
src="https://demo.arcade.software/srZqoYaaoVR1mCE3t8AL?embed&show_copy_link=true"
170+
title=""
171+
style={{
172+
position: 'absolute',
173+
top: 0,
174+
left: 0,
175+
width: '100%',
176+
height: '100%',
177+
colorScheme: 'light'
178+
}}
179+
frameborder="0"
180+
loading="lazy"
181+
webkitAllowFullScreen
182+
mozAllowFullScreen
183+
allowFullScreen
184+
allow="clipboard-write">
185+
</iframe>
186+
</div>
187+
<p></p>
188+
189+
190+
You can also directly insert a variable placeholder (e.g., `{{variableName}}`) into the code using a snippet or manual edit mode and FlutterFlow automatically creates the corresponding file-level variable.
191+
192+
193+
<div style={{
194+
position: 'relative',
195+
paddingBottom: 'calc(56.67989417989418% + 41px)', // Keeps the aspect ratio and additional padding
196+
height: 0,
197+
width: '100%'}}>
198+
<iframe
199+
src="https://demo.arcade.software/szmDUd7g9ZqX9OoNJVws?embed&show_copy_link=true"
200+
title=""
201+
style={{
202+
position: 'absolute',
203+
top: 0,
204+
left: 0,
205+
width: '100%',
206+
height: '100%',
207+
colorScheme: 'light'
208+
}}
209+
frameborder="0"
210+
loading="lazy"
211+
webkitAllowFullScreen
212+
mozAllowFullScreen
213+
allowFullScreen
214+
allow="clipboard-write">
215+
</iframe>
216+
</div>
217+
<p></p>
218+
219+
220+
:::tip
221+
You can use the file level variable across different snippets within the same file.
222+
:::
162223

163224
Here are some examples that utilize variables in native code:
164225

165226
**Example 1: Using API Keys in `AndroidManifest.xml`**
166227

167-
Let’s say you are integrating the Mapbox package in your FlutterFlow app, and it requires an API Key in the form of a token inside the `AndroidManifest.xml` file. Instead of hardcoding the token, you can use an environment variable like this:
228+
Let’s say you are integrating the Mapbox package in your FlutterFlow app, and it requires an API Key in the form of a token inside the `AndroidManifest.xml` file. Instead of hardcoding the token, you can use a variable like this:
168229

169230
```xml
170231
<meta-data
171232
android:name="com.mapbox.token"
172233
android:value="{{MAPBOX_ACCESS_TOKEN}}"/>
173234
```
174235

175-
Here, `{{MAPBOX_ACCESS_TOKEN}}` is an Environment Values that FlutterFlow replaces with the actual token at build time.
176-
177-
![variables-in-native-code-example-1](imgs/variables-in-native-code-example-1.avif) -->
236+
Here, `{{MAPBOX_ACCESS_TOKEN}}` is a file level variable that holds the Environment Value.
178237

179238

180-
<!-- **Example 2: Configuring `Info.plist` for iOS**
239+
**Example 2: Configuring `Info.plist` for iOS**
181240

182-
For iOS apps, you might need to configure App Transport Security (ATS) to allow non-HTTPS connections. Instead of manually setting `NSAllowsArbitraryLoads` to `true`, you can use a FlutterFlow variable:
241+
For iOS apps, you might need to configure App Transport Security (ATS) to allow non-HTTPS connections. Instead of manually setting `NSAllowsArbitraryLoads` to `true`, you can use a variable:
183242

184243
```xml
185244
<key>NSAllowsArbitraryLoads</key>
@@ -188,14 +247,12 @@ For iOS apps, you might need to configure App Transport Security (ATS) to allow
188247

189248
If `ALLOW_HTTP_TRAFFIC` is set to `true` in FlutterFlow’s Environment Value, the app will allow HTTP connections.
190249

191-
![variables-in-native-code-example-2](imgs/variables-in-native-code-example-2.avif)
192-
193250

194251
**Example 3: Using Library Values**
195252

196253
If you are building a [FlutterFlow Library](../../resources/projects/libraries.md) and need to include API keys in native code without exposing them when users import the library, you can use [Library Values](../../resources/projects/libraries.md#library-values) as placeholders. This ensures that when someone installs your library, they can define their own values without seeing the actual key or credentials inside the native files.
197254

198-
For example, If your library requires an API key for a third-party service (e.g., Google Maps or Payment Solution), you don’t want to expose it directly in the manifest file. Instead, use a Library Value like this:
255+
For example, if your library requires an API key for a third-party service (e.g., Google Maps or a payment provider), it’s best not to expose the key directly in the manifest file. Instead, create a file-level variable and assign it a Library Value.
199256

200257
```
201258
<application>
@@ -207,9 +264,6 @@ For example, If your library requires an API key for a third-party service (e.g.
207264

208265
The library user will define their own API key under Library Values when importing your library. At build time, FlutterFlow replaces `{{MAPS_API_KEY}}` with the user-defined key.
209266

210-
![lib-values-in-native-code-example-1](imgs/lib-values-in-native-code-example-1.avif) -->
211-
212-
213267
## Editable Files
214268

215269
FlutterFlow allows editing several key native files. Below, we cover each file’s role, why you might need to edit it, and examples of real-world use cases.
@@ -218,7 +272,7 @@ FlutterFlow allows editing several key native files. Below, we cover each file
218272

219273
`AndroidManifest.xml` is the master configuration file for your Android app. It is located in the root directory of the app's `android/app/src/main` folder and declares essential app information to the Android OS and Google Play. This includes your app’s package name, components (activities, services, receivers), and the permissions it needs.
220274

221-
It defines hardware and software features the app depends on, like Bluetooth, GPS, or sensors. The manifest manages intents and filters, determining how the app responds to system events and deep linking. It also includes metadata and configuration for SDKs and libraries, such as API keys or feature flags.
275+
It defines hardware and software features the app depends on, such as Bluetooth, GPS, or sensors. The manifest manages intents and filters, determining how the app responds to system events and deep linking. It also includes metadata and configuration for SDKs and libraries, such as API keys or feature flags.
222276

223277
In short, the manifest is like an app’s identity card and permission sheet for Android.
224278

@@ -248,7 +302,7 @@ This registers `NewScreenActivity` so the system knows it exists.
248302

249303
**Example 2: Requesting Permissions**
250304

251-
If your app requires access to restricted resources like wake locks (to keep the device awake) or audio recording, you must declare the necessary permissions in `AndroidManifest.xml` by [manually editing](#option-2-manual-edit-mode) the file. **Tip:** You can also add custom permissions directly through the [**Permission Settings**](../../resources/projects/settings/project-setup.md#adding-custom-permission) in FlutterFlow.
305+
If your app requires access to restricted resources such as wake locks (to keep the device awake) or audio recording, you must declare the necessary permissions in `AndroidManifest.xml` by [manually editing](#option-2-manual-edit-mode) the file. **Tip:** You can also add custom permissions directly through the [**Permission Settings**](../../resources/projects/settings/project-setup.md#adding-custom-permission) in FlutterFlow.
252306

253307
```xml
254308
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
@@ -345,7 +399,7 @@ You can modify the `AndroidManifest.xml` file by either [**adding a snippet**](#
345399

346400
`Info.plist` (Information Property List) is the configuration file for iOS apps. It’s a structured XML file that provides iOS with essential information about your app’s configuration and requirements.
347401

348-
The `Info.plist`defines things like your app’s bundle identifier, display name, version, and most importantly, usage descriptions for permissions and other settings iOS needs at runtime. The file is required for every iOS app and is located in the project’s `/ios/Runner/` directory of your FlutterFlow apps.
402+
The `Info.plist`defines things such as your app’s bundle identifier, display name, version, and most importantly, usage descriptions for permissions and other settings iOS needs at runtime. The file is required for every iOS app and is located in the project’s `/ios/Runner/` directory of your FlutterFlow apps.
349403

350404
Essentially, it’s the blueprint for iOS to understand your app’s capabilities and needs.
351405

@@ -669,7 +723,7 @@ This ensures reflection-based code continues working.
669723
- **Testing on Devices:** Especially for anything related to `Info.plist` or entitlements, always test on a real iOS device if possible. Some issues (like missing entitlements or background mode usage) won’t show up in the simulator. Similarly, test Android changes on a device or emulator with a release build – because ProGuard rules effects, for example, only show in release mode.
670724
- **Monitoring Logs and Errors:** After making changes, monitor the Xcode console or Android logcat when running the app. If there are misconfigurations, you often get warnings.
671725
- **Stay Updated:** FlutterFlow may improve native editing features over time. Keep an eye on FlutterFlow’s docs or community announcements. If they introduce a new easier way, prefer that to manual editing when possible, as it will be more foolproof.
672-
- **Security Consideration:** Remember that anything in these files (especially `Info.plist`, `AndroidManifest.xml`) is essentially public in the distributed app. Don’t assume an API key in `Info.plist` is hidden – it’s not. For keys you must include (maps, etc.), you'll soon be able to securely manage them using [private environment values](../../testing-deployment-publishing/development-environments/development-environments.md#private-environment-values) and easily monitor their usage.
726+
- **Security Consideration:** Remember that anything in these files (especially `Info.plist`, `AndroidManifest.xml`) is essentially public in the distributed app. Don’t assume an API key in `Info.plist` is hidden – it’s not. For keys you must include (maps, etc.), consider using [private environment values](../../testing-deployment-publishing/development-environments/development-environments.md#private-environment-values) and monitoring their usage.
673727

674728
## FAQs
675729

0 commit comments

Comments
 (0)