DA

Dart Defaults

Core Dart coding conventions

Details

Language / Topic
dartDart
Category
Style Guide

Rules

balanced
- Follow Effective Dart style: `lowerCamelCase` for variables/functions, `UpperCamelCase` for types, `lowercase_with_underscores` for files.
- Use null safety. Prefer non-nullable types and use `late` only when initialization is guaranteed.
- Use `final` for local variables that won't be reassigned and `const` for compile-time constants — Dart analyzer warns on unused `var`.
- Use named parameters with `required` keyword for functions with more than 2 parameters — improves call-site readability.
- Use `final` for variables that won't be reassigned. Use `const` for compile-time constants.
- Use `async`/`await` for asynchronous operations. Return `Future<T>` from async functions.
- Use named parameters with `required` keyword for functions with multiple parameters.
- Prefer `switch` expressions (Dart 3) over `if`/`else` chains for pattern matching.
- Use `extension` methods to add functionality to existing types without subclassing.