is it possible to compile the flutter library - flutter

I am write a flutter public lib, before I commit the code to the repo, I want to compile the whole project. Sometimes I want to make sure all code could compile, for example, after you changed the function the IDE may not give obviously tips somewhere going wrong, is it possible to compile the project? when I am developing a app I could run it, but when I develop a public library I do not know how to run it and check the whole project.

When making a public package, you should include an example project within it. It's basically a new flutter project that sits inside the pub project, typically under "example" folder. You can take a look at one of my packages here on GitHub, to get an idea of the folder structure.
If you click into example folder, you will see a complete Flutter project on its own. It has its own pubspec.yaml as well, and refers to the "parent folder" to use the pub package as a demo.
dependencies:
flutter:
sdk: flutter
animated_flip_counter:
path: ../

Check the docs about writing packages. https://docs.flutter.dev/development/packages-and-plugins/developing-packages

Related

How to use flutter plugin, that I created, in my flutter app as local plugin

I have created a flutter plugin for android and ios and I want to use that plugin in my flutter app locally. I don't want to upload it to pub.dev but to use it locally in my flutter app. I searched a bit and I found that I can use external packages locally but I didn't find anything about a plugin. These are directories under my plugin package all_pdf_tools:
Out of these which directory do I need to move to my flutter app directory and then how should I declare it to use it in my pubspec.yaml and then how can I use my plugin's methods in the flutter app.
Thank you.
Make sure that your Flutter app and plugin are in sibling folders.
The add a dependency in pubspec.yaml of your Flutter app:
dependencies:
all_pdf_tools:
path: ../all_pdf_tools
This tells your Flutter project to look for your plugin at the relative path, rather than in pub or a local git repo.
(If you look in all_pdf_tools/example/pubspec.yaml you'll see this is how the example app refers to its plugin by using path: ../)

How to add a second example app to a Flutter plugin project?

When creating a plugin project in Flutter, an example app, that is using the plugin, is added in a subfolder of the plugin project. What needs to be done to add a second "example" app to the plugin folder?
So far I have:
Copied and renamed the example folder to (let's call it) app2.
Adjusted the package names at the android manifest files of app2.
Renamed pluginrootfolder/app2/pluginname_example.iml to pluginrootfolder/app2/pluginname_app2.iml (to reflect the name of the second app).
In the .iml file of the plugin project (the root folder):
Copied and adjusted the exclude folder directive to reflect app2
<excludeFolder url="file://$MODULE_DIR$/app2/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/app2/.pub" />
<excludeFolder url="file://$MODULE_DIR$/app2/build" />
Run Flutter clean and Flutter pub get in both the plugins root directory and app2's directory.
Problem now is that app2 causes 1k+ Target of URI doesn't exist: error messages - from packages (like provider and json_annotation) to classes in the plugin's root project.
Do you have any ideas what's wrong here or how to fix it?
Firstly, please give a full GitHub reproducible repository and link it here so I can examine. And also paste (e.g. using github gist) the long log. Please comment to this answer so I can examine more.
"In the .iml file of the plugin project (the root folder)" - indeed not that needed. iml is for intellij idea, and is unrelated to flutter. so should not error even with wrong iml. You can even safely delete iml and when you import that module in intellij it will auto recreate.
Have you modified pubspec.yaml? e.g. the package name in it.
And, where is your plugin located, relative to your app2? In example app, the default pubspec.yaml uses path: ../ to point to your plugin. So if your app2 does not have .. as the plugin path you should change this as well.
Anyway, paste your log and give a reproducible sample please...
I suspect your issue is in the dependency tree. Your example2 project does not seem to point to the project above it. The only manual edits you need are in the pubspec.yaml. In the dependencies for the second example project.yaml file, include the path to the root project. For example:
dependencies:
<YOUR_ROOT_PROJECT>:
path: ../
flutter:
sdk: flutter
Including that should map the decencies of the root over with pub.get.
That should take care of the Target of URI doesn't exist errors.
Since you are using .iml files, I assume you're using an IntelliJ/JetBrains IDE. Creating example subprojects can be done without all of the manual work you listed.
You don't have to copy the files themselves manually to create a second example. You can simply right-click on the project root and select new module. Choose Flutter. The project type is Application.
Secondly, you don't have to add the second project to the exclude folders.

How to add a new flutter project as a IntelliJ module in a larger project

I have a single INTELLIJ project, with 4 java modules and 4 python modules, each is also pretty much a separate sub-project in gradle. Now, in an isolated module in the same project I want a flutter app.
Eventually I might want to make custom gradle tasks to run flutter as a subproject so that I can build all from gradle but that is way down the road. Right now I'm trying to get the intelliJ flutter plugin to work with the flutter project as a module (instead of the base folder, one level down, app/flutterApp/[Anything Flutter Needs]).
The dream is to have these 9 projects in the same folder, master project, git and build pipeline as a single set without losing functionality... if it can happen without touching android studio even better.
Instructions (So far):
File - new - module, then select flutter.
Add the module in project structure so it's inline with the others (use dot notation to signify module groups/folders).
Add "Dart SDK", "Dart Packages" and "Flutter Plugins" Dependencies in the said tab of the module.
Set the flutter sdk location (File - Settings - Languages - Flutter)
RUN main.dart: This allows the flutter plugin to recognize it; sadly after figuring the rest out, this is what thwarted the effort.

Can we create shared library or assembly like .dll in flutter package project?

I'm getting problem with flutter/dart. I created one flutter-package using dart lang, there is so many dart files. But i didn't get any option to make single lib file or assembly like dll (dll in Xamarin). I want to use that API in flutter mobile app [Android/iOS]. So is it possible to make single lib file in dart ? I don't want to show a source code to that person, who will use my API in Android/iOS & I don't want to publish my code to pub.dev.
I hope this is possible.
Thanks, i would be grateful.
You can store your package on your git repository and access them.
If the package is located at the root of the repo, use the following syntax:
dependencies:
plugin1:
git:
url: git://github.com/test/plugin1.git
https://flutter.dev/docs/development/packages-and-plugins/using-packages

how to modify a dart/flutter package?

I want to use a dart package. Currently its under dependencies in pubspec.yaml. And it works fine. However I need to make a few minor changes to the package. Do I need to import the whole package into my project and make changes there or is there an easier way?
You should clone the package from it's own repository and then just import it using the path instead. For example, if you have let's say, a package called foo: ^1.0.0 and want to modify it:
Go to it's GitHub project and clone it to somewhere in your machine;
Change the path in your pubspec.yaml to:
foo:
path: [your package path]
Have in mind that if you have the project stored in VC, the reference won't work and thus you should always point to a remote dependency unless it's shipped with your app as well (eg. path: ../dependency).