How to use a flutter plugin locally? - flutter

Let's say we have created a plugin with flutter. Named flutter_local_plugin.
How can we put it inside a flutter project flutter_some_application and access it?
There is a question here (how to use local flutter package in another flutter application?), but the accepted answer has 0 explanations regarding the actual file migrations.
we only need the plugin to be placed inside the flutter_some_application, without any example from the package project.
Where do you place the .kt & .dart files, and how do you link all of this together?
There seems to be no guide on how to achieve this.

I created a flutter plugin by Android Studio 4.0 which name is printer.
We can get a tip at the pubspec.yaml:
printer:
# When depending on this package from a real application you should use:
# printer: ^x.y.z
# See https://dart.dev/tools/pub/dependencies#version-constraints
# The example app is bundled with the plugin so we use a path dependency on
# the parent directory to use the current plugin's version.
path: ../
Then I use printer locally in another flutter project:
printer:
path: ../printer/
After pub get I found printer added in .flutter-plugins & .flutter-plugins-dependencies automatically.

Related

How to use a specific version of flutter for build apk, when i have 2 version of flutter install?

So i am installing both version of flutter, version 2 and, 1.22.6 , i want to build apk for my 1.22.6 project, but flutter automatically call the version 2 for building apk, this create error, what should i do?
Try using this Flutter version manager
You can create alias for Flutter and point to different version
for example
flutter will call flutter 1.22.6
flutterd will call flutter 2 instead
so when you want to build for 1.22.6 just use flutter
I have write a article, sadly in Thai not translate yet, how to have 2 different version of Flutter and how to make alias to call different version here
https://medium.com/kbtg-life/%E0%B8%A3%E0%B8%B9%E0%B9%89%E0%B8%88%E0%B8%B1%E0%B8%81-flutter-2-0-%E0%B8%81%E0%B8%B1%E0%B8%99%E0%B8%A3%E0%B8%B6%E0%B8%A2%E0%B8%B1%E0%B8%87-%E0%B9%81%E0%B8%A5%E0%B9%89%E0%B8%A7%E0%B8%97%E0%B8%B3%E0%B8%A2%E0%B8%B1%E0%B8%87%E0%B9%84%E0%B8%87%E0%B9%83%E0%B8%AB%E0%B9%89%E0%B9%80%E0%B8%84%E0%B8%A3%E0%B8%B7%E0%B9%88%E0%B8%AD%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B2%E0%B8%A1%E0%B8%B5%E0%B8%97%E0%B8%B1%E0%B9%89%E0%B8%87-2-%E0%B9%80%E0%B8%A7%E0%B8%AD%E0%B8%A3%E0%B9%8C%E0%B8%8A%E0%B8%B1%E0%B8%99-de861c810d57?source=your_stories_page-------------------------------------
so after you this, you can just run
flutter build
I also faced same problem in the past. So what I did was, I downloaded both versions of flutter say (flutter2.2 and flutter1.22). And I have kept them in same folder. Now if I want to use flutter 2.2 then I'll rename "flutter2.2" folder to "flutter" and If I want to use flutter1.2 then I'll rename the "flutter1.2" folder to "flutter"
In the environment variable path I have set the path to "flutter/bin" so if I rename flutter2.2 to flutter then my environment variable will automatically take 2.2 version.
You may need to restart your PC after changing the version.
The simple way is:
Download the version of Flutter you need and put it in the place where Flutter is installed
In this directory you have "flutter" folder.
In Ubuntu, it is usually located in this path:
/home/username/development/flutter
To develop the software with the desired version, just change the desired folder name to "flutter".
For example :
flutter --> flutter-2.x.x
flutter-3.x.x ---> flutter

Error setting-up flutter_localizations package "Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'."

This error appears when I try to add language support to my flutter application:
Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/app_localizations.dart'. Try creating the file referenced by the URI, or Try using a URI for a file that does exist.
I’m using flutter_localizations, the project is built with dart 2.7.0
It seems that flutter_localizations needs latest sdk which is dart 2.13.0
How can I fix this?
I had this same issue with import 'package:flutter_gen/gen_l10n/app_localizations.dart' in Visual Studio Code after updating to Flutter 2.5.
After closing the VS Code window and reopening it, the error was gone.
If that doesn't work, try closing and opening VS Code again.
Or restart the Dart Analysis Server by going to View > Command Palette and then typing Dart: Restart Analysis Server.
Credit goes to https://stackoverflow.com/a/68150402/4797855 and https://stackoverflow.com/a/68731436/4797855.
Open Command Palette and select Dart: Restart Analysis Server.
Just type in the project terminal flutter gen-l10n it will solve your problem.
Also, in the pubspec.yaml file, enable the generate flag. This is added to the section of the pubspec that is specific to Flutter, and usually comes later in the pubspec file.
# The following section is specific to Flutter.
flutter:
generate: true # Add this line
just in Your terminal run this
flutter pup add flutter_gen/gen_l10n
It fixed my app
I had this issue before, and I tried to solve it by adding charts_flutter to my pubspec.yaml but it didn't solve my.
Lucky me, charting library recently released a new version which is compatible with flutter 2.5. I didn't need to add anything to my pubspec(I removed chart_flutter from my ). just run the app even if the compiler shows an error saying Target of URI doesn't exist for the import line. The system is going to generate that file on runtime.
Be sure that there's an l10n.yaml file in your project root as follows.
Example
Demonstration variables
foldername = l10n
defaultIntlFile = intl_en.arb
importFileName = app_localizations.dart
Import
import 'package:flutter_gen/gen_l10n/importFileName';
l10n.yaml
arb-dir: lib/foldername
template-arb-file: intl_en.arb
output-localization-file: app_localizations.dart
Structure
lib/foldername/defaultIntlFile
The solution in my case:
"If you are using a package flutter_gen you need to remove it from pubscpec.yaml to resolve conflict." credit Target of URI doesn't exist: 'package:flutter_gen/gen_l10n/gallery_localizations.dart'

