@@ -674,6 +674,7 @@ bool DartIsolate::MarkIsolateRunnable() {
674674
675675[[nodiscard]] static bool InvokeMainEntrypoint (
676676 Dart_Handle user_entrypoint_function,
677+ Dart_Handle plugin_registrant_function,
677678 Dart_Handle args) {
678679 if (tonic::LogIfError (user_entrypoint_function)) {
679680 FML_LOG (ERROR) << " Could not resolve main entrypoint function." ;
@@ -689,6 +690,20 @@ bool DartIsolate::MarkIsolateRunnable() {
689690 return false ;
690691 }
691692
693+ if (tonic::GetErrorHandleType (plugin_registrant_function) ==
694+ tonic::DartErrorHandleType::kNoError ) {
695+ // The plugin registrant may or may not be defined.
696+ // If it's not defined, then continue as usual.
697+ // The tests in the framework will ensure that the Dart plugin registrant is
698+ // called when defined.
699+ if (tonic::LogIfError (tonic::DartInvokeField (
700+ Dart_LookupLibrary (tonic::ToDart (" dart:ui" )), " _runMainZoned" ,
701+ {start_main_isolate_function, plugin_registrant_function, args}))) {
702+ FML_LOG (ERROR) << " Could not invoke the Dart plugin registrant." ;
703+ return false ;
704+ }
705+ }
706+
692707 if (tonic::LogIfError (tonic::DartInvokeField (
693708 Dart_LookupLibrary (tonic::ToDart (" dart:ui" )), " _runMainZoned" ,
694709 {start_main_isolate_function, user_entrypoint_function, args}))) {
@@ -716,12 +731,18 @@ bool DartIsolate::RunFromLibrary(std::optional<std::string> library_name,
716731 auto entrypoint_handle = entrypoint.has_value () && !entrypoint.value ().empty ()
717732 ? tonic::ToDart (entrypoint.value ().c_str ())
718733 : tonic::ToDart (" main" );
734+ auto entrypoint_args = tonic::ToDart (args);
719735 auto user_entrypoint_function =
720736 ::Dart_GetField (library_handle, entrypoint_handle);
721-
722- auto entrypoint_args = tonic::ToDart (args);
723-
724- if (!InvokeMainEntrypoint (user_entrypoint_function, entrypoint_args)) {
737+ // The Dart plugin registrant is generated by the Flutter tool.
738+ // In general, this function binds a plugin implementation to their platform
739+ // interface based on the configuration in the app's pubpec.yaml, and the
740+ // plugin's pubspec.yaml.
741+ auto plugin_registrant_function =
742+ ::Dart_GetField (library_handle, tonic::ToDart(" _registerPlugins" ));
743+
744+ if (!InvokeMainEntrypoint (user_entrypoint_function,
745+ plugin_registrant_function, entrypoint_args)) {
725746 return false ;
726747 }
727748
0 commit comments