Removed unnecesary exceptions and made some changes to the implementation/docs
MODIFY
geolocator_platform_interface/lib/src/enums/location_accuracy.dart
geolocator_platform_interface/lib/src/enums/location_accuracy.dart
@@ -20,5 +20,10 @@ enum LocationAccuracy {
/// Location accuracy is optimized for navigation on iOS and matches the
/// [LocationAccuracy.best] on Android
- bestForNavigation
+ bestForNavigation,
+
+ /// Location accuracy is reduced for iOS 14+ devices, matches the
+ /// [LocationAccuracy.low] and [LocationAccuracy.lowest] on Android and
+ /// matches [LocationAccuracy.lowest] on devices using iOS 13 or below.
+ reduced
}

DELETE
geolocator_platform_interface/lib/src/errors/approximate_location_not_supported_exception.dart
-/// An exception thrown when users using iOS 13 or below try to execute the
-/// 'requestTemporaryFullAccuracy' method.
-///
-/// Since Approximate location only supports iOS 14 or above, the exception is
-/// only thrown when using iOS 13 or below.
-class ApproximateLocationNotSupportedException implements Exception {
- /// Constructs the [ApproximateLocationNotSupportedException]
- const ApproximateLocationNotSupportedException(this.message);
-
- /// A [message] describing more details about the exception
- final String? message;
-
- @override
- String toString() {
- if (message == null || message == '') {
- return 'The requestTemporaryFullAccuracy method only supports iOS 14'
- ' or above.';
- }
- return message!;
- }
-}

MODIFY
geolocator_platform_interface/lib/src/errors/errors.dart
geolocator_platform_interface/lib/src/errors/errors.dart
export 'activity_missing_exception.dart';
export 'already_subscribed_exception.dart';
-export 'approximate_location_not_supported_exception.dart';
export 'invalid_permission_exception.dart';
export 'location_service_disabled_exception.dart';
export 'permission_definitions_not_found_exception.dart';
export 'permission_denied_exception.dart';
export 'permission_request_in_progress_exception.dart';
export 'position_update_exception.dart';
\ No newline at end of file
-export 'precise_accuracy_enabled_exception.dart';

DELETE
geolocator_platform_interface/lib/src/errors/precise_accuracy_enabled_exception.dart
-/// An exception thrown when the user already enabled Precise Location fetching.
-///
-/// This exception is thrown only when using iOS 14 or above.
-class PreciseAccuracyEnabledException implements Exception {
- /// Constructs the [PreciseAccuracyEnabledException]
- const PreciseAccuracyEnabledException(this.message);
-
- /// A [message] describing more details about the exception.
- final String? message;
-
- @override
- String toString() {
- if (message == null || message == '') {
- return 'The user already enabled Precise location fetching, when using '
- 'the requestTemporaryFullAccuracy, make sure to check whether the '
- 'user has already given permission to use Precise Accuracy.';
- }
-
- return message!;
- }
-}

