- What is Effective Dart?
- Project Setup
- Customization & Control
WRITE DART CODE THE RIGHT WAY.
I am Birju Vachhani
I am here because I love clean code.
You can ﬁnd me on Twitter at @birjuvachhani
∎ What is Effective Dart?
∎ Project Setup
∎ Customization & Control
A set of rules and guidelines derived and
learned from code written over the past several
● To Be Consistent: If two pieces of code look different it should be because they are
different in some meaningful way.
● To Be Brief: If there are multiple ways to say something, you should generally pick the
most concise one.
● Style Guide: For laying out and organizing code.
● Documentation Guide: For doc comments and regular comments.
● Usage Guide: For using language features in best way to implement behavior.
● Design Guide: For designing consistent, usable APIs for libraries.
Constants are often changed to ﬁnal
non-const variables, which would
necessitate a name change.
The /// syntax is also easier to read in
some situations, such as when a doc
comment contains a bulleted list that
uses * to mark list items.
When testing whether an
iterable or map is empty,
prefer isNotEmpty over
!isEmpty to improve code
Omitting the type focuses the
reader’s attention on the more
important name of the variable and
its initialized value.
Let’s see how we can enable analyzer
and linter to use effective_dart for our
project and customize it.
Add effective_dart under
section in pubspec.yaml.
Create configuration file
the root of the project.
To avoid unrelated
warnings, you can exclude
files which you don’t want
analyzer to analyze.
CUSTOMIZING LINT RULES
Rules are organized into familiar
rule groups: errors, style and
Rules can be selectively enabled in
the analyzer using analysis options
or through an analysis options ﬁle.
ENABLE / DISABLE
As some lints may contradict
each other, only a subset of
these will be enabled in
Some rules may be marked
experimental to indicate that
they are under review.
RULES IN ACTION
If the rule is enabled, linter
shows warning when the rule is
broken like this one.
Customizing rules is ﬁne, but could
you change the severity of the rule?
Let’s see how...
Severity can be deﬁned under
errors section and can be error,
warning, info or ignore.
This way you’re in control of what
is considered error or warning by
YOU NEED TO
Don’t forget to keep an eye on Dart Analysis section in your
Android Studio. It can save you a lot of trouble!
➔ Effective Dart
➔ Linter for Dart
➔ Customizing Static Analysis