2

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

Kristi Jorgji
  • 1,154
  • 1
  • 14
  • 39
  • Thanks. The problem is not the country code picker itself, but a library being used by the code inside the country code picker... `'ModalBottomSheetRoute' is imported from both 'package:flutter/src/material/bottom_sheet.dart' and 'package:modal_bottom_sheet/src/bottom_sheet_route.dart'.` The later, modal_bottom_sheet package is a dependency of the country_code_picker package not of my app – Kristi Jorgji Jan 26 '23 at 18:00
  • You can use [`dependency_overrides`'](https://dart.dev/tools/pub/dependencies#dependency-overrides) to point to a copy of the package (possibly local) that includes a fix for the problem. – jamesdlin Jan 26 '23 at 18:10

1 Answers1

2

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
Chuck Batson
  • 2,165
  • 1
  • 17
  • 15
  • Yep. OP, it is always a good idea to check the issue section on GitHub for the package giving you the problem. – GrahamD Jan 26 '23 at 18:05
  • Thank you both for the replies. The solution above with using package from git did not work `Could not find a file named "pubspec.yaml" in https://github.com/jamesblasco/modal_bottom_sheet.git 42da8b016ca254c1a4fa01be2edbef2cadd71bd2. pub get failed` – Kristi Jorgji Jan 26 '23 at 19:12
  • But the solution with dependency override mentioned in the github issue worked `dependency_overrides: modal_bottom_sheet: git: url: https://github.com/danReynolds/modal_bottom_sheet.git path: modal_bottom_sheet` – Kristi Jorgji Jan 26 '23 at 19:15
  • 1
    I also understood the logic here. I am using the last version of modal_bottom_sheet library by Jamesblasco and ignoring the version of this library imported by country_code_picker. It is a workaround because the guy that implemented country_code_picker deprecated(archived stopped work) on his library and will probably never update to new modal_bottom_sheet package. Still I am very happy for resolving this, thanks! – Kristi Jorgji Jan 26 '23 at 19:17