How to share common code between multiple flutter engines?

539 Views Asked by At

I have a flutter added into my android host project. I am currently having multiple flutter engines. But there is no sharing of code between these engines. Therefore method-channel calls are happening multiple times. I have a single entry point for all the engines. I tried using singleton in my flutter code, but that is also executed multiple times. What would be a good solution to this. I read 'IsolateGroup' can be used but I haven't implemented it yet so I don't have a reference.

2

There are 2 best solutions below

0
On BEST ANSWER

I found 2 solutions on this :

  1. Isar DB - this can act as a common database layer, engines can read and write and share common data.
  2. SendPort - using this we can pass data with other engines
0
On

To share common code between multiple Flutter engines, you can create a separate Dart package that contains the shared code and then import that package into each engine that needs to use it. This allows you to maintain a single source of truth for the shared code and easily update it in all places where it is used. You can create a Dart package using the pub package manager and publishing it to a package repository such as pub.dev. Once the package is published, you can import it into your Flutter app using the dependencies section of your pubspec.yaml file.