Skip to content
DeveloperMemos

Fixing 'Flutter: Version solving failed in pub get' Error

Flutter, Dependency Management, Pub Get1 min read

The "Flutter: Version solving failed in pub get" error typically arises when there's a conflict between package versions in your Flutter project. This means that some of your dependencies have incompatible version requirements, making it impossible for the pub get command to resolve the dependencies.

Common Causes and Solutions

Here are some common causes of this error and potential solutions:

1. Conflicting Package Versions

  • Check dependency constraints:
    • Open your pubspec.yaml file and examine the version constraints of your packages. Ensure that the specified ranges are compatible.
    • For example, if one package requires version: ^2.0.0 and another requires version: ^1.0.0, there's a conflict.
  • Update packages:
    • Try updating all your packages to their latest stable versions using flutter pub upgrade.
    • Sometimes, newer versions might resolve dependency conflicts.
  • Specify exact versions:
    • If updating packages doesn't work, you can try specifying exact versions for problematic packages in your pubspec.yaml file.
    • However, be cautious as this might introduce other issues in the future.

2. Cached Packages

  • Clear the pub cache:
    • Run flutter pub cache clean to clear the pub cache.
    • This can sometimes resolve issues caused by corrupted or outdated cached packages.

3. Incorrect Flutter SDK or Dart Version

  • Check Flutter and Dart versions:
    • Ensure you're using a compatible Flutter SDK and Dart version.
    • You can check the versions by running flutter --version and dart --version in your terminal.
  • Update Flutter and Dart:
    • If necessary, update your Flutter and Dart installations to the latest stable versions.

4. Corrupted Project

  • Create a new project:
    • In extreme cases, create a new Flutter project and transfer your code manually.
    • This can help isolate the issue and ensure a clean project setup.

5. Detailed Error Messages

  • Provide more context:
    • If the above solutions don't work, provide more details about the error message, including the specific packages involved and any relevant parts of your pubspec.yaml file.
    • This information can help pinpoint the exact cause of the issue.

Additional Tips

  • Use version constraints effectively:
    • Carefully consider the version constraints you specify in your pubspec.yaml file.
    • Use caret (^) for patch and minor updates, tilde (~) for patch updates only, or specify exact versions when necessary.
  • Leverage dependency management tools:
    • Consider using dependency management tools like pubspec_assist or dart_fix to help manage package versions.