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 declaring parameters as final. Declaring parameters as final can lead to unnecessarily verbose code, especially
DO sort combinator names alphabetically. BAD:
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.
DO specify required
on named parameter before other named parameters. BAD:
DO depend on referenced packages. When importing a package, add a dependency on it to your pubspec.
pubspec.yaml
DRT-W1038DO Use secure urls in pubspec.yaml
. Use https
instead of http
or git:
.
DO declare method return types. When declaring a method or function always specify a return type.
From the style guide for the flutter repo: DO specify type annotations.
DO annotate overridden methods and fields. This practice improves code readability and helps protect against
AVOID annotating with dynamic when not required. As dynamic
is the assumed return value of a function or method, it is usually
AVOID field initializers in const classes. Instead of final x = const expr;
, you should write get x => const expr;
and
AVOID catches without on clauses. Using catch clauses without on clauses make your code prone to encountering
DON'T explicitly catch Error or types that implement it. Errors differ from Exceptions in that Errors can be analyzed and prevented prior