Flutter Naming Conventions Guidance
In Flutter projects, following a consistent and meaningful naming convention is crucial for code readability and maintainability. This guide provides a set of commonly accepted naming conventions for Flutter projects.
Package Names
Package names should be written in lowercase, and words should be separated by underscores (_).
Example: com.example.my_flutter_app
Project Names
Project names should be written in lowercase, and words should be separated by spaces.
Example: my_flutter_app
File Names
Dart files and other files should be written in lowercase, and words should be separated by underscores (_). File names should be descriptive enough to convey their content.
Examples:
user_profile.dart
constants.dart
Class and Function Names
Class and function names should follow the "camelCase" convention. Class names should start with an uppercase letter and be descriptive of their purpose.
Examples:
Variable Names
Variable names should follow the "camelCase" convention and should be descriptive and meaningful.
Examples:
Constant Names
Constants should be written in uppercase letters and words should be separated by underscores (_).
Examples:
Private Variable and Method Names
Private variables and methods should be written with an underscore (_) followed by "camelCase."
Example:
Boolean Variables
Boolean variables should have names that convey a positive meaning if true and a negative meaning if false.
Example:
Argument Names
Function arguments should have descriptive and meaningful names.
Example:
Widget Names
Custom widgets should have descriptive names that clearly convey their purpose and functionality.
Example:
Enum Names
Enum tipleri, büyük harfle başlamalı ve "camelCase" kullanılmalıdır. Enum değerleri de büyük harfle yazılmalıdır.
Constant Names with Prefix
When declaring constants in a class, use a prefix to indicate their purpose or category.
Constructor Names
Constructors should use "camelCase" with the class name in lowercase.
Factory Constructor Names
Factory constructors should be named appropriately and use "camelCase."
Named Constructor Names
Named constructors should be descriptive and use "camelCase."
Setters and Getters
Use "camelCase" for getter and setter methods, with a prefix like "get" and "set."
Boolean Getter Names
Boolean getter methods should be descriptive and start with "is" or "has."
Widget Constructor Arguments
When creating custom widgets, constructor arguments should be descriptive and follow "camelCase."
Utility Class Names
Utility classes should have descriptive names that indicate their purpose.
Widget Key Names
When using widget keys, use descriptive names that represent their purpose.
Constant Values in Switch Statements
When using constants in switch statements, capitalize the constant names.