-2

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.

Fahid sarker
  • 95
  • 2
  • 5
  • you can use `Platform.isAndroid` to identify the platform. – Hamed Jan 23 '22 at 08:39
  • @Hamed That would be run-time verification and will include both packages no matter what the os it. – Fahid sarker Jan 23 '22 at 08:46
  • Does [this](https://stackoverflow.com/questions/58710226/how-to-import-platform-specific-dependency-in-flutter-dart-combine-web-with-an) help you? – Peter Koltai Jan 23 '22 at 12:30
  • @Peter That approach only works for web vs. non-web, because there's no way to do conditional includes based on other platform distinctions. (And even if there were, it wouldn't prevent the native parts of plugins from being included.) – smorgan Jan 23 '22 at 23:23

1 Answers1

1

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
smorgan
  • 20,228
  • 3
  • 47
  • 55