Flutter web cannot use packages from mobile project - flutter

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 .

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 can you use a Flutter package developed locally as a dependency without having to push the package code every time you make a change?

I am working on a Flutter app that depends on an internal package where common functionality is extracted.
I have the package as a dependency in the pubspec.yaml as follows:
dependencies:
package1:
git:
url: git://github.com/myproj/packages.git
path: packages/package1
Everything works fine, but when I have to make a small change in package1, I have to push the code then run flutter pub upgrade in my project which takes quite a while.
How can I depend on an internal package and be able to do the development without having to push the code of the package every time?
You can write it as this to use a local package
dependencies:
package1:
path: ../packages/package1

Dart package Path_provider_macos has broken classes path

In my flutter project structure settings, the android studio gives me this problem:
Library Dart Packages has broken classes paths:   $home/snap/flutter/common/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-2.0.2/lib [Fix]
Removing this folder and repairing the cache using dart pub cache repair does not help.
This package path_provider_macos-2.0.2 does not have a lib folder even in their repo - https://github.com/flutter/plugins/tree/master/packages/path_provider/path_provider_macos
Every other dart package has that essential lib folder. Maybe it's the package error?
Does anyone know how to fix this?
After a quick look, it seems that using this package is not necessary. As seen in the image below. Therefore I think using path_provider itself should also work for MacOs
Greetz!

Flutter - Cannot find package in .pub-cache reference

I am trying to use tflite_flutter plugin for running a custom ml function from a tflite model. It is working fine on android but for the iOS setup, it requires us to add TensorFlowLiteC.framework on ~/.pub-cache/hosted/pub.dartlang.org/tflite_flutter-<plugin-version>/ios/ folder but I cannot find this folder no matter what I do. It is not just because it is hidden, the tflite_flutter-<plugin-version> folder is not there at all.
I tried:
Adding dependency directly from git.
tflite_flutter:
git:
url: git://github.com/am15h/tflite_flutter_plugin.git
ref: v0.9.0
Running
flutter pub cache repair
flutter pub cache add tflite_flutter
Help would be much appreciated.
use_frameworks!
pod 'TensorFlowLiteSwift'
followed by running pod install in your ios folder.
From official doc
https://www.tensorflow.org/lite/guide/ios
As a developer, you are not bound to using flutter packages only. You can directly add dependencies to your podfile or build.gradle as well.
You'll find your package in ~/development/tools/flutter/.pub-cache/hosted/pub.dartlang.org/

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