Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share dependencies from a package flutter

Tags:

flutter

dart

I'm developing a flutter library package.
In this package I used some other dependencies, for example the url_launcher like this:

 dependencies:
    flutter:
      sdk: flutter
    url_launcher: ^5.5.0 

When I import my package into the flutter app, I can't reference to url_launcher in the code until I add it into app pubspec.yaml dependencies
I wonder is there any way to share the imported dependencies from my library package so that I don't need to import again in the app?

like image 973
ductran Avatar asked May 01 '26 21:05

ductran


1 Answers

I guess, currently there is no specified way to do this. To give you an example, I would pick this package called Chewie. What is does is:

It sits on top of a plugin called video_player, and added some cool controller.

CATCH: Since it uses video_player extensively to give away the nicer controller, however, you still need to import the video_player in your app. Otherwise, your app will crash.

WHAT YOU CAN DO?

You can mention in your documentation stating about having that dependency in the project, like the chewie plugin does. This will help people know about those things before hand, and I am sure, if your plugin is great [which is, IT SAVES TIME], people won't mind adding just another single line in their pubspec.yaml file. Otherwise, they would have done it via url_launcher but they can't. Hahaha!

Guess that will give you some clarity.

Also, do give a read on this Developing Packages

like image 150
Alok Avatar answered May 04 '26 12:05

Alok