Flutter - how to use packages outside pub.dartlang.org - flutter

I'm trying to use flutterfire_ui for authentication in a flutter app. The developer (invertase) has committed a pull request 9343 on github that fixes some problems. I have pulled it into a local GIT folder. It includes some reorganization of folders, including a package name change - firebase_ui_auth instead of flutterfire_ui. I have changed my local pubspec.yaml to use all the firebase packages in PR 9343 but I get an error with "pub get" as follows that I am unable to resolve.
Running "flutter pub get" in firebase_with_flutter...
Because every version of firebase_ui_oauth from path depends on firebase_ui_auth from hosted and firebase_with_flutter depends on firebase_ui_auth from path, firebase_ui_oauth from path is forbidden.
So, because firebase_with_flutter depends on firebase_ui_oauth from path, version solving failed.
pub get failed (1; So, because firebase_with_flutter depends on firebase_ui_oauth from path, version solving failed.)
In pubspec.yaml I have entered an explicit path to all of the PR9343 firebase packages
firebase_core:
path: C:/GP/project/git-remote/flutterfire/packages/firebase_core/firebase_core/
cloud_firestore:
path: C:/GP/project/git-remote/flutterfire/packages/cloud_firestore/cloud_firestore/
firebase_auth:
path: C:/GP/project/git-remote/flutterfire/packages/firebase_auth/firebase_auth/
firebase_ui_auth:
path: C:/GP/project/git-remote/flutterfire/packages/firebase_ui_auth/
firebase_ui_oauth:
path: C:/GP/project/git-remote/flutterfire/packages/firebase_ui_oauth/
In main.dart android studio reports "invalid URI" for this import
import 'package:firebase_ui_auth/firebase_ui_auth.dart';
https://github.com/firebase/flutterfire/tree/master/packages/flutterfire_ui
Does anyone have any idea what I am doing wrong?

If I add explicit paths to the pubspec.yaml files in my local git repo just as I have for my own pubspec.yaml file then it works and pub get runs without error. So now I have this
firebase_auth:
path: C:\GP\project\git-remote\flutterfire\packages\firebase_auth\firebase_auth\
instead of this
firebase_auth: ^3.6.2
How come it works for the Invertase developer without using path settings and not for me. As well as that, the firebase_auth package is in a "deeper folder"
C:\GP...\packages\firebase_auth\firebase_auth\ than it was before and if I leave off the inner \firebase_auth from the path it doesn't work.
Maybe I'm supposed to use the git mechanism instead of an explicit path setting.

Related

Importing packages from GitHub in pubspec yaml, requires pubspec.yaml file which isnt in the repository

