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
Add a trailing whitespace to prevent missing whitespace between adjacent strings.
DO provide doc comments for all public APIs. As described in the pub package layout doc,
PREFER using interpolation to compose strings and values. Using interpolation when composing strings and values is usually easier to write
AVOID new keyword to create instances. BAD:
The analyzer produces this diagnostic when the runtime type of a constant value can't be assigned to the static type of a constant constructor's parameter.
pubspec.yaml
DRT-W1297The analyzer produces this diagnostic when a key is used in a pubspec.yaml
file that was deprecated. Unused keys take up space and might imply semantics that are no longer valid.
The analyzer produces this diagnostic when the result of dividing two numbers is converted to an integer using toInt
. Dart has a built-in integer division operator that is both more efficient and more concise.
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:
DO throw only instances of classes that extend dart.core.Error
or dart.core.Exception
.
DO put asserts in initializer lists. BAD:
The analyzer produces this diagnostic when an integer literal has a value that is too large (positive) or too small (negative) to be represented in a 64-bit word.
DO prefer declaring for-each loop variables as final if they are not reassigned later in the code.