How to use libflutter_linux_glfw.so file and related files from out/host_debug of flutter engine

I followed instructions from Setting up the Engine development to build the flutter engine. Purpose of this was to use the texture support from Texture support for glfw. I could compile the flutter engine.
Next I wanted to use this engine and develop Texture based application. While compiling using the following command, I see that libflutter_linux_glfw.so and other platform files are copied from flutter/bin/cache/artifacts/engine.
flutter build linux
I added the dependency_overrides to pubspec.yaml as follows. But, no luck.
dependency_overrides:
sky_engine:
path: <base folder of engine>/engine/src/out/host_debug_unopt/gen/dart-pkg/sky_engine
sky_services:
path: <base folder of engine>/engine/src/out/host_debug_unopt/gen/dart-pkg/sky_services
Looking forward for the suggestions on the changes required to use files from engine/src/out/host_debug_unopt.
I could use compiled libflutter_linux_glfw.so by using --local-engine-src-path and --local-engine options of flutter given in the following link.
Using a locally-built engine with the flutter tool

Flutter web cannot use packages from mobile project

A few months ago I made an android application using flutter. The application requires various dependencies such as intl, cached network image, stopper, carousel_slider, etc.
Then right now I want to convert the project to flutter_web. Here are the steps that I did:
clone github web flutter
I run the command "flutter packages pub global activate webdev"
Then I edited pubspec.yaml and I adjusted it to pubspec.yaml in the previous project (android project)
Here is the contents of pubspec.yaml on the web flutter project:
name: flutter_web.examples.hello_world
environment:
  # You must be using Flutter> = 1.5.0 or Dart> = 2.3.0
  sdk: '> = 2.3.0-dev.0.1 <3.0.0'
dependencies:
  flutter_web: any
  flutter_web_ui: any
  stopper: ^ 1.0.1
dev_dependencies:
  build_runner: ^ 1.4.0
  build_web_compilers: ^ 2.0.0
dependency_overrides:
  flutter_web:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages / flutter_web
  flutter_web_ui:
    git:
      url: https://github.com/flutter/flutter_web
      path: packages / flutter_web_ui
  provider:
    git:
      url: https://github.com/kevmoo/provider
      ref: flutter_web
When I run 'pub dev', an error occurs while resolving the package stopper. Then I tried to open github from the package stopper (https://github.com/aryzhov/flutter-stopper), after that I checked the files in the lib folder. There I found a file called stopper.dart. It turns out that in the file, still using
 import 'package: flutter / material.dart';
So that makes my pubspec error. Because the code should be replaced with
import 'package: flutter_web / material.dart';
Therefore, I tried to outsmart the problem by removing the dependency stopper on pubspec.yaml, then I created a stopper.dart file manually, then I saved it in the lib/mypackages folder. After that, I import stopper.dart from the lib/mypackages folder (it's no longer through the package).
The package stopper is just one of the packages that I use on my Android project. Actually there are many other packages that have the same problem as the package stopper. The point is I have to create the package files manually, then I change "package: flutter / ..." to "package: flutter_web /" manually, then I can import them.
What I want to ask, is there a more elegant and simple way?
Hi the instruction you are following is from an old repository here. As you can see this is discontinued. You can find the informaiton in the REadme.
Instead you should follow the instructions in this page. Read it once carefully and I would suggest to keep a backup of your main project and work on a copy.
First you will have to enable the flutter-web using flutter config --enable-web.
Then you will have to run flutter create .

How to test the working of flutter package?

What would be the best practice to test the working of flutter package?
Recently I developed a Flutter package and I am testing its functionality by creating another flutter application and importing it to there, in this way I have to deal with two projects. Is there any method to do all it in the same project like android native development?
example/ directory contains only example.dart which is not runable? Any suggestion ?
Answer based off of Shahzad's flutter_tex package, and thanks to Remi's suggestion.
As mentioned, one way to test a package in Flutter is to create a Flutter app within the "Example" directory. In this app, list the following in the pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
your_package_name:
path: ../
As shown, you specify your package's path, which is the level above the "Example" folder the test app resides in.