From b429e7eb0029afae5910fe9ff3e472ae47685235 Mon Sep 17 00:00:00 2001 From: stuartmorgan Date: Tue, 7 Apr 2020 09:03:49 -0700 Subject: [PATCH] Update Windows and Linux plugin templates (#53876) Updates Windows and Linux templates to use the new PluginRegistrarManager, improving lifetime handling and reducing boilerplate. --- .../plugin/linux.tmpl/projectName_plugin.cc.tmpl | 12 +++--------- .../plugin/windows.tmpl/projectName_plugin.cpp.tmpl | 12 +++--------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/packages/flutter_tools/templates/plugin/linux.tmpl/projectName_plugin.cc.tmpl b/packages/flutter_tools/templates/plugin/linux.tmpl/projectName_plugin.cc.tmpl index aab588b64b..5a0822a16a 100644 --- a/packages/flutter_tools/templates/plugin/linux.tmpl/projectName_plugin.cc.tmpl +++ b/packages/flutter_tools/templates/plugin/linux.tmpl/projectName_plugin.cc.tmpl @@ -72,13 +72,7 @@ void {{pluginClass}}::HandleMethodCall( void {{pluginClass}}RegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar) { - // The plugin registrar wrappers owns the plugins, registered callbacks, etc., - // so must remain valid for the life of the application. - static auto *plugin_registrars = - new std::map>; - auto insert_result = plugin_registrars->emplace( - registrar, std::make_unique(registrar)); - - {{pluginClass}}::RegisterWithRegistrar(insert_result.first->second.get()); + {{pluginClass}}::RegisterWithRegistrar( + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(registrar)); } diff --git a/packages/flutter_tools/templates/plugin/windows.tmpl/projectName_plugin.cpp.tmpl b/packages/flutter_tools/templates/plugin/windows.tmpl/projectName_plugin.cpp.tmpl index a26aee4e4d..665c9169a2 100644 --- a/packages/flutter_tools/templates/plugin/windows.tmpl/projectName_plugin.cpp.tmpl +++ b/packages/flutter_tools/templates/plugin/windows.tmpl/projectName_plugin.cpp.tmpl @@ -83,13 +83,7 @@ void {{pluginClass}}::HandleMethodCall( void {{pluginClass}}RegisterWithRegistrar( FlutterDesktopPluginRegistrarRef registrar) { - // The plugin registrar wrappers owns the plugins, registered callbacks, etc., - // so must remain valid for the life of the application. - static auto *plugin_registrars = - new std::map>; - auto insert_result = plugin_registrars->emplace( - registrar, std::make_unique(registrar)); - - {{pluginClass}}::RegisterWithRegistrar(insert_result.first->second.get()); + {{pluginClass}}::RegisterWithRegistrar( + flutter::PluginRegistrarManager::GetInstance() + ->GetRegistrar(registrar)); }