Skip to content

Commit 8eb272d

Browse files
committed
add new diagrams and fix docs
1 parent 2bc96c4 commit 8eb272d

File tree

5 files changed

+55
-33
lines changed

5 files changed

+55
-33
lines changed

docs/ff-concepts/adding-customization/custom-code.md

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ This is where writing custom code comes into play.
1717
There are a few different ways to make custom code accessible in FlutterFLow:
1818

1919
* **[Custom Functions](custom-functions.md):** Custom Dart functions that can be used to set Widget or Action properties.
20-
* **[Custom Actions](custom-actions.md):** Custom Dart functions that can be triggered by [Action Triggers](https://docs.flutterflow.io/resources/functions/action-triggers/) or used as nodes in an [Action Flow](https://docs.flutterflow.io/resources/functions/action-flow-editor#action-flow-editor). These are usually `async` functions and are able to import custom package dependencies.
21-
* **[Custom Widgets](custom-widgets.md):** Custom Flutter widgets, which can be used in the same way [Components](https://docs.flutterflow.io/resources/ui/components) are used throughout your project.
20+
* **[Custom Actions](custom-actions.md):** Custom Dart functions that can be triggered by [Action Triggers](https://docs.flutterflow.io/resources/functions/action-triggers/) or used as nodes in an [Action Flow](https://docs.flutterflow.io/resources/functions/action-flow-editor#action-flow-editor). These are usually `async` functions and are able to import [custom package dependencies](#adding-a-pubspec-dependency).
21+
* **[Custom Widgets](custom-widgets.md):** Custom Flutter widgets that can also import [custom package dependencies](#adding-a-pubspec-dependency) and be used in the same way as [Components](https://docs.flutterflow.io/resources/ui/components) throughout your project.
22+
* **[Custom Files](custom-files.md):** Within Custom Files, you'll have the ability to edit some parts of the `main.dart` file.
2223

2324

2425
:::tip[Why Write Custom Code?]
@@ -48,12 +49,6 @@ Note that the desktop version of the In-App Code Editor is limited. We recommend
4849
or the **[VSCode Extension](vscode-extension.md)**.
4950
:::
5051

51-
52-
Beyond the custom code resoureces outlined above, you'll also see an additional section in the left
53-
hand sidebar of the Custom Code page - [Custom Files:](custom-files.md).
54-
55-
Within Custom Files you'll have the ability to edit some parts of the `main.dart` file.
56-
5752
### Code Copilot
5853

5954
Code Copilot is an AI-assisted feature that helps you generate code snippets,
@@ -122,17 +117,23 @@ When there is a compilation error, the code analyzer will stop running and displ
122117
by the compiler. Once fixed, save the code and rerun using the Compile Code button. The code analyzer
123118
should then be reconnected. You can also manually reconnect it if needed.
124119

125-
### Custom Code Automatic Imports
120+
### Custom Code Default Imports
126121

127122
When creating a new custom code snippet (Actions, Widgets, or Functions) in FlutterFlow, some fundamental imports will be automatically added for you. These imports cannot be modified by the developer. Custom Functions do not allow adding any custom imports, but you can add custom imports in Custom Actions and Widgets after the line **"Do not remove or modify the code above"**.
128123

129124
![automatic-imports.png](imgs/automatic-imports.png)
130125

131126
### Custom Code Settings
132127

133-
When you edit a custom code snippet in FlutterFlow, the Settings block will open on the right. This
134-
block may vary slightly depending on the type of custom code (Actions, Functions, Widgets), but here
135-
we'll discuss the common settings.
128+
When you edit a custom code snippet in FlutterFlow, the Settings menu opens on the right. This menu may vary slightly depending on the type of custom code (Actions, Functions, or Widgets), but here, we’ll cover the common settings.
129+
130+
#### Generate Boilerplate Code
131+
This setting allows you to generate boilerplate code, providing a structured starting point with essential code imports and a basic widget or function structure.
132+
133+
![copy-boilerplate-code.png](imgs/copy-boilerplate-code.png)
134+
135+
After creating a new resource file, click the code icon on the Widget Settings menu to generate the boilerplate code. Then, click "Copy to Editor" to add the boilerplate to your resource file’s code editor, where you can further customize it.
136+
136137

137138
#### Exclude From Compilation
138139

@@ -156,7 +157,7 @@ context-specific data.
156157
This option is only available for Custom Actions.
157158
:::
158159

159-
#### Input Arguments
160+
## Input Arguments
160161

161162
When writing custom code in FlutterFlow, you can define input arguments to make your custom
162163
functions, widgets, or actions more dynamic and reusable. Input arguments allow you to pass data
@@ -174,7 +175,7 @@ as `<YourTypeName>Struct`. For example, if your custom data type is called `Item
174175
referenced in the generated code as `ItemsStruct`.
175176
:::
176177

177-
##### Add a Callback Action
178+
### Callback Action As Parameter
178179

179180
A callback action is an action passed as a parameter to a custom action or widget and triggered at some point in the future when a specific event occurs.
180181

@@ -190,7 +191,7 @@ action with an Action Parameter `searchKeyword`. This means that the custom acti
190191

191192
![explain-callback-action.png](imgs/explain-callback-action.png)
192193

193-
##### Provide an Action to Callback Action
194+
### Add an Action to Callback Action
194195

195196

196197
To provide a callback action to your main custom action, check out this quick guide where we provide a "**Show Snackbar**" action to `onError`, displaying a combined text using the search keyword.
@@ -221,7 +222,7 @@ To provide a callback action to your main custom action, check out this quick gu
221222
</iframe>
222223
</div>
223224

224-
#### Return Values
225+
## Return Values
225226

226227
In FlutterFlow, custom code can not only take input arguments but also return values, back to
227228
the caller. Return values allow your custom functions, or actions to pass data back to the
@@ -237,12 +238,14 @@ Here's an example of an Action that returns a _nullable_ integer.
237238
![return-value-actions.png](imgs/return-value-actions.png)
238239

239240
## Adding a Pubspec Dependency
241+
To utilize community-built Flutter solutions in your FlutterFlow projects, you can add a "pubspec dependency". The **pubspec file** is the configuration file in Flutter projects that lists external packages or libraries, along with other project configurations.
242+
240243

241244
:::tip[Scope]
242-
You can only add a pubspec dependency to [**Custom Action**](custom-actions.md) & [**Custom Widgets**](custom-widgets.md).
245+
You can only add a pubspec dependency to [**Custom Actions**](custom-actions.md) & [**Custom Widgets**](custom-widgets.md).
243246
:::
244247

245-
### Pub.dev
248+
#### Pub.dev
246249
[Pub.dev](https://pub.dev) is the official package repository for Dart and Flutter. It hosts a wide range of packages, libraries, and tools that developers can use to extend the functionality of their Dart and Flutter applications.
247250

248251
:::info[Flutter Favorite Packages]
@@ -253,6 +256,18 @@ You can explore the Flutter Favorite packages on **[pub.dev's Flutter Favorites
253256

254257
:::
255258

259+
To add a pubspec dependency from [**pub.dev**](#pubdev), follow these steps:
260+
261+
1. Create a new Custom Widget or Custom Action resource file, and be sure to give it a meaningful name.
262+
263+
2. [**Generate the boilerplate code**](#generate-boilerplate-code) and copy the basic widget or function structure into the code editor.
264+
265+
3. Select the [**package you want from pub.dev**](#choosing-the-correct-package-from-pubdev) and review its details.
266+
267+
4. Copy the package name and version, and add them to the Custom Code settings in FlutterFlow. Then, copy the import statement and add it to the list of imports in the Custom Code resource. You can also copy example code from the Example tab on the package’s pub.dev page and modify it as needed — see more in the **[Setup Code](#setup-code)** section.
268+
269+
5. Click "Save & **[Compile Code](#compile-code)**" to apply the changes.
270+
256271
### Choosing the correct package from pub.dev
257272

258273
You will find varieties of dependencies for a specific requirement, and choosing the best one can be
@@ -282,38 +297,45 @@ one.
282297

283298
When adding a pubspec dependency to your custom code in FlutterFlow, you’ll need two pieces of information: the [package name with its version number](#copy-package-name--version) and the [import statement](#copying-import-statement).
284299

285-
#### Copy Package Name & Version
300+
### Setup Code
301+
To configure your custom code with the package, copy and paste the following items from the package's pub.dev page:
286302

287-
To use the dependency code in our code editor, copy its name with the version. To do so, click
288-
the **Copy to Clipboard** icon.
303+
1. **Copy Package Name & Version**
289304

290-
<p></p>
305+
To use the dependency in your Custom Action or Custom Widget resource file, go to the package's pub.dev page and click the **Copy to Clipboard** icon next to the package name and version. Then, paste it into the **Pubspec Dependency** section (bottom right) of the FlutterFlow code editor.
306+
307+
![package-dependency-version-copy.png](imgs/package-dependency-version-copy.png)
308+
309+
310+
See **[example](#add-pubspec-dependency-to-custom-code-example-guide)** for more information.
291311

292-
![img.png](imgs/img.png)
293312

294-
<p></p>
295313

296314
:::warning
297315
The current dependency might depend on other dependencies to work. So make sure you also copy the
298-
name and version of all the additional dependencies to specify in the code editor.
299-
:::
316+
name and version of all the additional dependencies to specify in the code
300317

301318
You can check if the current dependency has any additional dependencies inside the '*Dependencies'*
302319
section at the bottom right side.
303320

321+
304322
![img_1.png](imgs/img_1.png)
323+
:::
305324

306-
#### Copying import statement
325+
2. **Copying Import Statement**
307326

308-
An import statement points to where the dependency's code is located. When making a custom widget or
309-
action, place this statement at the beginning of the code editor.
327+
An import statement specifies the location of the dependency's code. When creating a custom widget or action, add this statement at the end of the default import statements in the code editor.
310328

311-
Open the dependency page and select the installing tab; under the Import it section, you'll find
329+
Open the dependency page and select the **Installing** tab; under the **Import It** section, you'll find
312330
the import statement. To copy, click the **Copy to Clipboard** icon.
313331

314-
![img_2.png](imgs/img_2.png)
332+
![copy-import-statement.png](imgs/copy-import-statement.png)
333+
334+
3. **Copy Example Code**
335+
336+
Example code is always available in the **Example** tab on the package’s pub.dev page. Copy any relevant snippets that demonstrate usage, and paste them into your custom widget or function file. You can then modify the code as needed to fit your project.
315337

316-
### Add Pubspec Dependency to Custom Code: Guide
338+
## Add Pubspec Dependency to Custom Code: Example Guide
317339
In this example, we are using the
318340
[**flutter_rating_bar**](https://pub.dev/packages/flutter_rating_bar) dependency to create a
319341
`ProductRatingBar` custom widget for our
@@ -349,7 +371,7 @@ FlutterFlow:
349371
<p></p>
350372

351373
:::note
352-
This example demonstrates how to add a [pub.dev](https://pub.dev) package to a Custom Widget snippet, but you can follow the same process for adding a package to Custom Actions. For a deep dive, explore the detailed documentation on **[Custom Widgets](custom-widgets.md)** and [Custom Actions](custom-actions.md).
374+
This example demonstrates how to add a [**pub.dev**](https://pub.dev) package to a Custom Widget snippet, but you can follow the same process for adding a package to Custom Actions. For a deep dive, explore the detailed documentation on **[Custom Widgets](custom-widgets.md)** and [**Custom Actions**](custom-actions.md).
353375
:::
354376

355377

252 KB
Loading
255 KB
Loading
Binary file not shown.
139 KB
Loading

0 commit comments

Comments
 (0)