Search code examples
flutterdartflutter-dependenciesflutter-html

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


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.


Solution

  • 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 :)