Mobile Development 10 min read

Flutter Linter Practices and Code Style Guidelines at Xianyu

Xianyu’s Flutter team defines a custom lint configuration in analysis_options.yaml, selecting stable rules from effective_dart, pedantic, flutter_lints and lints to enforce concise syntax, safe null handling, explicit typing, consistent style, and proactive quality checks, supported by CI enforcement and team‑wide consensus.

Xianyu Technology
Xianyu Technology
Xianyu Technology
Flutter Linter Practices and Code Style Guidelines at Xianyu

Code standards are a core gene of a development team. This article shares Xianyu's practical experience in establishing basic Flutter code conventions.

Flutter static code scanning – Like Android/iOS, Flutter also provides a Linter mechanism based on Dart Linter. Rules are defined in analysis_options.yaml and can be customized per team.

The rules are grouped into three collections:

ERROR – potential bugs

STYLE – style issues

PUB – package‑management concerns

Each rule has a maturity level: Stable, Experimental, or Deprecated.

Common rule sets include effective_dart, pedantic, flutter_lints, and lints. Xianyu selects a subset that fits its workflow.

Key principles in Xianyu's selection :

Concise expression – use Dart’s advanced syntax (e.g., remove redundant new).

Efficient null handling – prefer null‑aware operators and conditional assignments.

Reduce ambiguity – explicitly specify variable types, use override, const, final where appropriate.

Style consistency – camelCase naming, always use braces, order imports (dart, package, relative), prefer SizedBox over Container, use full‑hex color values, add key in widget constructors.

Code quality checks target common pitfalls such as assigning to void, unchecked type equality, empty catch blocks, type shadowing, awaiting non‑Future objects, and mismatched collection removals.

Addressing these issues early improves robustness and prevents runtime exceptions.

Maintenance cost – clear documentation and comments (e.g., deprecation messages, comment references) reduce future debugging effort.

Rule authority – Xianyu involves the whole team in rule creation, ensuring consensus and adherence. An example is the discussion on line‑length limits, which led to adopting a 160‑character limit instead of the traditional 80.

Finally, Xianyu is building a CI pipeline to enforce these rules continuously, treating code as a valuable team asset.

[1] effective_dart: https://pub.dev/packages/effective_dart
[2] pedantic: https://pub.dev/packages/pedantic
[3] flutter_lints: https://pub.dev/packages/flutter_lints
[4] lints: https://pub.dev/packages/lints
[5] linter‑rules: https://dart.dev/tools/linter-rules#lints
DARTFluttercode stylestatic analysislinter
Xianyu Technology
Written by

Xianyu Technology

Official account of the Xianyu technology team

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.