Home > OS >  Is there any way to remove Transitive dependency in flutter?
Is there any way to remove Transitive dependency in flutter?

Time:01-27

I have a very frustrating problem in which two different packages define same function name showModalBottomSheet

I was(am) using this awesome flutter package https://pub.dev/documentation/country_code_picker which has a transitive dependency modal_bottom_sheet that defines showModalBottomSheet.

After upgrading to last flutter version 3.7 I cannot run my app because flutter material defines itself another showModalBottomSheet function. This creates compilation errors because doesn't know which one to use from the 2 different imports.

Error (Xcode): ../../../.pub-cache/hosted/pub.dev/modal_bottom_sheet-2.1.2/lib/src/bottom_sheets/bar_bottom_sheet.dart:102:13: Error: 'ModalBottomSheetRoute' is imported from both 'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'.

Is there a way to to configure pubspec and say it to ingore https://pub.dev/packages/modal_bottom_sheet from all the transitive dependencies ?

That way I avoid the issue and the app will run fine.

PS: I looked into other Newer libraries for country picker but they did not support all the features of the existing ones so best and shortest solution would be to ignore(not install) the package above

CodePudding user response:

It is a known issue. A fix has been merged. You can either wait for the package author to publish an update, or you could try using the package from git:

  modal_bottom_sheet:
    git:
      url: https://github.com/jamesblasco/modal_bottom_sheet.git
      ref: main

Note: According to OP (via comment), the above did not work, but the following does:

dependency_overrides:
  modal_bottom_sheet:
    git:
      url: https://github.com/danReynolds/modal_bottom_sheet.git
      path: modal_bottom_sheet
  • Related