Dart Tooling & Package Workflows
Contents
Static Analysis Resolution
Use this sequential workflow to identify, fix, and verify static analysis errors in a Dart project.
- Run Static Analyzer:
dart analyze . --fatal-infos - Apply Automated Fixes:
dart fix --dry-rundart fix --apply
- Resolve Manually: Address Type Mismatches, Null Safety, or Invalid Overrides that
dart fixcouldnāt automatically resolve. - Performance Diagnostics: Utilize the Analysis Server diagnostics page (available at
http://localhost:8082when analyzer runs) to trace and diagnose slow analysis times. - Verify: Ensure both
dart analyze .anddart testpass.
Resolving Package Conflicts
When pub get fails due to incompatible package versions, use this systematic approach.
Understanding dart pub outdated
| Column | Meaning |
|---|---|
| Current | Version in pubspec.lock right now |
| Upgradable | Latest version allowed by pubspec.yaml constraints |
| Resolvable | Latest version that CAN be resolved with all other deps |
| Latest | Latest published version (ignoring constraints) |
dart pub outdated
Git LFS Support
Introduced in Dart 3.12
- The
dart pubpackage management command natively supports Git Large File Storage (LFS). Dependencies fetched from Git repositories that contain LFS objects (e.g. assets, binaries, models) resolve automatically without requiring local configuration.
Version Constraint Best Practices
- Use Caret Syntax: Always use
^1.2.3ā allows non-breaking updates up to next major version. - Tighten Dev Dependencies: Set lower bounds to exact current version for
dev_dependencies. - CI Reproducibility: Use
dart pub get --enforce-lockfilein CI to ensure exact tested versions.
Upgrading Dependencies
If updating to āUpgradableā versions:
dart pub upgrade
dart pub upgrade --tighten # Auto-update lower bounds in pubspec.yaml
If updating to āResolvableā versions (major):
- Manually edit
pubspec.yamlto bump constraints. - Run
dart pub upgrade. - Run
dart analyzeā fix breaking API changes. - Run
dart testā fix regressions.
Surgical Lockfile Removal
NEVER delete the entire pubspec.lock. This causes uncontrolled upgrades across the dependency graph.
Instead, remove ONLY the conflicting packageās block:
- Open
pubspec.lock. - Find and delete ONLY the conflicting packageās YAML block.
- Run
dart pub getā fetches newest compatible version for that package only. - Verify:
dart pub depsā check dependency graph resolves correctly.
Temporary Overrides (Last Resort)
dependency_overrides:
shared_package: ^x.y.z # Remove once direct deps support newer version
Migrating Tests to package:checks
Transition test assertions from the package:matcher syntax to the literate API provided by package:checks for more readable output.
- Dependency: Add
dev_dependencychecksviadart pub add dev:checks. - Basic Equality: Replace
expect(actual, equals(expected))withcheck(actual).equals(expected). - Type Checking: Replace
expect(actual, isA<Type>())withcheck(actual).isA<Type>(). - Asynchronous Expectations:
await check(Future.value(10)).completes((it) => it.equals(10));
- Workflow:
- Add
package:checksand importpackage:checks/checks.dart. - Rewrite
expect()calls tocheck(). - Run static analyzer and tests to verify.
- Add