How to test the working of flutter package? - flutter

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.

Related

Flutter project not picking up local flutter package updates

Flutter 3.3.9
I created a flutter project and I reference it as a dependency in another flutter project like so:
dev_dependencies:
flutter_test:
sdk: flutter
my_utils:
path: ../my_utils
When I added the local package to my project initially, I could see and debug the referenced local package just fine. I made updates to the my_utils package, did a "flutter pub get" in the project referencing my_utils, and the changes are not being picked up.
I added a new class to my_utils and it is not finding it in the other project.
I have this in analysis_options.yaml:
include: package:flutter_lints/flutter.yaml
linter:
rules:
depend_on_referenced_packages: false
Setting depend_on_referenced_packages to true didn't help.
How do I make my changes/updates in my_utils show in my referencing project?
Thanks
did you export the files properly ? e.g files inside src/?
my_utils file structure should be like the following:
lib/
...src/
......my_impl.dart
...my_utils.dart
and in your my_utils.dart should contain the following:
export 'src/my_impl.dart';
I recommend you use melos for managing multi-package projects. it might solve your problem. Also with melos bootstrap, you get flutter pub get running in all packages with one command.
you can follow the installation from here

How to add a library to flutter dependencies

I am new in flutter and I want to add Fast Android networking library to flutter dependencies and I don't know how to add, anyone, help me, please.
It is very simple to add a package in flutter dependencies. What you need to do is place it under the dependencies: inside the pubspec.yaml file.
So open the pubspec.yaml. You will find this file in root project folder of your flutter app. And do the following to add new dependencies/libraries:
dependencies:
flutter:
sdk: flutter
# dependencies come below here
example_dependency: ^3.2.0+1 // at the end is the version of the depenency
second_example_dependecy: any // 'any' for any version of the dependecy
To find or discover new libraries for flutter and dart to help you in building your app you can find flutter and dart packages here.
To add http package to your flutter project, from within a terminal at the project root, just type:
flutter pub add http
The latest stable version will be used.
For info on options take a look at https://dart.dev/tools/pub/cmd/pub-add

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 use a flutter plugin locally?

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.

How can I make my Flutter app work also as a module app?

I've created a Flutter standalone app and it's all working fine.
But now I want to integrate some of the screens of that Flutter app in an existing Android/iOS app.
Is it possible?
Yes.
I could make it work by adding this at the end of the pubspec.yaml:
module:
androidPackage: com.teste.embeded
iosBundleIdentifier: com.teste.embeded
Add this and then call a packages get. This will create 2 hidden folders in your project structure: .android and .ios.
Becareful with the identation! This settings must be inside the flutter: tag, like this:
flutter:
uses-material-design: true
assets:
- images/a_dot_burr.jpeg
- images/a_dot_ham.jpeg
module:
androidPackage: com.test.embeded
iosBundleIdentifier: com.test.embeded
After doing this, follow the documentation for the Android/iOS sides (skip the module creating parts).
https://github.com/flutter/flutter/wiki/Add-Flutter-to-existing-apps
You can do that in tow ways:
1- Convert your project to Flutter module and then put that along side the native project and call your FlutterActivity from native
2- Convert your project to Flutter module and make an AAR from it ant import in the native project
Read this Flutter documentation:
https://flutter.dev/docs/development/add-to-app/android/project-setup