Flutter: Override pub package with a specific commit while retaining dependencies - flutter

We're having a problem with the flutter_html package in our project since upgrading flutter, but there's a potential fix introduced as a PR by other github user. The problem is, I can't get their changes to override the base package, namely because we also use flutter_html_table which relies on flutter_html to resolve its version with flutter pub get
Here's what I've tried using in the project's pubspec.yaml file:
flutter_html: ^3.0.0-alpha.6
flutter_html_table: ^3.0.0-alpha.3
dependency_overrides:
flutter_html:
git:
url: https://github.com/Sub6Resources/flutter_html.git
ref: 6908733505732bff93a5e7d45e822bd837c16c5b
But the changes introduced in the git commit I've referenced as a dependency_override aren't being reflected in the plugin's source code when I inspect it inside the project. This is after I've run a flutter clean to ensure cached versions weren't being used instead.
I've also tried swapping the git/pub.dev versions of the package around, but this fails to resolve when I build the project so I'm assuming it's the wrong approach.
I've also just tried running flutter pub cache repair to ensure the cache is truly wiped, but still has no effect on bringing the changes from the commit into my project.

The issue came from the fact that dependency_overrides only apply to the package that they're defined in. As my project has multiple dependencies (app, core, types, etc.) and I was defining the override in 'core', the 'app' package (which depends on 'core') used the original flutter_html package instead of the overridden one.
Moving the dependency override to my app package's pubspec.yaml resolved the issue :)

Related

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

After cloning any flutter project I can not resolve dependencies?

I want to clone open source projects, I face a hole punch of errors after tapping pub get, all dependencies cannot be resolved and many of the code is out of date, so how can I overcome this?
Please use intl 0.17.0 to resolve the issue
This problem is due to the conflict between dependency versions.
You are using two dependencies that need different version of intl:
flutter_localization
openfluttercommerce
in your pubspec.yaml change the version of intl from 0.16.0 to 0.17.0. It may cause another conflict with other dependencies that may depend on 0.16.0 version of intl. If it accurs, you need to change the version of utilized dependencies to whatever need the same version of intl.
Whenever you clone the project from Github try to open it with flutter sdk version 1.17.0 or 1.22.4 after seeing the first commit of the project then the problem seems to be solved.
but here it seems that you got problem with two dependencies try to resolve that by not mentioning any version in yuml file.

Flutter | Error: Couldn't resolve the package

I created a package that is a collection of my own helper classes for faster developing...
The package also included firebase_analytics: which requires a native implementation for each platform i want it to run. Even if i dont wanted to use firebase at all, but still wanted to use my package i was forced to create firebase-config files for the app, because the app crashes if the firebase_analytics package does not find a valid file for the specific platform. To avoid those things i splitted my package in two packages.
The Core-Package: All helper classes that run native dart code
Optional extension: Only the classes that need the firebase implementation
So if i want to use the package without firebase i just have to depend on the core.
If i want to use the firebase variant i could simply depend the firebase package, because the extension package itself depends on the core-package in its own pubspec.yaml file.
PROBLEM: Since i restructured my package like i described, all my apps that depend on it are not building anymore. The console says that all packages that i depend on in my two packages can not be found. This error occures both ways: With firebase & without.
ERROR: (Scroll down for the complete console output)
MY ATTEMPTS:
"flutter clean" & "flutter pub get" in every package and app folder
"flutter pub cache repair"
CORE-PACKAGE Pubspec.yaml:
FIREBASE-Extension Pubspec.yaml:
Plain Console Output:
pastebin.com/m14cbqDV
Thanks for any help!!
I am facing the same issue while i was making a build in Xcode 13.So I had upgraded my flutter version 2.8.0 to 2.10.2 and also removed the version of all firebase dependencies, then the issue was finally solved.
I have faced similar issues and resolved them by removing package versions. Issues like this often arise due to mismatched versions of packages (eg firebase_core, firebase analytics). Please try to remove versions of the firebase packages or the whole packages. (like firebase_analytics :).
Sorry, my bad! As you can see i moved my dependencys to the dev section of my pubspec.yaml. They should be placed in the dependency section.

How to set version constraints when depending on git packages using Flutter/Dart with versions below 1.0.0?

I am trying to set constraints for git package dependencies with versions below 1.0.0; however, it might also be versions above, but not sure.
Flutter project depends on two packages that we're hosting on git repositories.
We're referencing them in our pubspec.yaml as git packages
According to the Dart.dev dependencies docs: ^0.1.2 is equivalent to '>=0.1.2 <0.2.0'
However, it's always fetching the latest version on github regardless of our version constraints.
Here is how we are referencing package in our pubspec.yaml like this:
my_private_package:
git:
url: ssh://git#github.com-org/my_private_package/my_private_package.git
ref: develop
version: ^0.30.0
For example: If we have a branch in this repo that's versioned 0.32.1 the code above doesn't seem to work(or rather respect the version constraints) and will simply get 0.32.1 version rather than 0.30.x
Does anyone know how to prevent the flutter pub get command from pulling 0.32.1 in this instance? Is the caret constraint not working because we're pulling from a git repository maybe?
Judging by the documentation on pubspec.yaml dependencies, Git dependencies use the ref key to specify the version to pull from the repository. dart pub and flutter pub don't know how to search through your repository for a package version, so the latest commit on the master branch is chosen by default.

Flutter: build runner throws a precompile error

I am using analyser 1.7.1. The latest build_runner build command generates the following error.
flutter packages pub run build_runner build Failed to precompile
build_runner:build_runner:
../../../sdk/flutter/.pub-cache/hosted/pub.dartlang.org/analyzer-1.7.1/lib/src/error/best_practices_verifier.dart:1998:14:
Error: A non-null value must be returned since the return type
'String' doesn't allow null. String get displayString {
The usual flutter clean and pub cache repair commands don't seem to be fixing the problem, and displayString doesn't appear anywhere in my codebase.
There's an issue open 9 days ago. Here's the key part:
Right now, the current state of affairs is that:
package:analyzer 1.7.0 requires package:meta ^1.4.0
package:analyzer 1.7.1 has the same contents as 1.7.0, but requires package:meta ^1.3.0
Flutter stable pins package:meta to 1.3.0
I'm uncertain how we're running into the exceptions above - the two most recent versions of analyzer are pretty explicit about which version of meta they need.
#edlman do you have any dependency_overrides in your pubspec?
you're right, I'm using 3rd party pkgs which depend on meta 1.4.0 so I put it to dependency_overrides to solve the collision. It didn't come to my mind it cause such a problem.
I've changed the override to 1.3.0, it works fine, no problem yet
So I'd suggest checking whether or not there's a dependency_overrides in your pubspec, too.
It's a problem with analyser 1.7.1.
Add
dependency_overrides:
analyzer: 1.7.0
to pubspec.yaml.
There are more details available in raina77ow's answer.