Search code examples
flutterpackagedependencies

Ignore subpackage using Flutter pub?


We're only supporting Android and iOS, but we're getting a version conflict with a web subpackage (maplibre_gl_web) of a package (flutter-maplibre-gl) we're using, namely:

Because every version of maplibre_gl_web from git depends on image ^3.0.2 and flutter_launcher_icons >=0.12.0 depends on image ^4.0.15, maplibre_gl_web from git is incompatible with flutter_launcher_icons >=0.12.0.

Is there a way to resolve this by excluding the unused subpackage?


Solution

  • I don't think there is a direct way to exclude a transitive dependency, but you can use dependency_overrides to override version constraints for transitive dependencies. That is, you should be able to do:

    dependency_overrides:
      image: ^4.0.15
    

    to force all uses of package:image in your dependency graph to use version 4.0.15 (or a compatible version). That is, it would force maplibre_gl_web to use a image: ^4.0.15 dependency.

    Note that doing so might break the maplibre_gl_web package, but since you're not actually using that, that might be okay.

    Alternatively, you could override the maplibre_gl_web dependency itself and point it to an empty package:

    dependency_overrides:
      maplibre_gl_web:
        path: fake_maplibre_gl_web
    

    and then create a fake_maplibre_gl_web subdirectory with its own pubspec.yaml file:

    name: maplibre_gl_web
    publish_to: 'none'
    version: 0.0.0
    

    The empty package approach is a bit more work but would be functionally equivalent to excluding the package. It's also probably a bit safer since it wouldn't override whatever version of the image package flutter_launcher_icons wants to use.