解决 depends on flutter from hosted, flutter_test from sdk is forbidden.

9 min read

To solve the issue "depends on flutter from hosted, flutter_test from sdk is forbidden" in Flutter, you can try the following steps:

  1. Check the version of flutter_test in your pubspec.yaml file.

    • Make sure you are using a compatible version of flutter_test with your Flutter SDK version.
  2. Ensure that your pubspec.yaml file includes the following lines:

    dependencies:
      flutter:
        sdk: flutter
    
  3. Run flutter pub get to fetch and update the dependencies.

  4. If the issue persists, you can try deleting the pubspec.lock file and the flutter/.pub-cache folder in your project's root directory. Then run flutter pub get again to re-fetch the dependencies.

  5. If none of the above solutions work, it's possible that you have a conflicting package dependency. In this case, you can try the following steps:

    • Run flutter clean to remove the build cache.
    • Update or remove any conflicting dependencies in your pubspec.yaml file.
    • Run flutter pub get to fetch the updated dependencies.
  6. If the issue still persists, you may need to update your Flutter SDK. Ensure that you are using the latest stable version of Flutter and Flutter packages.

Hopefully, one of these steps will resolve the "depends on flutter from hosted, flutter_test from sdk is forbidden" issue in your Flutter project.