Reputation: 1631
I am planning to make a package that has x functionality enabled. However, if package p is installed, how can I make my package enable y functionality?
I cannot have package p give any info to my package, so having them cross-communicate in some way wouldn't work.
Therefore, in Dart (with or without Flutter), can I programatically check to see if another Dart/Flutter package has been installed in the project (added to pubspec.yaml and available)?
Upvotes: 0
Views: 1047
Reputation: 1631
I achieved this through extension methods and a seperate export/import file for 'plugins'/modules/extensions only.
Unfortunately, this won't allow for new non-methods, such as variables, but getters may be used instead.
To implement a similar system:
Upvotes: 0
Reputation: 4554
You can determine if a package is globally installed by checking if a directory exists: (pub cache)/global_packages/package_name.
The DCli api has the following method:
DartSdk().isPackageGloballyActivated(String package)
So to check if dcli is globally active:
DartSdk().isPackageGloballyActivated('dcli');
Upvotes: 2