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

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.

Related

Unverified breakpoint in VSCode in Flutter

My debug mode does not work as I see the unverified breakpoint notice in VSCode in debug mode.
I already checked the Launch json file and it is fine, but something else is wrong which I do not see what it is. Maybe something related to paths, etc.
I tried to make a new project in VSCode using the command and the new default Flutter project is OK.
So it seems like, if I can make a fresh project from my current project then my problem could be solved. But how? I tried to move my files from my current project to the newly made Default Flutter project but I do not think this is the way. Because I guess some of the files in my project are the source of issues...
I already deleted .vs file but no help.
Do you have any good idea how to fix this issue?
First try cleaning the project files using flutter clean then flutter pub get, try running the app without debugging and if you are down for making a new one just move the lib and assets folders and copy the content of pubspec.yaml file.

Weird output from "flutter clean" command when used outside folder that has build

When i run flutter clean a folder outside the main build folder. I this response:
Changing current working directory to: /User/..
Why is that? and what does working directory refer to? How do i know my old one?
There needs to be a yaml file for flutter clean to work correctly.
That was my mistake.

Flutter only release app is crashing when I push chat screen in firebase Also i have change package name before

Am trying to release my apk and just changed the com.example package name to my own com.[companynamehere].[appname] in the AndroidManifest.xml file and app/build.gradle file, however now my app stops working as soon as I run it.
Any idea what might be the problem? Is there anywhere else I need to change the package name?
I'm also using firebase and I generated a new google-services.json file with the new package name.
Update your package name in android>src>main>kotlin>Mainactivity.kt
Hope it will work. If it doesn't work then another solution is to search your old package name on the entire project and replace them with the new package name. In this case, VSCode will help you to do this just with a few clicks.

How to create/provide multiple example apps for a flutter plugin?

Flutter seems to have a very strict/rigid structure for plugins with example folder and all contents inside that folder.
I want to provide multiple examples with my plugin. Something like examples folder and then examples/demo1 and examples/demo2 as two different app examples.
I tried doing this but flutter run or pub get command breaks with this change. it's gets stuck with below error which wasn't thrown with exact same code in previous structure before change. Also my app actually follow embedding v2 code so this error is completely false too.
The plugin `<MY PLUGIN>` requires your app to be migrated to the Android embedding v2. Follow the steps on
https://flutter.dev/go/android-project-migration and re-run this command.
Somehow is it expecting that there should be only one example and that too with example folder only ?
Can someone help, and if possible point me to a plugin project where it's using multiple examples ?
After trying multiple ways to deal with the situation,
I ended up with a good enough solution.
I moved entire flutter repo inside an sdk directory, and then Introduced a samples folder at root level which can contain multiple sample applications.
sdk itself has a default sample app under example folder which I kept so sdk can ship with one example project.
Final structure look like below,
- Root
- sdk
- Flutter plugin project (like android/example/ios/lib directory etc.)
- samples
- sampleOne
- sampleTwo
I then mentioned relative path to sdk for sampleOne or sampleTwo inside their pubspec.yaml like path: ../../sdk/
When I want to open sampleOne in AndroidStudio, I import sampleOne directory and it works like charm. Make sure you don't import entire samples directory or sampleOne/Android.
For any regular Flutter commands for plugin, I run them inside sdk directory and everything works fine as expected. So I would run publish or pub get inside root/sdk directory

How to develop Flutter app and related package at same time in VS Code

I have a Flutter app and a package folder loaded in VS code at the same time within a workspace. What entry do I need to make to my app's pubspec.yaml file to ensure that changes I've made to the package are compiled and included whenever I hot reload or restart the app? What would be an alternate strategy if this is not possible?
If your pubspec.yaml refers to your package with a path then I would expect this to happen automatically. If not, I would consider it a bug. Please file an issue at https://github.com/Dart-Code/Dart-Code and include a log file generated by running the Dart: Capture Logs command and as much info about your project layout as possible (a clonable repo to repro would be perfect).