简体   繁体   中英

error: Target of URI doesn't exist: 'package:flutter_test/flutter_test.dart'

A new error has recently appeared in Android Studio for widget_test.dart :

在此处输入图像描述

I am using the most up-to-date flutter version. ' flutter upgrade ' provides the following info:

Flutter is already up to date on channel stable
Flutter 3.0.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 676cefaaff (5 days ago) • 2022-06-22 11:34:49 -0700
Engine • revision ffe7b86a1e
Tools • Dart 2.17.5 • DevTools 2.12.2

I tried 'flutter pub get', 'flutter upgrade', restarting Android Studio, rebooting PC. I tried adding "test:" into dev dependencies in pubspec.yaml as per this question-answer. Nothing fixed the issue. It continues to persist. However, I can run my app and see it workable in emulator.

Any ideas how to fix this anoying error?

Solved. As almost always, human factor.. :)

  1. I checked that I do have this library in the directory where Flutter is installed. -> So logically that the linkage is broken.

  2. I created a new Flutter project. -> there was no such error.

  3. I searched in the 'new project' directory for "flutter_test" -> Such query was found in Dart_Packages.xml file. (obviously, I was not able to find "flutter_test" in my main project directory)

  4. I understood that I need to add manually URI to flutter_test package, as it seems something is broken.

  5. I opened ".packages" file in the project's root directory (don't ask why I opened it and not Dart_Packages.xml - I don't know :)) and added the following line: flutter_test:file:///C:/Src/flutter/packages/flutter_test/lib/

    then "flutter clean" and "flutter pub get" commands -> checked ".packages" file and my line dissappeared from there. -> so it seems "pub get" command breaks something. As "pub get" depends on pubspec.yaml, I compared pubspec.yaml files of two projects -> and surprisingly found this:

dev_dependencie                             тs:
  flutter_test:
    sdk: flutter

with NO error highlighted!

Just in case you don't see it at first sight, as I did :), there shall not be so many spaces and cyrillic letter "т" in 'dependencies' word. :)

Long story short: check whether everything is fine with appropriate part of pubspec.yaml. :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM