Skip to content

Commit 3114584

Browse files
Style Guide v1 (#253)
* WIP on style guide * Add more clarifications to certain parts * Add custom data types style guide. * add constants and fix other sections * add state variables style guide. * Add note for minimum layout nesting. * Fix headers * Adding style guide notes. * Adding description. * fix refs. * Apply suggestions from code review Co-authored-by: pinkeshmars <[email protected]> * add custom actions/func naming style --------- Co-authored-by: pinkeshmars <[email protected]>
1 parent f37aeb0 commit 3114584

File tree

7 files changed

+169
-18
lines changed

7 files changed

+169
-18
lines changed

docs/ff-concepts/design-system/design-system.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,9 @@ To add a design system from a library, first, ensure that you [add a library dep
239239

240240
---
241241

242-
## Loading Indicator
242+
## Loading Indicators
243243

244-
To customize the loading indicators used in the app, you can make changes in this section. You have the option to specify the **Indicator Type**, **Color**, and **Radius**, and the preview of the changes will be displayed below.
244+
To customize the **Loading Indicators** used in the app, you can make changes in this section. You have the option to specify the **Indicator Type**, **Color**, and **Radius**, and the preview of the changes will be displayed below.
245245

246246
<div style={{
247247
position: 'relative',
@@ -269,6 +269,10 @@ To customize the loading indicators used in the app, you can make changes in thi
269269
</div>
270270
<p></p>
271271

272+
:::tip
273+
Avoid mis-sized loading indicators or components, which lead to jumping layouts. Ensure loading components match the size and position of the content they replace.
274+
:::
275+
272276
If you prefer watching a video tutorial, here is the guide for you:
273277

274278
<div style={{

docs/resources/data-representation/variables.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ When creating variables in FlutterFlow, there are a few important considerations
3434
Start by giving your variable a meaningful and descriptive name that reflects its purpose. This name will be used throughout your app to reference the variable, so it's important to keep it clear and consistent with your naming conventions.
3535

3636
:::tip[Recommended naming convention]
37-
We recommend the `lowerCamelCase` naming convention for variables.
37+
We recommend the `lowerCamelCase` naming convention for variables. Learn more about the **[recommended naming conventions](../style-guide.md)** used in FlutterFlow and Flutter projects.
3838
:::
3939

4040
### Assigning a Data Type to a Variable
63.1 KB
Loading

docs/resources/style-guide.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
---
2+
slug: /resources/style-guide
3+
title: Naming Variables & Functions
4+
description: Naming conventions for FlutterFlow, including guidelines for widgets, components, state variables, constants, and more.
5+
tags: [Style Guide, Variables]
6+
keywords: [Style Guide, Variables]
7+
---
8+
9+
# Naming Variables & Functions
10+
11+
To make your code more maintainable, readable, and consistent, it’s essential to adopt clear naming conventions for variables, functions, and components.
12+
13+
Best practices for naming conventions in app development (especially for projects using Flutter), aim to improve code readability, maintainability, and consistency across the application. Here are some general guidelines tailored for different aspects of a Flutter project:
14+
15+
Various naming styles (as suggested by [Dart Effective Style Guide](https://dart.dev/effective-dart/style#identifiers)):
16+
17+
- **UpperCamelCase** names capitalize the first letter of each word, including the first.
18+
19+
- **lowerCamelCase** names capitalize the first letter of each word, except the first which is always lowercase, even if it's an acronym.
20+
21+
- **lowercase_with_underscores** names use only lowercase letters, even for acronyms, and separate words with _.
22+
23+
![various-naming-styles.png](imgs/various-naming-styles.png)
24+
25+
**General Principles**
26+
- **Be Consistent:** Whatever conventions you choose, apply them consistently across the project.
27+
- **Be Descriptive:** Names should be self-explanatory, reducing the need for additional comments to explain what a variable, function, or class does.
28+
- **Avoid Abbreviations:** Unless it's a well-known abbreviation, spell out words to avoid confusion.
29+
30+
31+
## Variable Naming Convention
32+
This section outlines naming conventions for pages, components, state variables, custom data types, enums, and constants to ensure clarity and consistency throughout the project.
33+
34+
35+
### Pages & Components
36+
Use **UpperCamelCase** for all widgets, components, pages, and screen names to maintain consistency and readability. FlutterFlow ensures clarity by automatically adding "Widget" to widget names when generating code. For components, you can suffix the name with "Component" to clearly distinguish them.
37+
38+
Similarly, for pages and screens, include "Page" or "Screen" in the name to indicate their purpose. This approach aligns with Dart conventions for class names and ensures a well-organized project structure.
39+
40+
:::tip[Do's]
41+
- **Use UpperCamelCase for Names:** Always use **UpperCamelCase** for widgets, components, pages, and screens. Examples: `CustomButton`, `UserProfilePage`, `MainViewComponent`.
42+
43+
- **Include "Screen" or "Page" in Page Names:** Use "Screen" or "Page" in file names to identify UI screens or pages. Examples: `LoginScreen`, `SettingsPage`.
44+
45+
- **Use Prefixes for Clarity When Necessary:** Add a prefix if it significantly improves clarity or prevents naming conflicts. Example: `AdminUserProfile` (to differentiate it from `CustomerUserProfile` or `UserProfile`).
46+
47+
- **Be Descriptive and Clear in File Names:** Ensure names are descriptive enough to convey their purpose at a glance. Examples: `OrderConfirmationScreen`, `ProductDetailsPage`.
48+
:::
49+
50+
:::danger[Don'ts]
51+
- **Don’t Use Unnecessary Prefixes:** Avoid prefixes that do not add clarity or are redundant. Bad Example: `AppPrimaryButton` (if `PrimaryButton` is sufficient).
52+
53+
- **Don’t Add "Widget" Explicitly:** Avoid adding "Widget" to class or component names manually, as FlutterFlow already appends it during code generation. Bad Examples: `ButtonWidget`, `ProfileCardWidget`.
54+
55+
- **Don’t Use LowerCamelCase for Class Names:** Reserve **lowerCamelCase** for variables and methods, not for components, or pages. Bad Examples: `loginButton`, `userProfile`.
56+
57+
- **Don’t Mix Naming Conventions:** Maintain consistency with UpperCamelCase for all widgets, components, pages, and screens. Bad Examples: `userLogin`, `Profilecard`, `headerView`.
58+
59+
- **Don’t Use Generic Names Without Purpose:** Avoid overly generic names that do not clearly convey the file’s intent. Bad Examples: `Main`, `View`, `Screen1`.
60+
61+
:::
62+
63+
64+
Note that the style guidelines for Pages and Components also apply to **[Custom Widgets](../ff-concepts/adding-customization/custom-widgets.md)**, as Pages and Components created in FlutterFlow are internally generated as widgets.
65+
66+
67+
### Custom Data Types & Enums
68+
69+
When naming custom data types and enums, use **UpperCamelCase** for consistency and clarity. Ensure that names are descriptive, providing a clear representation of the entity or purpose.
70+
71+
:::tip[Do's]
72+
73+
- **Use UpperCamelCase for Custom Data Types:** Name your custom data types using **UpperCamelCase**. Ensure that names are clear, concise, and descriptive, reflecting the entity they represent. Good Examples: `UserModel`, `ProductDetails`, `OrderItem`.
74+
75+
- **Use consistent naming for Enum Names and Values:** Use **UpperCamelCase** for the enum name such as, `Status`, `ConnectionState`, `UserRole` and **lowerCamelCase** for its values e.g., `{active, inactive, pending}`. This approach aligns with Dart's enum naming guidelines and ensures consistency.
76+
77+
- **Use Plural Names for Lists:** If the data type represents a List, use a plural name to clarify its purpose. Good Example: `OrderItems` (to represent multiple `OrderItem` objects).
78+
:::
79+
80+
:::danger[Don'ts]
81+
82+
- **Don’t Use All Lowercase or Mixed Case for Custom Data Types:** Avoid using all lowercase or inconsistent casing in data model class names, as it reduces readability. Bad Example: `usermodel`, `product_details`.
83+
84+
- **Don’t Use Vague or Non-Descriptive Names**: Avoid using generic or unclear names that do not clearly describe the data entity. Bad Example: `DataModel`, `Entity`, `Item`.
85+
86+
- **Don’t Mix Naming Conventions for Enums:** Maintain consistent capitalization between enum names and their values. Bad Example: `enum UserRole { Admin, EDITOR, viewer }`
87+
:::
88+
89+
### Constants
90+
91+
Flutter prefers using a lowercase `k` prefix for constants to indicate their immutability, especially for project-specific constants. This approach is more concise and aligns with Dart's common practices. Use **SCREAMING_SNAKE_CASE** only when contributing to global or legacy projects where it is already in use.
92+
93+
:::tip[Do's]
94+
- **Start Constants with a k Prefix:** Always use a lowercase `k` followed by **UpperCamelCase** for constants in FlutterFlow projects.
95+
- **Use Descriptive and Contextual Names:** Clearly describe the purpose of the constant. Avoid using abbreviations unless they are widely understood. Examples: `kDefaultPadding`, `kMaxUploadSizeMb`
96+
:::
97+
98+
:::danger[Don'ts]
99+
- **Don’t Omit the k Prefix for Constants:** Avoid using plain names for constants in a Flutter-specific project, as they might conflict with variables or methods. Bad Examples: `padding`, `uploadSize`.
100+
- **Don’t Use Vague or Generic Names:** Avoid using names that fail to describe the purpose of the constant. Bad Examples: `VALUE`, `DATA`, `X`, `Y`.
101+
:::
102+
103+
### State Variables
104+
105+
State variable names follow the **lowerCamelCase** naming style to align with Dart's conventions.
106+
107+
:::tip[Do's]
108+
- **Be Descriptive and Clear:** Use variable names that clearly describe their purpose, avoiding generic or vague terms. Examples: `isFormValid`, `errorMessage`, `availableProducts`.
109+
- **Prefix Boolean Variables with `is`, `has`, or `should`:** For readability, use prefixes that denote the variable's purpose when naming Boolean values. Examples: `isActive`, `hasErrors`, `shouldReload`.
110+
- **Use Consistent Prefixes to denote state:** When managing UI or asynchronous state, use prefixes like `current`, `selected`, or `pending` for better context. Examples: `currentTabIndex`, `selectedUserId`, `pendingAction`.
111+
:::
112+
113+
:::danger[Don'ts]
114+
- **Don’t Use Abbreviations or Single Letters:** Avoid abbreviations or single-character names that obscure the variable's intent. Bad Examples: `usrNm`, `f`, `cnt`.
115+
- **Don’t Use Generic Names:** Avoid using generic terms that do not convey the variable’s purpose. Bad Examples: `data`, `value`, `temp`.
116+
- **Don’t Start State Variables with Uppercase:** Follow Dart conventions by starting variable names with lowercase. Bad Examples: `UserName`, `IsLoading`.
117+
:::
118+
119+
## Function Naming Convention
120+
This section defines naming conventions for custom functions, actions, and action blocks to maintain consistency, readability, and ease of understanding across the codebase.
121+
122+
### Custom Functions & Actions
123+
124+
Custom functions and custom actions created in the Custom Code tab of FlutterFlow should follow the **lowerCamelCase** naming convention. These typically reflect an action or behavior.
125+
126+
:::tip[Do's]
127+
- **Be descriptive and concise:** Use clear, meaningful names that describe the action or purpose of the function (e.g., `validateForm` instead of `doCheck`, or `fetchUserData` instead of `userData`).
128+
- **Use action-oriented names:** Start with verbs to indicate behavior (e.g., `submitForm`, `processPayment`).
129+
:::
130+
131+
:::danger[Dont's]
132+
- **Avoid using underscores or spaces:** Names like `fetch_user_data` do not align with **lowerCamelCase** conventions.
133+
- **Avoid redundant prefixes or suffixes:** There’s no need to prefix with `custom` or suffix with `Func` unless absolutely necessary for clarity (e.g., `customSubmitFormFunc` is redundant).
134+
- **Don’t use overly generic names:** Avoid vague terms like `doSomething` or `functionOne`, which don’t provide context.
135+
:::
136+
137+
Note that **[Action Blocks](../resources/control-flow/functions/action-blocks.md)** should follow the same naming convention as custom actions, as they are both technically Dart functions internally in the generated code.

docs/resources/ui/widgets/composing-widgets/list-grid.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Axis sets the orientation of the ListView. You can select either "Vertical" or
2929
- **Items Spacing:** This defines the space between individual items in the ListView. You can
3030
specify the spacing in pixels.
3131

32+
:::tip[Items Spacing vs Padding]
33+
Prefer “Items Spacing” set on the parent row or column instead of padding on individual elements. This ensures consistency, especially on non-dynamically generated lists.
34+
:::
35+
3236
- **Apply to Start & End:** When enabled, the item spacing will also be applied to the start and the
3337
end of the ListView, adding a margin at the beginning and end of the list. This effectively adds padding at the start and end of the layout in addition to between the items.
3438

docs/resources/ui/widgets/composing-widgets/rows-column-stack.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ depends on how you need to arrange your UI components:
3030

3131
![row-col-stack.png](../../imgs/row-col-stack.png)
3232

33+
:::tip[Minimum Layout Nesting]
34+
Use the minimum amount of rows/columns necessary to achieve your layout to avoid unnecessary complexity. No page or component should nest more than 10 levels deep. Reaching this limit likely signals the need for **[converting a part of the widget tree into components](../../components/creating-components.md#convert-into-a-component)**.
35+
:::
36+
3337
<!---TODO #### Choosing your parent widget
3438
link to quickstart for how to choose parent widget [Rows/Column/Stacks]
3539
with examples --->
@@ -218,6 +222,10 @@ incoming constraints and the scrolling movement, effectively managing overflow b
218222
Column. You can specify a static numerical value that determines the pixel spacing between
219223
adjacent children or set it from a variable.
220224

225+
:::tip[Items Spacing vs Padding]
226+
Prefer “Items Spacing” set on the parent row or column instead of padding on individual elements. This ensures consistency, especially on non-dynamically generated lists.
227+
:::
228+
221229
- **Apply to Start & End:** When toggled on, this applies the specified item spacing to the
222230
beginning and the end of the Row or Column. This effectively adds padding at the start and end of the layout in addition to between the items.
223231

docs/resources/ui/widgets/widget-commonalities.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ com/embed/f510565b464c4fb8903c0b6993fc8c20?sid=ceb9de2e-af71-4ba0-b888-b6d4e47d6
4747

4848

4949

50-
### Responsive
50+
### Responsive Properties
5151

5252
When developing user interfaces with widgets, you'll notice certain properties and features that are universally applicable. This section provides guidance on adjusting these shared attributes across different widgets.
5353

@@ -75,7 +75,7 @@ Here is how it is done:
7575
<figcaption class="centered-caption">Responsive visibility for web</figcaption>
7676
</figure>
7777

78-
#### Customize responsive breakpoint
78+
#### Customize Responsive Breakpoint
7979

8080
Sometimes, you might want to override the default responsive breakpoint to suit unique requirements; whether it's accommodating a specific device or catering to a particular user experience, having the flexibility to customize breakpoints can be advantageous.
8181

@@ -154,7 +154,7 @@ com/embed/iMc1m-l7eyw" frameborder="0" allow="accelerometer; autoplay; clipboard
154154

155155

156156

157-
### Adjust alignment
157+
### Adjust Alignment
158158

159159
This property helps you position the widget in two ways.
160160

@@ -179,11 +179,11 @@ com/embed/vuJ2fTnYyCM" frameborder="0" allow="accelerometer; autoplay; clipboard
179179

180180

181181

182-
## Testing
182+
## Testing Widgets
183183

184184
This property enables you to specify the **Value Key** for the current widget, which serves as a reference point during automated test runs. Please refer to the detailed guide provided [here](../../../testing-deployment-publishing/testing/automated-tests.md).
185185

186-
## Changing the size
186+
## Set Width & Height Properties
187187

188188
To change the size, navigate to the **Width** and **Height** properties, and then you have three choices for setting the size:
189189

@@ -195,21 +195,21 @@ To change the size, navigate to the **Width** and **Height** properties, and the
195195
com/embed/aa1755b1b7b94ef3ac3a72da431d844f?sid=982c1f26-b768-4c8d-ab77-c085219ebab6" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
196196

197197

198-
## Change color
198+
## Change Color
199199

200200
To change color for any widget property:
201201

202202
1. Navigate to a widget property that allows you to set a color.
203203
2. Click on the currently selected color to either pick a new color or enter the Hex Code directly.
204204
3. By default, theme colors are displayed. Simply click on a color to apply it.
205205
4. For a custom color, switch to the **Custom Color** tab, select your desired color, and then click **Use Color**.
206-
5. You can also set a [color from variable](#setting-color-from-variable).
206+
5. You can also set a [color from variable](#set-color-from-variable).
207207

208208
<div class="video-container"><iframe src="https://www.loom.
209209
com/embed/7fb8cd068bbb45c9ae34cfd4f325a3dc?sid=b3559d67-9e11-4501-8a17-7f4e92bd5847" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe></div>
210210

211211

212-
## Setting color from variable
212+
## Set Color From Variable
213213

214214
You may want to apply dynamic colors to widget properties like Container backgrounds or Text colors, which can be achieved by assigning colors from a variable. For instance, you can display temperature color dynamically based on an app state variable, data from a Firestore document, responses from API calls, or other similar sources.
215215

@@ -253,7 +253,7 @@ com/embed/6bffe7446e1d414f99baee759fda8fc0?sid=abfedd7c-3bc4-4eda-a9ab-341b72e4b
253253

254254
You can also set the color from a [conditional value](../../../resources/control-flow/functions/conditional-logic.md#setting-widget-properties-with-conditional-logic).
255255

256-
## Copy variable
256+
## Copy Variable
257257

258258
If you have a complex variable value (e.g., using [Conditional Logic](../../../resources/control-flow/functions/conditional-logic.md)) and want to use the same logic in another variable value, you can do so by copying a variable.
259259

@@ -283,7 +283,7 @@ com/embed/f3cdb87b927b46508a2f1c21c2524cfe?sid=bb94b178-cba5-4423-afd0-47a4669c2
283283

284284
<p></p>
285285

286-
## Add an image from Unsplash
286+
## Add Image from Unsplash
287287

288288
You can also add images directly from the [Unsplash](https://unsplash.com/) right inside the properties panel. To do so, simply click on the search icon and search and select the image. **Tip**: You can also choose the size of the image to add (i.e., Small, Regular, Full).
289289

@@ -292,13 +292,11 @@ com/embed/6954aafd8e494e74b52a2e89d4744e39?sid=8cd4d95b-e338-41f1-ae8a-912422f58
292292

293293
<p></p>
294294

295-
## UI builder display value
296-
297-
For widgets like **Text** and **RichText**, when their content is coming from a variable, you have the option to set a placeholder value that will be displayed only in the app builder. Keep in mind that this display value is solely for visualization purposes within the canvas and will be replaced with the actual variable value when the app is running.
298-
299-
This is helpful in assessing spacing and alignment without the need to remove variable bindings.
295+
## UI Builder Display Value
300296

297+
For widgets like `Text` and `RichText`, when their content is set from a variable, you can set a placeholder value to be displayed only in the app builder. Keep in mind that this placeholder is solely for visualization purposes within the canvas and will be replaced by the actual variable value when the app runs.
301298

299+
This feature is useful for assessing spacing and alignment without removing variable bindings.
302300

303301
![img_4.png](..%2Fimgs%2Fimg_4.png)
304302
## Trigger action on selection change

0 commit comments

Comments
 (0)