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:
AVOID empty else statements. 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.
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
dart:io
methods DRT-W1006AVOID using the following asynchronous file I/O methods because they are much slower than their synchronous counterparts.
DO avoid calls to
AVOID using a parameter name that is the same as an existing type. BAD:
AVOID using web libraries, dart:html
, dart:js
and dart:js_util
in Flutter packages that are not web plugins. These libraries are not supported outside a web context; functionality that depends on them will
DO invoke cancel
on instances of dart.async.StreamSubscription
. Cancelling instances of StreamSubscription prevents memory leaks and unexpected
dart.core.Sink
DRT-W1011DO invoke close
on instances of dart.core.Sink
. Closing instances of Sink prevents memory leaks and unexpected behavior.
DO reference only in scope identifiers in doc comments. If you surround things like variable, method, or type names in square brackets,
AVOID control flow leaving finally blocks. Using control flow in finally blocks will inevitably cause unexpected behavior
DO reference all public properties in debug
method implementations. Implementers of Diagnosticable
should reference all public properties in
Making asynchronous calls in non-async
functions is usually the sign of a programming error. In general these functions should be marked async
and such futures should likely be awaited (as enforced by unawaited_futures
).