DON'T put any logic in createState()
. Implementations of createState()
should return a new instance
DON'T assign a variable to itself. Usually this is a mistake. BAD:
DON'T use wildcard parameters or variables. Wildcard parameters and local variables
DON'T use the type Null where void would work. BAD:
From the style guide for the flutter repo: DO separate the control structure expression from its statement.
AVOID wrapping widgets in unnecessary containers. Wrapping a widget in Container
with no other parameters set has no effect
AVOID empty else statements. BAD:
AVOID declaring parameters as final. Declaring parameters as final can lead to unnecessarily verbose code, especially
DO sort combinator names alphabetically. BAD:
print
calls in production code DRT-W1004DO avoid print
calls in production code. For production code, consider using a logging framework.
DON'T use more than one case with same value. This is usually a typo or changed value of constant.
DO sort pub dependencies alphabetically (A to Z) in pubspec.yaml
. Sorting list of pub dependencies makes maintenance easier.
AVOID bool literals in conditional expressions. BAD:
AVOID shadowing type parameters. BAD:
From Effective Dart: DO name extensions using UpperCamelCase
.
PREFER using lowerCamelCase for constant names. In new code, use lowerCamelCase
for constant variables, including enum values.
Attach library doc comments (with ///
) to library directives, rather than leaving them dangling near the top of a library.
The analyzer produces this diagnostic when a deprecated library member or class member is used in the same package in which it's declared.
lib/
DRT-W1026PREFER relative imports for files in lib/
. When mixing relative and absolute imports it's possible to create confusion
lib/
DRT-W1001DO avoid relative imports for files in lib/
. When mixing relative and absolute imports it's possible to create confusion