To make your code more maintainable, readable, and consistent, it’s essential to adopt clear naming conventions for variables, functions, and components.
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:
UpperCamelCase (also known as PascalCase) names capitalize the first letter of each word, including the first.
lowerCamelCase (also known as camelCase) names capitalize the first letter of each word, except the first which is always lowercase, even if it’s an acronym.
lowercase_with_underscores (also known as snake_case) names use only lowercase letters, even for acronyms, and separate words with _.
General Principles
Be Consistent: Whatever conventions you choose, apply them consistently across the project.
Be Descriptive: Names should be self-explanatory, reducing the need for additional comments to explain what a variable, function, or class does.
Avoid Abbreviations: Unless it’s a well-known abbreviation, spell out words to avoid confusion.
Variable Naming Convention
This section outlines naming conventions for pages, components, state variables, custom data types, enums, and constants to ensure clarity and consistency throughout the project.
Pages & Components
Use UpperCamelCase for all widgets, components, pages, and screen names to maintain consistency and readability. FlutterFlow Studio 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.
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.
Note that the style guidelines for Pages and Components also apply to Custom Widgets, as Pages and Components created in FlutterFlow Studio are internally generated as widgets.
Custom Data Types & Enums
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.
For datatype fields, we use the same convention as State variables.
Constants
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.
Variables
State variable & Data Type field names follow the lowerCamelCase naming style to align with Dart’s conventions.
Function Naming Convention
This section defines naming conventions for custom functions, actions, and action blocks to maintain consistency, readability, and ease of understanding across the codebase.
Custom Functions & Actions
Custom functions and custom actions created in the Custom Code tab of FlutterFlow Studio should follow the lowerCamelCase naming convention. These typically reflect an action or behavior.
Note that Action Blocks should follow the same naming convention as custom actions, as they are both technically Dart functions internally in the generated code.