dependency_overrides for dependency with path dependency - flutter

In Flame we have a monorepo with Flame and its bridge packages and all of the bridge packages has Flame as a path dependency (not when they are released). It doesn't seem to be possible to depend on our main branch and on a bridge library on the main branch at the same time, I have this in the pubspec.yaml file:
dependencies:
flutter:
sdk: flutter
flame:
git:
url: git#github.com:flame-engine/flame.git
path: packages/flame
ref: main
flame_fire_atlas:
git:
url: git#github.com:flame-engine/flame.git
path: packages/flame_fire_atlas
ref: main
dependency_overrides:
flame:
git:
url: git#github.com:flame-engine/flame.git
path: packages/flame
ref: main
When doing pub get I get:
Error on line 15, column 11: Invalid description in the "flame_fire_atlas" pubspec on the "flame" dependency: "../flame" is a relative path, but this isn't a local pubspec.
╷
15 │ path: ../flame
│ ^^^^^^^^
╵
pub get failed (65; ╵)
which indicates that the dependency_override wasn't used, is it not possible to override path dependencies?

Apparently this is a bug in pub, the only way to solve it for now is to clone the dependencies that you need to the path that the packages expect them.
So in this case I would have to clone the branch of flame that I want to use to ../flame, in relation to the projects pubspec file.

see this this solution it may help you.

Related

How can I clone a plugin repository and use the modified repository in my code

I want to clone a repository to my github account Repository link, then I want to make changes to the code and use the updated project in my vs code project.
For now i have only forked the repository and using it like this
dependencies:
hive: ^2.2.3
hive_flutter: ^1.1.0
flutter:
sdk: flutter
flutter_osm_plugin:
git:
url: https://github.com/tulip/osm_flutter
#flutter_osm_plugin: ^0.42.0
I get the following errors
[rider] flutter pub get
Waiting for another flutter command to release the startup lock...
Running "flutter pub get" in rider...
Resolving dependencies...
Error on line 20, column 11: Invalid description in the "flutter_osm_plugin" pubspec on the "flutter_osm_interface" dependency: "./flutter_osm_interface" is a relative path, but this isn't a local pubspec.
╷
20 │ path: ./flutter_osm_interface
│ ^^^^^^^^^^^^^^^^^^^^^^^
╵
pub get failed
command: "/Users/pannam/development/flutter/bin/cache/dart-sdk/bin/dart __deprecated_pub --directory . get --example"
pub env: {
"FLUTTER_ROOT": "/Users/tulip/development/flutter",
"PUB_ENVIRONMENT": "vscode.dart-code:flutter_cli:get",
"PUB_CACHE": "/Users/tulip/.pub-cache",
}
exit code: 65
exit code 65
Do i need to create a local repo in my device, using Mac, if so can you please let me know where i am going wrong? I tried searching in the internet and followed the steps but to no vail.
I review your issue. Try the below thing inside your plugin's pubspec.yaml.
dependencies:
flutter_osm_interface:
git:
url: https://github.com/jesussmile/osm_flutter/tree/master/flutter_osm_interface

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

How to develop a plugin with subdirectory as dependency in flutter?

I came across several plugins with the following structure:
my_plugin/
my_plugin_platform_interfance/
my_plugin_web/
README.md
Inside the main implementation, the file my_plugin/pubspec.yaml depends on both:
my_plugin_platform_interface: ^1.0.3
my_plugin_web: ^1.0.10
But I need to make change in both my_plugin_platform_interface and my_plugin_web.
I am not sure if this is the correct thing to do (but it feels wrong): I just commented these two lines and replaced with:
Please tell me if there is a proper way than this
my_plugin_platform_interface:
path: ../my_plugin_platform_interface/
my_plugin_web:
path: ../my_plugin_web/
I finished the change but I am not willing to publish it to dart pub. I just want to use it as a git repo directly.
So in my project I added:
my_plugin:
git:
url: git://github.com/TSR/my_plugin.git
ref: my/branch
path: my_plugin
But now I get the following error:
Flutter pub get
Running "flutter pub get" in my_project...
Error on line 18, column 11: Invalid description in the "my_plugin" pubspec on the "my_plugin_platform_interface" dependency: "../my_plugin_platform_interface/" is a relative path, but this isn't a local pubspec.
╷
18 │ path: ../my_plugin_platform_interface/
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
╵
pub get failed (65; ╵)
exit code 65
So does this mean I should also edit my plugin dependency to
my_plugin_platform_interface:
git:
url: git://github.com/TSR/my_plugin.git
ref: my/branch
path: my_plugin_platform_interface
my_plugin_web:
git:
url: git://github.com/TSR/my_plugin.git
ref: my/branch
path: my_plugin_web
This feels even more wrong. Can someone tell me if there is a proper way to do this

Flutter - Add pub package in pubspec.yaml

I want to add this package in flutter project. Why this charts? Because it´s have a negative bars
I try to add something like this
charts_flutter:
git:
url: git://github.com/jeroentrappers/charts.git
path: charts/charts_flutter/
name: charts
ref: master
But return
Could not find a file named "charts/charts_flutter/pubspec.yaml" in
git://github.com/jeroentrappers/charts.git
ee7a2110386f7b3e6476eb9ff815c11a65875195.
So what is the correct way to add this type git packages?
This should work
charts_flutter:
git:
url: git://github.com/jeroentrappers/charts.git
path: charts_flutter
ref: master
The path is relative to the repository and charts_flutter is a root directory in the repository.
name is redundant if it's the same as the dependency itself.
Update
In the GitHub repo the charts_flutter pubspec.yaml is set up for development and can't be used as Git dependency because it contains a path dependency
dependencies:
charts_common:
path: ../charts_common/
That this dependency can not be overridden by dependency_overrides looks like a pub bug to me.
dependencies:
charts_flutter:
dependency_overrides:
charts_common:
git:
url: git://github.com/jeroentrappers/charts.git
path: charts_common
ref: master
charts_flutter:
git:
url: git://github.com/jeroentrappers/charts.git
path: charts_flutter
ref: master
A workaround would be to clone the GitHub repo to a local directory and use a path dependency instead.
dependencies:
charts_flutter:
path: ../../charts/charts_flutter