@@ -725,6 +725,32 @@ bool DartIsolate::MarkIsolateRunnable() {
725725 return true ;
726726}
727727
728+ [[nodiscard]] static void InvokeDartPluginRegistrantIfAvailable (
729+ Dart_Handle library_handle) {
730+ TRACE_EVENT0 (" flutter" , " InvokeDartPluginRegistrantIfAvailable" );
731+
732+ // The Dart plugin registrant is a static with signature `void register()`
733+ // within the class `_PluginRegistrant` generated by the Flutter tool.
734+ //
735+ // This method binds a plugin implementation to their platform
736+ // interface based on the configuration of the app's pubpec.yaml, and the
737+ // plugin's pubspec.yaml.
738+ //
739+ // Since this method may or may not be defined, check if the class is defined
740+ // in the default library before calling the method.
741+ Dart_Handle plugin_registrant =
742+ ::Dart_GetClass (library_handle, tonic::ToDart(" _PluginRegistrant" ));
743+
744+ if (Dart_IsError (plugin_registrant)) {
745+ return ;
746+ }
747+ Dart_Handle result =
748+ tonic::DartInvokeField (plugin_registrant, " register" , {});
749+ if (tonic::LogIfError (result)) {
750+ FML_LOG (ERROR) << " The Dart plugin registrant produced an error" ;
751+ }
752+ }
753+
728754bool DartIsolate::RunFromLibrary (std::optional<std::string> library_name,
729755 std::optional<std::string> entrypoint,
730756 const std::vector<std::string>& args) {
@@ -746,25 +772,7 @@ bool DartIsolate::RunFromLibrary(std::optional<std::string> library_name,
746772 auto user_entrypoint_function =
747773 ::Dart_GetField (library_handle, entrypoint_handle);
748774
749- // The Dart plugin registrant is a static with signature `void register()`
750- // within the class `_PluginRegistrant` generated by the Flutter tool.
751- //
752- // This method binds a plugin implementation to their platform
753- // interface based on the configuration of the app's pubpec.yaml, and the
754- // plugin's pubspec.yaml.
755- //
756- // Since this method may or may not be defined, check if the class is defined
757- // in the default library before calling the method.
758- Dart_Handle plugin_registrant =
759- ::Dart_GetClass (library_handle, tonic::ToDart(" _PluginRegistrant" ));
760-
761- if (!Dart_IsError (plugin_registrant)) {
762- Dart_Handle result =
763- tonic::DartInvokeField (plugin_registrant, " register" , {});
764- if (tonic::LogIfError (result)) {
765- FML_LOG (ERROR) << " Could not invoke the Dart plugin registrant." ;
766- }
767- }
775+ InvokeDartPluginRegistrantIfAvailable (library_handle);
768776
769777 if (!InvokeMainEntrypoint (user_entrypoint_function, entrypoint_args)) {
770778 return false ;
0 commit comments