From 721669c9f9b764fd95a186f2d3ebe3294ddfb672 Mon Sep 17 00:00:00 2001 From: skylar taylor-barrick Date: Fri, 3 Jul 2026 14:10:38 -0600 Subject: [PATCH] Lazily create Windows geolocator --- permission_handler_windows/CHANGELOG.md | 4 ++++ permission_handler_windows/pubspec.yaml | 2 +- .../windows/permission_handler_windows_plugin.cpp | 11 ++--------- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/permission_handler_windows/CHANGELOG.md b/permission_handler_windows/CHANGELOG.md index 91c2f5049..669d92d1b 100644 --- a/permission_handler_windows/CHANGELOG.md +++ b/permission_handler_windows/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.2.2 + +* Lazily creates the Windows `Geolocator` only when checking location service status. + ## 0.2.1 * Updates the dependency on `permission_handler_platform_interface` to version 4.1.0 (SiriKit support is only available for iOS and macOS). diff --git a/permission_handler_windows/pubspec.yaml b/permission_handler_windows/pubspec.yaml index f5553e0d6..3495a07b7 100644 --- a/permission_handler_windows/pubspec.yaml +++ b/permission_handler_windows/pubspec.yaml @@ -1,6 +1,6 @@ name: permission_handler_windows description: Permission plugin for Flutter. This plugin provides the Windows API to request and check permissions. -version: 0.2.1 +version: 0.2.2 homepage: https://github.com/baseflow/flutter-permission-handler flutter: diff --git a/permission_handler_windows/windows/permission_handler_windows_plugin.cpp b/permission_handler_windows/windows/permission_handler_windows_plugin.cpp index 4b4d6d184..6bc45ff12 100644 --- a/permission_handler_windows/windows/permission_handler_windows_plugin.cpp +++ b/permission_handler_windows/windows/permission_handler_windows_plugin.cpp @@ -63,9 +63,6 @@ class PermissionHandlerWindowsPlugin : public Plugin { private: void IsLocationServiceEnabled(std::unique_ptr> result); winrt::fire_and_forget IsBluetoothServiceEnabled(std::unique_ptr> result); - - winrt::Windows::Devices::Geolocation::Geolocator geolocator; - winrt::Windows::Devices::Geolocation::Geolocator::PositionChanged_revoker m_positionChangedRevoker; }; // static @@ -86,12 +83,7 @@ void PermissionHandlerWindowsPlugin::RegisterWithRegistrar( registrar->AddPlugin(std::move(plugin)); } -PermissionHandlerWindowsPlugin::PermissionHandlerWindowsPlugin(){ - m_positionChangedRevoker = geolocator.PositionChanged(winrt::auto_revoke, - [this](Geolocator const& geolocator, PositionChangedEventArgs e) - { - }); -} +PermissionHandlerWindowsPlugin::PermissionHandlerWindowsPlugin() = default; PermissionHandlerWindowsPlugin::~PermissionHandlerWindowsPlugin() = default; @@ -149,6 +141,7 @@ void PermissionHandlerWindowsPlugin::HandleMethodCall( } void PermissionHandlerWindowsPlugin::IsLocationServiceEnabled(std::unique_ptr> result) { + Geolocator geolocator; result->Success(EncodableValue((int)(geolocator.LocationStatus() != PositionStatus::NotAvailable ? PermissionConstants::ServiceStatus::ENABLED : PermissionConstants::ServiceStatus::DISABLED)));