pubspec.yaml - package versions : - ^0.13.0
Answer
Overview
The
text
^text
pubspec.yamltext
^0.13.0Semantic Versioning (SemVer)
Flutter packages follow SemVer format:
text
MAJOR.MINOR.PATCHtext^1.2.3 │ │ │ │ │ └─ PATCH: Bug fixes (backward compatible) │ └─── MINOR: New features (backward compatible) └───── MAJOR: Breaking changes
Caret (^) Version Constraint
Syntax:
text
^versionyamldependencies: http: ^0.13.0 # 0.13.0 <= version < 0.14.0 provider: ^6.0.5 # 6.0.5 <= version < 7.0.0
Examples
| Constraint | Allowed Versions | Not Allowed |
|---|---|---|
text | 0.13.0, 0.13.5, 0.13.99 | 0.14.0, 1.0.0 |
text | 1.2.3, 1.5.0, 1.99.0 | 2.0.0 |
text | 2.0.0, 2.1.0, 2.99.0 | 3.0.0 |
text | 0.0.5 only | 0.0.6, 0.1.0 |
Why Use ^?
Automatic compatible updates without breaking your app.
yaml# ✅ With caret — gets bug fixes automatically dependencies: flutter_bloc: ^8.1.0 # Receives 8.1.1, 8.2.0, etc. (no breaking changes) # ❌ Without caret — stuck on exact version dependencies: flutter_bloc: 8.1.0 # Never updates (even for critical bug fixes)
Other Version Constraints
Exact Version
yamldependencies: http: 0.13.0 # Only 0.13.0 (no updates)
Range
yamldependencies: http: '>=0.13.0 <0.15.0' # 0.13.0 to 0.14.x (not 0.15.0)
Any Version
yamldependencies: http: any # Latest version (not recommended)
Greater Than or Equal
yamldependencies: http: '>=0.13.0' # 0.13.0 or newer (no upper limit)
Special Case: 0.x.y Versions
Pre-1.0 packages are considered unstable. Minor updates may include breaking changes.
yaml# ^0.13.0 is strict for pre-1.0 versions dependencies: package_a: ^0.13.0 # 0.13.0 <= v < 0.14.0 (minor = potential breaking) package_b: ^1.2.0 # 1.2.0 <= v < 2.0.0 (major = breaking)
How Flutter Resolves Versions
When you run
text
flutter pub getyaml# Your app dependencies: http: ^0.13.0 # Allows 0.13.x # Another dependency needs http dependencies: http: ^0.13.5 # Also allows 0.13.x # Flutter installs: 0.13.6 (latest that satisfies both)
Common Patterns
yamldependencies: # Stable packages (1.0+) — use caret provider: ^6.0.0 http: ^1.1.0 # Pre-1.0 packages — caret for minor updates some_new_package: ^0.5.0 # Gets 0.5.x (not 0.6.0) # Flutter SDK constraints sdk: ">=3.0.0 <4.0.0" # Git dependencies (exact commit/tag) custom_package: git: url: https://github.com/user/repo.git ref: v1.2.3 # Specific tag
Updating Dependencies
bash# Check for available updates flutter pub outdated # Update within constraints (respects ^) flutter pub upgrade # Update to latest (ignores constraints) flutter pub upgrade --major-versions
Best Practices
yaml# ✅ Use caret for stable packages dependencies: http: ^1.0.0 # ✅ Lock critical dependencies dependencies: payment_sdk: 2.5.3 # Exact version (no surprises) # ❌ Avoid 'any' (unpredictable) dependencies: random_package: any # ✅ Set SDK constraints environment: sdk: ">=3.0.0 <4.0.0" flutter: ">=3.10.0"
Version Conflict Example
yaml# App dependency dependencies: package_a: ^1.0.0 # Depends on shared_lib: ^2.0.0 package_b: ^2.0.0 # Depends on shared_lib: ^3.0.0 # ❌ Conflict! Cannot satisfy both # Solution: Update package_a or package_b
pubspec.lock
After
text
flutter pub gettext
pubspec.lockyaml# pubspec.lock (auto-generated) packages: http: version: "0.13.6" # Exact installed version
Commit to ensure team uses same versions.textpubspec.lock
Summary Table
| Symbol | Meaning | Example | Allowed |
|---|---|---|---|
text | Compatible updates | text | 1.2.3 - 1.x.x |
| None | Exact version | text | 1.2.3 only |
text | Greater/equal | text | 1.2.3+ |
| Range | Explicit range | text | 1.x.x |
text | Latest | text | Any version |
Learn more: Dart Package Versioning