dart-idiomatic-usage
Writing Idiomatic Dart Collections and Strings
Contents
- String Composition
- Collection Initialization
- Collection Operations
- Type Casting in Collections
- Workflow: Refactoring Legacy Collections
String Composition
Follow these practices to compose strings efficiently and readably.
- Use adjacent strings for concatenation: Do not use the
+operator to concatenate string literals. Place them next to each other to form a single string. - Prefer string interpolation: Use
$variableor${expression}to compose strings and values instead of concatenation (+). - Omit unnecessary curly braces: Use
$identifierinstead of${identifier}when interpolating a simple identifier that is not immediately followed by alphanumeric text.
Examples
Good:
More from dart-lang/skills
dart-add-unit-test
Write and organize unit tests for functions, methods, and classes using `package:test`. Use when creating new logic or fixing bugs to ensure code remains correct and regression-free.
2.0Kdart-fix-runtime-errors
Uses get_runtime_errors and lsp to fetch an active stack trace, locate the failing line, apply a fix, and verify resolution via hot_reload.
2.0Kdart-run-static-analysis
Execute `dart analyze` to identify warnings and errors, and use `dart fix --apply` to automatically resolve mechanical lint issues. Use during development to ensure code quality and before committing changes.
2.0Kdart-use-pattern-matching
Use switch expressions and pattern matching where appropriate
2.0Kdart-resolve-package-conflicts
Workflow for fixing package version conflicts. Use this when `pub get` fails due to incompatible package versions.
2.0Kdart-collect-coverage
Collect coverage using the coverage packge and create an LCOV report
2.0K