Flutter child isolate can not dependent on flutter engine(WidgetsFlutterBinding.ensureInitialized())

43 Views Asked by At

in my flutter android project, need to send serial request, so create a plugin to send serial request, contains below functions: 1, read excel config; 2, send serial request;

in root isolate, send serial port requests every 100ms to 200ms in a loop, so I create a child isolate;

but in child isolate, can not use the plugin, the plugin can only be instantiated in the child isolate;

so here is the question, in child isolate, during the plugin instantiation process, it will depend on Flutter Engine initialization. but in child isolate, the entryPoint must be a static function, can not dependent the Flutter Engine initialzation.

error log: I/flutter ( 2513): 协议备份失败:Binding has not yet been initialized. I/flutter ( 2513): The "instance" getter on the ServicesBinding binding mixin is only available once that binding has been initialized. I/flutter ( 2513): Typically, this is done by calling "WidgetsFlutterBinding.ensureInitialized()" or "runApp()" (the latter calls the former). Typically this call is done in the "void main()" method. The "ensureInitialized" method is idempotent; calling it multiple times is not harmful. After calling that method, the "instance" getter will return the binding. I/flutter ( 2513): In a test, one can call "TestWidgetsFlutterBinding.ensureInitialized()" as the first line in the test's "main()" method to initialize the binding. I/flutter ( 2513): If ServicesBinding is a custom binding mixin, there must also be a custom binding class, like WidgetsFlutterBinding, but that mixes in the selected binding, and that is the class that must be constructed before using the "instance" getter.

error file, the red line throw the error: enter image description here

0

There are 0 best solutions below