Plugins with dart plugin registrants don't work on background isolates

This issue has been created since 2022-09-22.

After #13937, platform channels work on background isolates. Plugins should work as well, but if a plugin relies on a dart plugin registrant (example shared_preferences usage to set the platform_interface subclass) the registrant isn't executed on the background isolate, so the plugin doesn't function correctly. Specifically there aren't handlers registered for the platform channels.

The solution should be to execute the Dart plugin registrant on the background isolate when it registers with the root isolate.

See:

  • PlatformConfigurationNativeApi::RegisterBackgroundIsolate
  • flutter::FindAndInvokeDartPluginRegistrant
gaaclarke wrote this answer on 2022-09-23

fyi @stuartmorgan

I tried the naive solution of calling flutter::FindAndInvokeDartPluginRegistrant in PlatformConfigurationNativeApi::RegisterBackgroundIsolate but oddly crashes. Ideally we can fix this under the covers so BackgroundIsolateBinaryMessenger.ensureInitialized calls the registrant.

stuartmorgan wrote this answer on 2022-09-23

Does calling the Dart plugin ensure-initialized method (I forget the exact name) from the Dart side work?

gaaclarke wrote this answer on 2022-09-23

Does calling the Dart plugin ensure-initialized method (I forget the exact name) from the Dart side work?

Are you talking about calling the generated dart code directly? The generated code is private (class _PluginRegistrant), I wonder if I may have to end up exposing a function that is calling it. I don't know if there already is one. I didn't see one.

I suspect the crash on the c++ solution may be something weird about jumping back into dart after dart calls c++ (ie Dart-> C++-> Dart ).

stuartmorgan wrote this answer on 2022-09-23

I meant calling DartPluginRegistrant.ensureInitialized().

gaaclarke wrote this answer on 2022-09-24

I completely forgot I implemented that, that worked out.

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-10-05
Star Count 145516
Watcher Count 3569
Fork Count 23400
Issue Count 11194

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Support for `\newenvironment` wrapping another environment 3 2020-12-23 2022-07-09
Wallet Connect Modal Not Working?! [Vite / Replit / TSX] 5 2022-06-26 2022-09-30
IP address - UF-Nano-G 0 2021-11-16 2022-04-06
UF-Instant connection issue 1 2021-12-10 2022-07-20
What are the disadvantages when the data Preprocessing and model training pipelines are integrated via raydp? 1 2021-07-31 2022-08-16
Bar Chart label is not in the middle of the bar 1 2022-03-15 2022-08-04
Prolog error in tf_mng_tree/2: `lookup_transforms/2` doesn't seem to be accessable 2 2021-09-13 2022-10-01
webrtc Retrying source if enable live stream 8 2021-05-09 2022-09-27
Improvements to trait handling 2 2022-08-15 2022-10-02
Node stalled "No header for child block [], so will not validate continuity" 2 2022-08-21 2022-09-14
Remove developer mode as default feature 1 2022-08-18 2022-09-14
Request to add a site 2 2022-06-17 2022-06-19
Doesn't work on iOS mobile devices 11 2020-11-11 2022-09-08
Support for @ungap/custom-elements 4 2021-01-20 2022-09-20
Is it possible to use "pretty reporter" when running test by require('test-file.js') 1 2021-03-30 2022-09-24
t.doesNotThrow() expected parameters seems to be ignored 14 2021-04-19 2022-09-24
webui error/bug 5 2022-01-19 2022-01-13
slvs.h: problem using SLVS_C_PT_PLANE_DISTANCE 0 2021-12-24 2022-08-11
KdbxError: Error FileCorrupt: no kdf uuid 13 2021-05-23 2022-01-29
Add DjVuXML converter 2 2021-09-08 2022-10-05
[BUG] fillFormula 0 2021-07-09 2022-01-02
组件xrdp 和 omnidb 报如下问题 2 2022-06-13 2022-09-22
Add support for `@implNote`, `@implSpec` and `@apiNote` 6 2022-04-28 2022-08-27
Drag-n-drop images to change order 0 2021-02-20 2022-08-27
add gruvbox theme (light and dark) 1 2021-08-20 2022-02-27
[flaky] test/e2e.TestChannelNamespaceDefaulting 4 2022-01-21 2022-09-11
lilymanga.com 0 2021-11-11 2021-12-28
shell files: enable `set -u -e -o pipefail`. 1 2022-03-01 2022-09-23
Legend Alignment always on the edge 2 2021-09-18 2022-08-31
Deprecation warning for recordFailed on Xcode 13 0 2021-09-22 2022-10-03
[PHP] Explore PHP 8.1 Internal API signature and behavioral changes. 4 2021-10-29 2022-07-23
Support bash's process substitution on kubeconfig flag 2 2021-07-29 2022-09-29
[Bug]: Update not working 1 2022-06-19 2022-10-04
[documentation]: Unknown option quarkus.http.proxy-address-forwarding 1 2022-08-23 2022-08-19
build rest client error from class of jar. 4 2022-08-23 2022-09-07
Add __repr__ method for modules 0 2020-11-16 2022-09-17
combineVSelectWithAllOnesOrZeros - extend to support X86ISD::BLENDV 1 2022-02-12 2022-02-13
Automated PR: Standardising Files 0 2021-08-16 2022-02-10
UX fail: no hint in settings that you can't use firefox with ledger 4 2021-10-20 2022-08-22
iOS app doesn’t allow for TFA login 3 2022-01-08 2022-09-23
Inconsistent range position for selection from parens 0 2021-11-11 2022-09-07
HTTPMetricHandler make constructor public 2 2021-12-09 2022-09-30
Add MailboxProcessor.StartImmediate method 7 2021-04-13 2022-08-20
[Bug]: Column Seperator is not accessible by the keyboard 0 2022-09-21 2022-09-19
Tig blame: pushing enter gives "Commit data not loaded" 1 2022-06-23 2022-09-15
Feature Request: with mouse on, clicking on a commit in [diff] view should open diff view for that commit 0 2022-07-15 2022-09-15
Tig Colors Are Missing Inside Tmux 6 2022-06-30 2022-09-15
~/.local/share/tig/history may not be used since version 2.5.6 3 2022-07-15 2022-09-15
How to set conf make per request just in on core? 2 2022-04-19 2022-09-26
Can't run on Linux with Docker 7 2021-05-03 2022-09-20