Irbisa · Cheatsheet
Packages & Dependencies
Version constraints, pubspec.lock, version solving, overrides, publishing, melos, upgrades
What is the difference between a Dart package, a Flutter package and a Flutter plugin?
# A plugin's pubspec.yaml: the `plugin:` block is what makes it onename: battery_levelenvironment: sdk: ^3.9.0 flutter: '>=3.35.0'…What is the difference between
dependencies,dev_dependenciesanddependency_overridesinpubspec.yaml?dependencies: dio: ^5.9.0 json_annotation: ^4.9.0 # lib/ imports the annotations dev_dependencies: build_runner: ^2.5.0 # runs on your machine and in CI only…Should you commit
pubspec.lock, and does the answer differ for an app and for a published package?What is the difference between
pub get,pub upgradeandpub upgrade --major-versions?$ flutter pub outdated# Package Current Upgradable Resolvable Latest# dio 5.7.0 5.9.0 5.9.0 5.9.0# acme_analytics 1.9.4 1.9.6 2.3.0 2.3.0 $ flutter pub get # dio stays on 5.7.0: the lock wins…Which versions can pub pick for each constraint below, and why does
intlrefuse 0.21.0 whilediomoves to 5.9.0?dependencies: dio: ^5.7.0 intl: ^0.20.2 uuid: 4.5.1 web_socket_channel: '>=3.0.0 <3.0.3' crypto: anyWhat are the trade-offs of hosted,
pathandgitdependencies, and when is pointing at a GitHub branch acceptable?dependencies: dio: ^5.9.0 # hosted on pub.dev acme_domain: path: ../packages/acme_domain # inside this repo only…How do you share private packages between several of your company's apps?
# The shared package: can only ever be published to the private servername: acme_uiversion: 3.2.0publish_to: https://pub.acme.internal ---…flutter pub getfails with "version solving failed" and a long "Because…" chain. How do you find and fix the actual conflict?$ flutter pub getBecause every version of flutter_localizations from sdk depends on intl 0.20.2 and acme_analytics >=2.1.0 depends on intl ^0.21.0, flutter_localizations from sdk is incompatible with acme_analytics >=2.1.0.So, because checkout_app depends on both flutter_localizations from sdk and acme_analytics ^2.1.0, version solving failed.…What does
dependency_overridesactually switch off, and why is it a last resort?dependencies: acme_analytics: ^2.1.0 # needs intl ^0.21.0 flutter_localizations: sdk: flutter # pins intl exactly # wrong: pub get is green, the combination is untested…After a Flutter upgrade
pub getfails with "requires SDK version >=2.7.0 <3.0.0" on a package you don't own. What happened, and what are your options?Your package is at 1.2.0 and the next release makes the three changes below. Is that a patch, a minor or a major?
// acme_toast 1.2.0, publishedclass Toast { Toast({required this.message, this.seconds = 3}); final String message; final int seconds;} enum ToastStyle { info, error } // Next release:// 1. Toast's constructor gains `required this.icon`.// 2. ToastStyle gains a third value, `warning`.// 3. A new top-level function `showToast(Toast toast)` is added.How do you structure, version and publish a package to pub.dev, and what can you never undo?
acme_result/ lib/ acme_result.dart # public API: export 'src/result.dart' show Result; src/ result.dart # implementation, never imported by consumers example/…What do pub workspaces change in a monorepo, and what is Melos still needed for?
# pubspec.yaml at the repo rootname: acme_workspacepublish_to: noneenvironment: sdk: ^3.9.0workspace:…A transitive dependency you never chose ships a broken patch and your build starts failing. What do you do first?
# 1) What moved, and who pulls it in?git diff HEAD~1 -- pubspec.lock | grep -A3 broken_jsonflutter pub deps --style=compact | grep broken_json # 2) Back to the last good resolutiongit checkout HEAD~1 -- pubspec.lock # or the last known-good commit…Why is one plugin such as
path_providersplit into several packages on pub.dev, and which of them does your app depend on?# bar_scanner/pubspec.yaml: the app-facing packagedependencies: flutter: { sdk: flutter } bar_scanner_platform_interface: ^2.0.0 bar_scanner_android: ^2.1.0 # endorsed: lands in every consumer bar_scanner_ios: ^2.1.0…Two packages in your pub workspace (or one app) need different major versions of the same dependency. Why can't pub give each its own copy, and how do you get out?
Your team upgrades dependencies twice a year and each round costs days of firefighting. How do you make upgrades routine?
# .github/dependabot.ymlversion: 2updates: - package-ecosystem: pub directory: / schedule:…How do you move an app to a new Flutter release that contains breaking changes?
# On a dedicated branch, with the version pinned for everyonefvm use 3.38.0 # writes .fvmrc; CI reads the same file fvm flutter pub upgrade # plugins often need releases for the new SDKfvm flutter pub outdated…A package at the centre of your app has not shipped in two years and now blocks a Dart SDK bump: fork, vendor, or replace?