I have issues using flutter pub get with a repository package in my pubspec.yaml file.
dependencies:
flutter:
sdk: flutter
flutter_stripe:
git:
url: https://github.com/flutter-stripe/flutter_stripe.git
ref: poc-use-expensive-androidview
Following the steps provided https://dart.dev/tools/pub/dependencies#git-packages.
However, I am getting the error
Could not find a file named "pubspec.yaml" in https://github.com/flutter-stripe/flutter_stripe.git 7934151fefed73c6a22c253de3a1f1c9d46decc2.
pub get failed (1; Could not find a file named "pubspec.yaml" in https://github.com/flutter-stripe/flutter_stripe.git 7934151fefed73c6a22c253de3a1f1c9d46decc2.)
I have no idea what I am suppose to put for the pubspec.yaml which is not present in the repository. And it works fine if you call the package as it is using flutter pub add flutter_stripe.
The reason I am required to use an unofficial branch is because one of the fields provided by the package is not working correctly, and the suggested solution is to use this branch.
Sorry, my bad, I didnt know that the root of the Hosted package isn't the final path. I was required to add a path to the packages, which can then be found in ./packages/stripe.
flutter_stripe:
git:
url: https://github.com/flutter-stripe/flutter_stripe.git
ref: poc-use-expensive-androidview
path: ./packages/stripe
For anyone who has the same issue as me... or maybe i'm just noob
If you look at the packages of the git project you can see more then one package: https://github.com/flutter-stripe/flutter_stripe/tree/main/packages
You have to choose the package(s) you need.

Getting an error when running "flutter pub get"

I have cloned a Repo of a Flutter project from my developer who has the App working perfectly on his machine, and opened the project in VS Code. I did flutter clean, then flutter pub get, and am getting an error as shown below. AFAIK when I clone the repo, I should get his exact files, so I don't understand how I am getting this error, but he does not? Does anyone know how to fix this? TIA for any and all help.
Because every version of charts_flutter from git depends on logging ^1.0.2 and signalr_client >=0.1.3 depends on logging ^0.11.3+2, charts_flutter from git is incompatible with signalr_client >=0.1.3.
So, because app1 depends on both signalr_client ^0.1.6 and charts_flutter from git, version solving failed.
Running "flutter pub get" in App1...
pub get failed (1; So, because app1 depends on both signalr_client ^0.1.6 and charts_flutter from git, version solving failed.)
The reason is simple
The both two packages depends on one common package
Signalr_client & Charts Flutter packages needs the logging package as a dependency.
See the pubspec file
https://github.com/soernt/signalr_client/blob/master/pubspec.yaml
https://github.com/google/charts/blob/master/charts_flutter/pubspec.yaml
But the versions are different for that.
Solution:
Try to remove the logger package from the pub_cache folder.
remote any one package signalr_client or charts_flutter.
use syncfusion_charts instead of charts_flutter
Try to update the flutter packages

Trying to do a flutter pub get and got Process finished with exit code 66

Running "flutter pub get" in mobile...
Because mobile depends on charts_flutter from path which doesn't exist (could not find package charts_flutter at "../mobile-dependencies/pub.dartlang.org/charts_flutter-0.12.0"), version solving failed.
pub get failed (66; Because mobile depends on charts_flutter from path which doesn't exist (could not find package charts_flutter at "../mobile-dependencies/pub.dartlang.org/charts_flutter-0.12.0"), version solving failed.)
Process finished with exit code 66
/Users/H025712/development/flutter/bin/flutter --no-color pub get
Running "flutter pub get" in mobile...
Because mobile depends on charts_flutter from path which doesn't exist (could not find package charts_flutter at "../mobile-dependencies/pub.dartlang.org/charts_flutter-0.12.0"), version solving failed.
pub get failed (66; Because mobile depends on charts_flutter from path which doesn't exist (could not find package charts_flutter at "../mobile-dependencies/pub.dartlang.org/charts_flutter-0.12.0"), version solving failed.)
Cause: Someone in your team (could be yourself) add a plugin from their local folder. This plugin can't be found when you try to update the dependency.
Quick fix: If you use remote git, let you teammate include that plugin in the project folder, modify the pubspec.yaml path, add it to stage, commit then push. In the case not using git remote, copy those files to your computer in the path as pub spec.yaml suggested.
Ideal fix: Let your teammate use public plugin or share that plugin in private with password, then let flutter download that plugin by flutter pub get/upgrade.
Check your pubspec.yaml is well ordered, I had badly composed dev_dependencies and it failed me
Talked to my tech lead, who is familiar with the code; he said to check out the missing code that was referencing overrides in the pubspec.yaml:
https://dart.dev/tools/pub/dependencies
Dependency overrides
You can use dependency_overrides to temporarily override all references to a dependency.
For example, perhaps you are updating a local copy of transmogrify, a
published library package. Transmogrify is used by other packages in
your dependency graph, but you don’t want to clone each package
locally and change each pubspec to test your local copy of
transmogrify.
In this situation, you can override the dependency using
dependency_overrides to specify the directory holding the local copy
of the package.
The pubspec would look something like the following:
name: my_app
dependencies:
transmogrify: ^1.2.0
dependency_overrides:
transmogrify:
path: ../transmogrify_patch/

Could not find a file named "pubspec.yaml" when auto generating code with build_runner

After I have updated Flutter to v1.22 using code generation with build_runner was not working. I was told that the proper command to use in this version was:
dart pub run build_runner watch --delete-conflicting outputs
However, I receive the following error:
Could not find a file named "pubspec.yaml" in "C:\Users\jpiab\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org\_fe_analyzer_shared-2.2.0".
I have no idea why it is looking for pubspec.yaml in that folder, since that folder is not the current working directory.
--- EDIT ---
The file exists in path:
C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/_fe_analyzer_shared-2.2.0
dart is just looking for it in the wrong place. Any ideas on how to fix it?
I solved for me. I use Android Studio in Ubuntu 20.04.01 LTS.
Firstly run this command:
flutter pub get
After run this command:
flutter packages pub run build_runner build
Or:
flutter packages pub run build_runner watch
Source: https://github.com/flutter/flutter/issues/50092
Deleting the .pub-cache folder.
and then run pub get
Edit:
If above method won't work then delete the folder
C:\Users\jpiab\AppData\Roaming\Pub\Cache\hosted\pub.dartlang.org_fe_analyzer_shared-2.2.0
and then run pub get from within your project directory.
That same error I had and I resolved it by aligning my dependencies. Check if your build_runner is in the same line as flutter_test if you added it to dev_dependencies.
Error Corrected
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: [latest]
My Error
dev_dependencies:
flutter_test:
sdk: flutter
build_runner: [latest]
I fixed it by changing the environment variable PUB_CACHE to the right folder.
TL;DR
Make sure you run the flutter command from the project's root directory.
As you can see, Running the command from a specific folder reproduces this error while everything works as expected from the project's root directory.

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 .