Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion geolocator_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 4.2.7

- Adds `updatePositionStream` API.
- Updated `flutter_lints` to version `^5.0.0`.

## 4.2.6
Expand Down
1 change: 1 addition & 0 deletions geolocator_platform_interface/lib/src/errors/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export 'activity_missing_exception.dart';
export 'already_subscribed_exception.dart';
export 'invalid_permission_exception.dart';
export 'location_service_disabled_exception.dart';
export 'not_subscribed_exception.dart';
export 'permission_definitions_not_found_exception.dart';
export 'permission_denied_exception.dart';
export 'permission_request_in_progress_exception.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/// An exception thrown when trying to update location stream settings without
/// having an active subscription to the location stream.
class NotSubscribedException implements Exception {
/// Constructs the [NotSubscribedException]
const NotSubscribedException();

@override
String toString() =>
'The App is not listening to a stream of position updates and thus it is'
'not possible to update location stream settings. Call '
'getPositionStream() first.';
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,17 @@ abstract class GeolocatorPlatform extends PlatformInterface {
throw UnimplementedError('getPositionStream() has not been implemented.');
}

/// Updates the parameters of the active position stream.
///
/// Throws a [NotSubscribedException] when there is no active position stream
/// to update.
Future<void> updatePositionStream({
required LocationSettings locationSettings,
}) {
throw UnimplementedError(
'updatePositionStream() has not been implemented.');
}

/// Asks the user for Temporary Precise location access (iOS 14 or above).
///
/// Returns [LocationAccuracyStatus.precise] if the user already gave
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import '../enums/enums.dart';
import '../errors/errors.dart';
import '../extensions/extensions.dart';
import '../geolocator_platform_interface.dart';
import '../models/position.dart';
import '../models/location_settings.dart';
import '../models/position.dart';

/// An implementation of [GeolocatorPlatform] that uses method channels.
class MethodChannelGeolocator extends GeolocatorPlatform {
Expand Down Expand Up @@ -191,6 +191,22 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
return _positionStream!;
}

@override
Future<void> updatePositionStream(
{required LocationSettings locationSettings}) async {
if (_positionStream == null) {
throw const NotSubscribedException();
}
try {
await _methodChannel.invokeMethod(
'updatePositionStream', locationSettings.toJson());
} on PlatformException catch (e) {
final error = _handlePlatformException(e);

throw error;
}
}

Stream<dynamic> _wrapStream(Stream<dynamic> incoming) {
return incoming.asBroadcastStream(onCancel: (subscription) {
subscription.cancel();
Expand Down Expand Up @@ -234,6 +250,8 @@ class MethodChannelGeolocator extends GeolocatorPlatform {
return const LocationServiceDisabledException();
case 'LOCATION_SUBSCRIPTION_ACTIVE':
return const AlreadySubscribedException();
case 'LOCATION_SUBSCRIPTION_INACTIVE':
return const NotSubscribedException();
case 'PERMISSION_DEFINITIONS_NOT_FOUND':
return PermissionDefinitionsNotFoundException(exception.message);
case 'PERMISSION_DENIED':
Expand Down
11 changes: 5 additions & 6 deletions geolocator_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ description: A common platform interface for the geolocator plugin.
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_platform_interface
# 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: 4.2.6

version: 4.2.7

dependencies:
flutter:
sdk: flutter
plugin_platform_interface: ^2.1.6

plugin_platform_interface: ^2.1.8
vector_math: ^2.1.4
meta: ^1.9.1

dev_dependencies:
async: ^2.11.0
async: ^2.12.0
flutter_test:
sdk: flutter
flutter_lints: ^5.0.0
mockito: ^5.4.2
mockito: ^5.6.1

environment:
sdk: ^3.5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,21 @@ void main() {
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of updatePositionStream should throw unimplemented error',
() {
// Arrange
final geolocatorPlatform = ExtendsGeolocatorPlatform();

// Act & Assert
expect(
() => geolocatorPlatform.updatePositionStream(
locationSettings: LocationSettings()),
throwsUnimplementedError,
);
});

test(
// ignore: lines_longer_than_80_chars
'Default implementation of openAppSettings should throw unimplemented error',
Expand Down