Pulling dependencies from an internal repository via pubspec.yaml - flutter

I'm in a corporate firewall which blocks me from pulling packages from pub.dev. However, I was given the option to use an internal repository where I can pull the packages from as tar.gz files.
However, after reading https://dart.dev/tools/pub/dependencies#hosted-packages, I attempted to add this to mypubspec.yaml file:
dependencies:
flutter:
sdk: flutter
http:
hosted:
name: http
url: http://repository.internal-repo.com/repository/googleapis-storage/packages/
version: ^0.12.0+4
If I were to hit the link directly via Chrome (this url is in an internal network) http://repository.internal-repo.com/repository/googleapis-storage/packages/http-0.12.0+4.tar.gz the package downloads as a tar.gz file
But when I run a pub get:
502 notresolvable trying to find package http-0.12.0+4.tar.gz at http://repository.internal-repo.com/repository/googleapis-storage/packages/.
pub get failed (server unavailable) -- attempting retry 1 in 1 second...
I see that you can pull from public Github directly however that is also blocked by our proxy.
Am I doing something wrong here or is this feature not available?

The doc you link says:
or another HTTP server that speaks the same API
I.E. your internal server must implement the pub API. It seems that if you put
http:
hosted:
name: http
url: http://repository.internal-repo.com/foo/
version: ^0.12.0+4
then pub make a request to http://repository.internal-repo.com/foo/api/packages/http It's not clear what it expects to find there.
You may want to unzip your tar file onto a shared drive somewhere and use the path syntax instead, for example (assuming you've unzipped into the http_12_0_4 folder of the pub share and mounted that):
http:
path: /Volumes/pub/http_12_0_4
No version is needed because you've hard-coded that into the folder name.

Related

How to solve problem of git cloning while running flutter pub get for a dependency

I am currently working on an old flutter project. I want to install the necessary dependencies so that i can start making changes.
Now when i run the flutter pub get command, i get a certain error which is not explaining how to solve it.
pub get failed (server unavailable) -- attempting retry 10 in 64 seconds...
Git error. Command: git clone --mirror git://github.com/tekartik/platform.dart C:\src\flutter2\.pub-cache\git\cache\platform.dart-6f0f0462856ed9b1246d3c594e824b1b2d81f000
stdout:
stderr: Cloning into bare repository 'C:\src\flutter2.pub-cache\git\cache\platform.dart-6f0f0462856ed9b1246d3c594e824b1b2d81f000'...
fatal: unable to connect to github.com:
github.com[0: 140.82.121.3]: errno=Unknown error
I think the point reached for downloading the dependency and it is not showing me where i can change from git:// to git#github
Below is a code snippet of the pubspec.yaml file where the dependency is to be installed
tekartik_app_platform:
git:
url: git#github.com:tekartik/app_flutter_utils.dart.git
ref: null_safety
path: app_platform
version: '>=0.1.0'
I am trying to get help on how to solve it because i only just got the code which is an old code and so am not sure where to go and make the fix.
Thank you alot in advance.
Try changing it to:
git:
url: https://github.com/tekartik/app_flutter_utils.dart
path: app_platform
ref: null_safety
More info on the packages can be found under: Dependencies on unpublished packages
https://docs.flutter.dev/development/packages-and-plugins/using-packages
I managed to find the solution. The ref value the project was using is null safety which still uses "git://" which is not being used by github anymore and so that is where the error is coming from.
So i changed to
tekartik_app_platform:
git:
url: git#github.com:tekartik/app_flutter_utils.dart.git
ref: dart2_3
path: app_platform
version: '>=0.1.0'
If this is the case for adding the plugin dependecy in flutter by git reference
Make sure you have public access for the same repository. if private then go to bottom of general setting and make it public.

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.

How to use a fork of flutter.widgets in a flutter project?

Found this article, that seems like it would give sufficient instructions for using forked versions of many pub packages.
However, the package I want to fork (scrollable_positioned_list) is a part of a the flutter.widgets repository, which is not a package itself, but a collection of packages.
I've been able to fork and modify the package, my trouble is being able to use my fork in my project.
I've tried the obvious:
dependencies:
flutter:
sdk: flutter
scrollable_positioned_list:
git:
url: https://github.com/bendelonlee/flutter.widgets
This causes flutter pub get to fail with the error:
pub get failed (1; Could not find a file named "pubspec.yaml" in https://github.com/bendelonlee/flutter.widgets 1f2935687390a9315c3336007a4eac00563365a4.)
Indeed, there is no pubspec.yaml in the root of that directory, though there is one nested in the package.
I've also tried using the url of the package inside the repository
scrollable_positioned_list:
git:
url: https://github.com/bendelonlee/flutter.widgets/tree/master/packages/scrollable_positioned_list
This fails with an error complaining that the repository isn't found:
fatal: repository 'https://github.com/bendelonlee/flutter.widgets/tree/master/packages/scrollable_positioned_list/' not found
The path argument should be added just as the official docs state:
Pub assumes that the package is in the root of the Git repository. To specify a different location in the repo, use the path argumen
In your specific cace this would be
scrollable_positioned_list:
git:
url: https://github.com/bendelonlee/flutter.widgets
path: packages/scrollable_positioned_list

I am wondering how to use pub get and package download when using the internal network in Flutter

The company currently uses the internal network IP.
So I want to know the package download port and url address to use pub get.
What IPs and ports must the firewall allow to use package download?
You can link git repositories in your pubspec.yaml like this:
dependencies:
plugin1:
git: https://github.com/flutter/plugin1.git
Or you can link a private hosted package like this:
dependencies:
plugin1:
hosted:
name: plugin1
url: http://your-package-server.com
You can find more examples and a more detailed explanation here

Error when running pub get: Failed to rename directory because it was in use by another process

I get the below error when I try to get packages of beautifulsoup in my dart console project.
[scrape_3] pub get
Resolving dependencies...
+ beautifulsoup 0.0.1
Downloading beautifulsoup 0.0.1...
Failed to rename directory because it was in use by another process.
This may be caused by a virus scanner or having a file
in the directory open in another application.
exit code 1
My pubspec.yaml file is as follows:
name: scrape_3
description: A sample command-line application.
# version: 1.0.0
# homepage: https://www.example.com
environment:
sdk: ">=2.10.0 <3.0.0"
#dependencies:
# path: ^1.7.0
dev_dependencies:
pedantic: ^1.9.0
test: ^1.14.4
dependencies:
beautifulsoup: ^0.0.1
html: ^0.13.3+3
How can I solve this? this is a recurring error for me and happens often.
Just reset changes on your "pubspec.lock".
Or simply delete it.
Shutting down PC and starting it back on after some minutes eventually worked. Apparently, the file stays in use by VS CODE itself for a while and direct Restarts don't work
I had to close VSCode, open it as Admin, then run flutter get again.
As an extra precaution I had also made sure I didn't have any of the flutter/dart tools running in command lines, powershell etc and no File Explorer windows open.
If you using android studio
1.restart you laptop/pc.
2.close your antivirus if exist.
3.run android studio as administration and try again.