Introduction

When running flutter pub get, you may encounter a platform conflict error where a dependency declares a constraint that is incompatible with your target platform. This commonly happens when a package supports only certain platforms, or when transitive dependencies pull in platform-specific versions that conflict with your project's SDK constraints. The error is particularly common in multi-platform projects (mobile + web + desktop) where a newly updated package drops support for one platform, or when a dependency adds a platform-specific native requirement that your project cannot satisfy.

Symptoms

  • flutter pub get fails with error:
  • `
  • Because my_app depends on package_a ^2.0.0 which doesn't support any version, version solving failed.
  • `
  • Or more specifically:
  • `
  • Because package_b 3.1.0 doesn't support android and my_app depends on package_b ^3.0.0, version solving failed.
  • `
  • The error mentions specific platforms (android, ios, web, linux, macos, windows)
  • Running flutter doctor shows all toolchains are healthy, confirming the issue is dependency-level

Common Causes

  • A direct dependency dropped support for a platform you are targeting
  • A transitive dependency pulled in by another package has platform constraints
  • Your pubspec.yaml SDK constraint is too broad for the packages you depend on
  • A conditional import in a package's pubspec.yaml uses platforms: key incorrectly

Step-by-Step Fix

  1. 1.Identify the conflicting dependency:
  2. 2.```bash
  3. 3.flutter pub deps --style=compact
  4. 4.`
  5. 5.This shows the full dependency tree. Look for the package mentioned in the error.
  6. 6.Check which version supports your platform:
  7. 7.```bash
  8. 8.flutter pub outdated
  9. 9.`
  10. 10.This shows available versions and which platforms they support.
  11. 11.Use dependency overrides as a temporary fix:
  12. 12.```yaml
  13. 13.# pubspec.yaml
  14. 14.dependency_overrides:
  15. 15.conflicting_package:
  16. 16.git:
  17. 17.url: https://github.com/maintainer/conflicting_package.git
  18. 18.ref: main
  19. 19.`
  20. 20.Pin to a compatible version:
  21. 21.```yaml
  22. 22.dependencies:
  23. 23.problematic_pkg: ^2.4.0 # Last version supporting your platform
  24. 24.`
  25. 25.If using Flutter 3.16+, check conditional imports:
  26. 26.```yaml
  27. 27.# Some packages use this format:
  28. 28.platforms:
  29. 29.android:
  30. 30.package: com.example.pkg
  31. 31.pluginClass: ExamplePlugin
  32. 32.ios:
  33. 33.pluginClass: ExamplePlugin
  34. 34.# If 'web' is missing, the package does not support web
  35. 35.`
  36. 36.Clean and retry:
  37. 37.```bash
  38. 38.flutter clean
  39. 39.flutter pub cache clean
  40. 40.flutter pub get
  41. 41.`

Prevention

  • Regularly run flutter pub outdated to catch platform support changes early
  • Pin dependency versions in production rather than using caret ranges
  • Check package health on pub.dev before adding dependencies, looking at the "Platforms" badge
  • Use flutter pub deps --json in CI to detect platform constraint changes before merging
  • Maintain a multi-platform test matrix that runs flutter pub get on each target platform
  • Consider using dependency_overrides only as a short-term workaround, not a permanent solution
  • Review the pub.dev package changelog before upgrading to understand platform support changes