Flutter use plugin based on platform (compile time optimization)
I want to use android_alarm_manager for the android side and work_manager for the ios. Is there any way to tell flutter NOT to include work_manager for the android build?
Note: I am asking for a solution for compile-time optimization which checking platform.isAndroid can not do.
There is no way to include only part of a plugin.
- If you are only concerned with the native part of the plugin, you could fork it (even just locally) and remove the
android
entry from the plugin's pubspec.yaml, then use your fork. - If you are also concerned about the Dart code, you would need to:
- extract most of the logic to a package
- define an abstraction for the functionality you want to implement with the two plugins
- make the shared logic package take that abstraction via injection
- make two app projects, one for Android and one for iOS, each using the shared package, and each including the relevant plugin and providing an implementation for the abstraction using that plugin