Flutter Best Practices

Chapter 1 · Practice 5 of 5

Turn on the recommended lints and treat analyzer warnings as work

From Dart and null safety

Why it matters

The analyzer is your cheapest reviewer. New Flutter projects include the flutter_lints package, and the Flutter performance docs specifically recommend it so you are reminded to use const where you can.

  • Keep analysis_options.yaml in the repo and include package:flutter_lints/flutter.yaml.
  • Run flutter analyze in CI and fail the build on errors and warnings.
  • Add stricter rules your team agrees on, one at a time, and fix existing hits before turning each on.

An app with hundreds of ignored warnings hides the one warning that matters. Keep the count at zero so new problems stand out.

Do

  • Run flutter analyze in CI on every pull request
  • Fix or explicitly ignore each warning with a short reason

Avoid

  • Deleting analysis_options.yaml to make warnings go away

Example

YAML
# analysis_options.yaml
include: package:flutter_lints/flutter.yaml

linter:
  rules:
    prefer_const_constructors: true
    avoid_print: true