Since Flutter already has taken a shared library approach for Android and iOS apps; is it possible to extend this idea to add server (API) code using Dart and web content using Angular-Dart? I can see examples of server and client code being shared, and can see Android and iOS code being shared (Flutter) - are there any examples where business logic is shared between iOS, Android, web and API code? Something similar to kotlin-multiplatform?
1 Answers
Just move your code in another Dart package that
does not depend (directly or transitive) on
dart:ui
(Flutter)dart:html
or Angular (browser)dart:io
(server or console)
Everything that needs a dependency to one of these needs to be abstracted and then injected (passed as argument) when you use the platform-independent code on a specific platform.
You actually can share code between server and Flutter that depends on dart:io
but such a dependency would prevent code being used in the browser.
See also
In a project I'm working on I have built_value
model classes and built_redux
(actions, reducers, state) in the shared package and use it in Flutter and Angular.
The main pain point was Firebase where the whole Firebase API needed to be abstracted because Angular and Flutter use different Firebase packages. It wasn't too difficult, but cumbersome. There are attempts to create a package that provide such an abstraction out of the box, but I don't know about the progress.

- 623,577
- 216
- 2,003
- 1,567