MODIFY
geolocator_platform_interface/lib/src/geolocator_platform_interface.dart
geolocator_platform_interface/lib/src/geolocator_platform_interface.dart
import 'dart:async';
import 'dart:math';
+import 'package:geolocator_platform_interface/geolocator_platform_interface.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:vector_math/vector_math.dart';
@@ -161,15 +162,15 @@ abstract class GeolocatorPlatform extends PlatformInterface {
/// Asks the user for Temporary Precise location access (iOS 14 or above).
///
- /// Throws a [AccuracyDictionaryNotFoundException] when the key
+ /// Returns [LocationAccuracyStatus.precise] if the user already gave
+ /// permission to use Precise Accuracy. If the user uses iOS 13 or below,
+ /// [LocationAccuracyStatus.precise] will also be returned. On other platforms
+ /// an PlatformException will be thrown.
+ ///
+ /// Throws a [PermissionDefinitionsNotFoundException] when the key
/// `NSLocationTemporaryUsageDescriptionDictionary` has not been set in the
/// `Infop.list`.
- /// Throws a [PreciseAccuracyEnabledException] when the user already gave
- /// permission to use Precise Accuracy location fetching.
- /// Throws a [ApproximateLocationNotSupportedException] when Approximate
- /// Location is not supported (iOS 13 or below).
- Future<void> requestTemporaryFullAccuracy() {
- // ignore: lines_longer_than_80_chars
+ Future<LocationAccuracyStatus> requestTemporaryFullAccuracy() async {
throw UnimplementedError(
'requestTemporaryFullAccuracy() has not been implemented');
}

MODIFY
geolocator_platform_interface/lib/src/implementations/method_channel_geolocator.dart
geolocator_platform_interface/lib/src/implementations/method_channel_geolocator.dart
@@ -226,10 +226,11 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
}
@override
- Future<void> requestTemporaryFullAccuracy() async {
+ Future<LocationAccuracyStatus> requestTemporaryFullAccuracy() async {
try {
- await _methodChannel.invokeMethod<void>('requestTemporaryFullAccuracy');
- return;
+ final int status = await _methodChannel
+ .invokeMethod('requestTemporaryFullAccuracy');
+ return LocationAccuracyStatus.values[status];
} on PlatformException catch (e) {
_handlePlatformException(e);
rethrow;
@@ -262,10 +263,6 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
throw PermissionRequestInProgressException(exception.message);
case 'LOCATION_UPDATE_FAILURE':
throw PositionUpdateException(exception.message);
- case 'PRECISE_ACCURACY_ENABLED':
- throw PreciseAccuracyEnabledException(exception.message);
- case 'APPROXIMATE_LOCATION_NOT_SUPPORTED':
- throw ApproximateLocationNotSupportedException(exception.message);
default:
throw exception;
}

MODIFY
geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart
geolocator_platform_interface/test/src/implementations/method_channel_geolocator_test.dart
@@ -134,121 +134,40 @@ void main() {
});
});
- group(
- // ignore: lines_longer_than_80_chars
- 'requestTemporaryFullAccuracy: When requesting Temporary Precise location',
- () {
- test('Should receive an exception when precise location is enabled',
- () async {
+ group('requestTemporaryFullAccuracy: When requesting temporary full'
+ 'accuracy.', () {
+ test('Should receive reduced accuracy if Location Accuracy is pinned to'
+ ' reduced', () async {
+ // Arrange
MethodChannelMock(
channelName: 'flutter.baseflow.com/geolocator',
method: 'requestTemporaryFullAccuracy',
- result: PlatformException(
- code: 'PRECISE_ACCURACY_ENABLED',
- message: 'Precise location is enabled.',
- details: null,
- ),
+ result: 0
);
// Act
- final accuracyFuture =
- MethodChannelGeolocator().requestTemporaryFullAccuracy();
+ final accuracy = await MethodChannelGeolocator()
+ .requestTemporaryFullAccuracy();
// Assert
- expect(
- accuracyFuture,
- throwsA(
- isA<PreciseAccuracyEnabledException>().having(
- (e) => e.toString(),
- 'description',
- 'Precise location is enabled.',
- ),
- ),
- );
+ expect(accuracy, LocationAccuracyStatus.reduced);
});
- test('Should receive an exception when iOS 13 or below is used',
- () async {
- MethodChannelMock(
- channelName: 'flutter.baseflow.com/geolocator',
- method: 'requestTemporaryFullAccuracy',
- result: PlatformException(
- code: 'APPROXIMATE_LOCATION_NOT_SUPPORTED',
- message: 'Approximate location not supported.',
- details: null,
- ),
- );
- // Act
- final accuracyFuture =
- MethodChannelGeolocator().requestTemporaryFullAccuracy();
-
- // Assert
- expect(
- accuracyFuture,
- throwsA(
- isA<ApproximateLocationNotSupportedException>().having(
- (e) => e.toString(),
- 'description',
- 'Approximate location not supported.',
- ),
- ),
- );
- });
- test('Should receive an exception when precise location is enabled',
- () async {
- MethodChannelMock(
- channelName: 'flutter.baseflow.com/geolocator',
- method: 'requestTemporaryFullAccuracy',
- result: PlatformException(
- code: 'PRECISE_ACCURACY_ENABLED',
- message: null,
- details: null,
- ),
- );
-
- // Act
- final accuracyFuture =
- MethodChannelGeolocator().requestTemporaryFullAccuracy();
-
- // Assert
- expect(
- accuracyFuture,
- throwsA(isA<PreciseAccuracyEnabledException>().having(
- (e) => e.toString(),
- '',
- 'The user already enabled Precise location fetching, when using '
- 'the requestTemporaryFullAccuracy, make sure to check '
- 'whether the user has already given permission to use '
- 'Precise Accuracy.')),
- );
- });
- test('Should receive an exception when iOS 13 or below is used',
- () async {
+ test('Should receive reduced accuracy if Location Accuracy is already set'
+ ' to precise location accuracy', () async {
+ // Arrange
MethodChannelMock(
channelName: 'flutter.baseflow.com/geolocator',
method: 'requestTemporaryFullAccuracy',
- result: PlatformException(
- code: 'APPROXIMATE_LOCATION_NOT_SUPPORTED',
- message: null,
- details: null,
- ),
+ result: 1
);
// Act
- final accuracyFuture =
- MethodChannelGeolocator().requestTemporaryFullAccuracy();
+ final accuracy = await MethodChannelGeolocator()
+ .requestTemporaryFullAccuracy();
// Assert
- expect(
- accuracyFuture,
- throwsA(
- isA<ApproximateLocationNotSupportedException>().having(
- (e) => e.toString(),
- '',
- 'The requestTemporaryFullAccuracy method only supports iOS 14'
- ' or above.'),
- ),
- );
+ expect(accuracy, LocationAccuracyStatus.precise);
});
});
@@ -271,6 +190,7 @@ void main() {
expect(locationAccuracy, LocationAccuracyStatus.reduced);
});
+
test('Should receive reduced accuracy if Location Accuracy is reduced',
() async {
// Arrange

Removed unnecesary exceptions and made some changes to the implementation/docs