Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Plugin Controller not static so it creates new instance for each Flutter Engine #723

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

daviddomkar
Copy link

@daviddomkar daviddomkar commented Apr 22, 2023

I encountered a bug with this package when using together with flutter_foreground_task plugin.

flutter_foreground_task plugin creates a separate Flutter Engine in android foreground task to perform some work. This engine also initializes flutter_reactive_ble plugin.

However, because the PluginController instance is static, it would deinitialize the plugin when Flutter Engine that the app uses is destroyed (on app force close) which leaves the plugin deinitialized for the potentionally running Flutter Engine in the foreground task.

This PR ensures that each Flutter Engine has its own instance of the PluginController which deintializes only if the given engine is destroyed. This allows for plugin usage within background contexts like the foreground task on android.

The change is only for android at the moment. I don't have equipment to implement and test this on the iOS side.

Fixes #687 #672

@daviddomkar daviddomkar marked this pull request as draft April 22, 2023 16:01
@daviddomkar daviddomkar marked this pull request as ready for review April 22, 2023 16:02
@daviddomkar daviddomkar force-pushed the feat/make-new-plugin-controller-instance-for-each-flutter-engine branch from cab4435 to 39540c4 Compare May 31, 2023 19:11
@dominicmh
Copy link

This fix is important since the underlying bug turns the plugin useless in any project that creates – or has plugins that create – a new FlutterEngine.
An additional issue remains: Whenever a FlutterEngine is destroyed the plugin will also disconnect from all connections or stop scanning. E.g. if a background task is finished or in hybrid apps that have some parts of the UI native and some parts in Flutter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bluetooth connection problem in foreground service when closing application since 5.0.3
2 participants