简体   繁体   中英

Flutter Package URI doesn't exist inside package's test

Inside the Flutter project directory, I created a package with the following command:

 flutter create --template=package emoji_support

After it completes creating the package and completes flutter get .

But..

Files inisde package's /test directory can't find files inside package's /lib directory :

import 'package:flutter_test/flutter_test.dart'; is resolved ✅

But...

import 'package:emoji_support/emoji_support.dart'; is not resolved ❌

在此处输入图像描述

File structure

在此处输入图像描述

What error am I making here?

I created a package inside my project flutter_example_file_picker with flutter create --template=package emoji_support

在此处输入图像描述

Then in the pubspec.yaml of the project (not the one inside the plugin) flutter_example_file_picker > pubspec.yaml I added to the dependenceis the package

dependencies:
  flutter:
    sdk: flutter
  emoji_support:
    path: ./emoji_support

and the problem resolved, I could run the test with no problem, also tried with a relative path without adding it to the dependencies and worked too

在此处输入图像描述

UPDATE

I think I undestand how to fix it without adding it to the pubspec, when creating a plugin inside a project, the flutter plugin of AndroidStudio (or VS) is still working in the main route (check the terminal dir and it will be C:/.../Workspace_Android\hundreddaysofflutter> so it doesnt detect the inner plugin) and doesn't update to detect the new folder. Even if it's red and says it cannot detect the URI.

You can ignore it and try to run the test and see if it detects the inner dart_tool with package_config.json, then it will run succesfully and the problem will dissapear. The second option is to move to the folder where the plugin is (in the terminal cd my_plugin_name_folder or just file open and open the plugin).

Run flutter get pub (it does it automatically when creting the first time a project but sometimes when you create one inside another it doesnt do it) to run for the first time the package and create the package_config.json inside dart_tool (the dart_tool of the plugin), at the end of the file you can see the name and rootUri of the package, now you can use it in your test nad it should detect it correctly. Sometimes it's generated but it seems it doesn't update correctly and the IDE doesn't know even if it's there.

This is just a problem that occurs, when you are adding new sub_directories in vsCode. just a simple exist and re-open will fix the issue. tell me if that fix it.

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