Flutter flavouring mobile app and Flutter web - flutter

I am working on a Flutter project where I have a mobile application and a web application both are different e.g. one of them is a client application and the other one is the admin panel. But they have so many common files e.g. models and utils. But their dependencies are entirely different e.g. firebase for flutter(iOS and Android) and firebase for Dart.
I want to share common files between 2 projects but I want to keep their dependencies separate as I don't want to build useless dependencies with another project.
How can I do this? I have good experience with Android Flavouring but I am unable to accomplish this here. can I have separate dependencies for both? I googled and found much data regarding flutter flavors but I couldn't find my answer.

You can try to create a flutter package and share the package between the projects
see
https://flutter.dev/docs/development/packages-and-plugins/developing-packages
create the package (e.g. my_pkg) in folder next to your app folder
move the files you want to share to the my_pkg project
then in your puspec.yaml you can do this
dependencies:
flutter:
sdk: flutter
my_pkg:
path: ../my_pkg/
the only other change in your code would be the import statements of the class that you moved to my_pkg
Hope it answer your question.

Related

Flutter app which uses huawei_push rejected by Google Play Store

I want to use huawei_push kit in my flutter app but Google Play Store rejected my app because of PendingIntent issues (security rules). I want to use the same source code for Google Play Store and Huawei App Gallery. I was thinking of:
building APK based on flavor (huawei push kit dependencies won't be used in built APK),
using different pubspec.yaml files to avoid huawei push kit dependencies in the whole project.
Question:
How can I use huawei_push kit just for Huawei App Gallery still using the same source code for different stores?
Update:
The problem has been reported to R&D Team. And it's expected to be fixed in the next version.
At the same time, we provide a workaround solution. You may refer to this before next version release.(The Flutter plug-in is open source, so you can modify it directly)
Here's how to modify:
1.Open the pubspec.xml file in the root directory and find the plug-in.Like following:
dependencies:
flutter:
sdk: flutter
huawei_location: 5.0.0+301
You need to find the cache directory of the Flutter, for example:
Find the plug-in directory, for example:
If the plug-in points to a directory, for example:
dependencies:
huawei_location:
path: {library path}
directly access the directory.
2.Modify the build.gradle file in the android directory to modify the SDK version on which the file depends.
For example:
implementation 'com.huawei.hms:location:5.1.0.303'
P.S. The PendingIntent issue has been resolved in Push kit 5.3.0.304. So you can directly use this version.
After the modification, run the following command to trigger compilation:
flutter run

Create a flutter project without a web dependence

I want to create a new project in flutter using VS, but I want this project without the web dependence just a mobile app dependence but each time I create a project it gives me the dependence of the web, not a mobile app
For Example, this what I get:
This what I want
You can generate a flutter app for only mobile platforms with flutter create tool by specifying platforms.
flutter create <app_name> --platforms=android,ios
In the same way you enabled flutter web support, disable it.
flutter config --no-enable-web
This removes web support so that future created projects will not generate a web folder. You may need to restart any open editors for the changes to take place.

Web capability with flutter package: mapbox_gl

The mapbox gl package page lists it as suitable for web applications (mapbox_gl).
I tried running the example as a web application, but I encounter the error Error creating mapbox_gl_example|lib/move_camera.ddc.dill
Error creating kernel summary for module:mapbox_gl_example|lib/move_camera.ddc.dill
.
So, my question is, is the flutter package mapbox_gl actually able to be run as a web application as the tags "FLUTTER ANDROID IOS WEB" suggest (is there something I must configure), or is it really not web capable as may be indicated by the fact that the actual description mentions nothing of web capability?
Update: The mapbox_gl flutter plugin now has web support merged into master on Github. If you don't want to wait until web support is released to pub.dev, you can depend on the Github repo directly with this dependency in pubspec.yaml:
mapbox_gl:
git:
url: git://github.com/tobrun/flutter-mapbox-gl.git
Outdated answer: Unfortunately, it doesn't support web yet (although PRs are welcome if you want to contribute). The reason it was listed as supporting web (like many other plugins) was that flutter changed the way plugins declare their supported platforms in the pubspec.yaml file. The mapbox_gl package has since been updated on pub.dev and now correctly shows that it only supports Android and iOS.

How can I import dependencies in flutter web?

I'm setting up a new flutter-web application but I can't add dependencies that I could do in flutter.
for example I want to add font-awesome-flutter to the project but get this error!
font_awesome_flutter: 8.5.0
Because font_awesome_flutter >=8.0.0 depends on flutter any from sdk which is forbidden, font_awesome_flutter >=8.0.0 is forbidden.
So, because salema depends on font_awesome_flutter 8.5.0, version solving failed.
since flutter-web is not still stable and its in technical stage, a simple way for using library in flutter-web which has been working for me is to add the library resources manually. you just need to copy everything inside the lib folder of the library in your own project.
in order to access the library's resources go to https://pub.dev/flutter and search for the library you want and then find the library's github repo in the about section.
flutter_web does not have a plugin system yet. Temporarily, we provide
access to dart:html, dart:js, dart:svg, dart:indexed_db and other web
libraries that give you access to the vast majority of browser APIs.
However, expect that these libraries will be replaced by a different
plugin API.
Source:
https://github.com/flutter/flutter_web/blob/master/README.md
In short, Flutter dependencies are not supported by Flutter Web at this time.

Add flutter web and desktop to existing flutter (android/ios) project in android studio

I know it maybe still early but I want to try and use full flutter existing cross-platform support in one project. Stability is not my main concern.
I have started a flutter project in android studio. Naturally I have (android/Ios) going smoothly. But I would love to add Web and desktop to the same project.
Please help me with and direction, or if there is solution any one has created however much experimental.
There is a migration guide for web here. I got it up and running on a very basic existing app.
Best way is to do it in a separate branch since it requires changing packages and I even deleted .packages and pubspec.lock files first. Then I ran pub get (not flutter packages get) to download the required packages and run some precompilers.