The Flutter and Dart Guide serves as a tool to expedite developers' work by facilitating collaboration, simplifying learning, enhancing code readability, and promoting standardization within our company. Additionally, we must prepare documents for the CUBETIQS government, All members have created by Man Brahim, Chea Kit and Son Phumrin are included.
Style is an essential aspect of good coding practice. It emphasizes consistent naming conventions, logical ordering, and proper formatting, which collectively contribute to the clarity and readability of code.
Identifiers come in three flavors in Dart.
-
UpperCamelCase names capitalize the first letter of each word, including the first.
-
lowerCamelCase names capitalize the first letter of each word, except the first which is always lowercase, even if it's an acronym.
-
lowercase_with_underscores names use only lowercase letters, even for acronyms, and separate words with _.
Example
- Using UpperCamelCase
| Bad | Good |
|---|---|
class Menucontroller {...}
class httpRequest {...}
typedef predicate <T> = bool Function(T value);
|
class MenuController {...}
class HttpRequest {...}
typedef Predicate <T> = bool Function(T value);
|
- Using lowerCamelCase
| Bad | Good |
|---|---|
const PI = 3.14;
const DefaultTimeout = 1000;
final URL_SCHEME = RegExp('^([a-z]+):');
class Dice {
static final NUMBER_GENERATOR = Random();
}
|
const pi = 3.14;
const defaultTimeout = 1000;
final urlScheme = RegExp('^([a-z]+):');
class Dice {
static final numberGenerator = Random();
}
|
- lowercase_with_underscores
| Bad | Good |
|---|---|
mypackage
└─ lib
└─ file-system.dart
└─ SliderMenu.dart
|
my_package
└─ lib
└─ file_system.dart
└─ slider_menu.dart |