Added the locationServiceStream to the platform interface + edited pubspec.yaml and CHANGELOG
MODIFY
geolocator_platform_interface/CHANGELOG.md
geolocator_platform_interface/CHANGELOG.md
+## 2.1.0
+
+- Added the possibility to start a stream which will return an event when Location Services are manually enabled/disabled
+
## 2.0.2
- Added definition of the `ActivityMissingException`.

MODIFY
geolocator_platform_interface/lib/src/enums/enums.dart
geolocator_platform_interface/lib/src/enums/enums.dart
export 'location_accuracy.dart';
export 'location_permission.dart';
+export 'location_service_status.dart';

ADD
geolocator_platform_interface/lib/src/enums/location_service_status.dart
+/// Represents the possible Location Service Statuses
+enum LocationServiceStatus {
+ /// Location Services are enabled on the native device
+ enabled,
+
+ /// Location Servies are disabled on the native device
+ disabled
+}

MODIFY
geolocator_platform_interface/lib/src/geolocator_platform_interface.dart
geolocator_platform_interface/lib/src/geolocator_platform_interface.dart
@@ -107,6 +107,14 @@ abstract class GeolocatorPlatform extends PlatformInterface {
throw UnimplementedError('getCurrentPosition() has not been implemented.');
}
+ /// Fires when the Location Service is manually disabled or enabled f.e.
+ /// when Location Service in Settings is disabled, a event will be fired which
+ /// returns a [LocationServiceStatus].
+ Stream<LocationServiceStatus> getServiceStatusStream() {
+ throw UnimplementedError(
+ 'getServiceStatusStream() has not been implemented.');
+ }
+
/// Fires whenever the location changes inside the bounds of the
/// [desiredAccuracy].
///

MODIFY
geolocator_platform_interface/lib/src/implementations/method_channel_geolocator.dart
geolocator_platform_interface/lib/src/implementations/method_channel_geolocator.dart
@@ -21,6 +21,11 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
static const _eventChannel =
EventChannel('flutter.baseflow.com/geolocator_updates');
+ /// The event channel used to receive [LocationServiceStatus] updates from the
+ /// native platform.
+ static const _serviceStatusEventChannel =
+ EventChannel('flutter.baseflow.com/geolocator_service_updates');
+
/// On Android devices you can set [forceAndroidLocationManager]
/// to true to force the plugin to use the [LocationManager] to determine the
/// position instead of the [FusedLocationProviderClient]. On iOS this is
@@ -28,6 +33,7 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
bool forceAndroidLocationManager = false;
Stream<Position>? _positionStream;
+ Stream<LocationServiceStatus>? _serviceStatusStream;
@override
Future<LocationPermission> checkPermission() async {
@@ -121,6 +127,27 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
}
}
+ @override
+ Stream<LocationServiceStatus> getServiceStatusStream() {
+ if (_serviceStatusStream != null) {
+ return _serviceStatusStream!;
+ }
+ var serviceStatusStream =
+ _serviceStatusEventChannel.receiveBroadcastStream();
+
+ _serviceStatusStream = serviceStatusStream
+ .map((dynamic element) => element as LocationServiceStatus)
+ .handleError((error) {
+ _serviceStatusStream = null;
+ if (error is PlatformException) {
+ _handlePlatformException(error);
+ }
+ throw error;
+ });
+
+ return _serviceStatusStream!;
+ }
+
@override
Stream<Position> getPositionStream({
LocationAccuracy desiredAccuracy = LocationAccuracy.best,

MODIFY
geolocator_platform_interface/pubspec.yaml
geolocator_platform_interface/pubspec.yaml
@@ -3,7 +3,7 @@ description: A common platform interface for the geolocator plugin.
homepage: https://github.com/baseflow/flutter-geolocator
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
-version: 2.0.2
+version: 2.1.0
dependencies:
flutter:

Added the locationServiceStream to the platform interface + edited pubspec.yaml and CHANGELOG