Test added to geolocator
MODIFY
geolocator/example/lib/main.dart
geolocator/example/lib/main.dart
@@ -32,7 +32,7 @@ class GeolocatorWidget extends StatefulWidget {
class _GeolocatorWidgetState extends State<GeolocatorWidget> {
final List<_PositionItem> _positionItems = <_PositionItem>[];
StreamSubscription<Position>? _positionStreamSubscription;
- StreamSubscription<bool>? _locationServiceStatusSubscription;
+ StreamSubscription<ServiceStatus>? _locationServiceStatusSubscription;
@override
Widget build(BuildContext context) {

MODIFY
geolocator/lib/geolocator.dart
geolocator/lib/geolocator.dart
@@ -111,9 +111,6 @@ class Geolocator {
/// Throws a [LocationServiceDisabledException] when the user allowed access,
/// but the location services of the device are disabled.
- static Stream<bool> getServiceStatusStream() =>
- GeolocatorPlatform.instance.getServiceStatusStream();
-
static Stream<Position> getPositionStream({
LocationAccuracy desiredAccuracy = LocationAccuracy.best,
int distanceFilter = 0,
@@ -129,6 +126,13 @@ class Geolocator {
timeLimit: timeLimit,
);
+ /// Fires whenever the location services are disabled/enabled in the notification
+ /// bar or in the device settings. Returns ServiceStatus.enabled when location
+ /// services are enabled and returns ServiceStatus.disabled when location
+ /// services are disabled
+ static Stream<ServiceStatus> getServiceStatusStream() =>
+ GeolocatorPlatform.instance.getServiceStatusStream();
+
/// Opens the App settings page.
///
/// Returns [true] if the location settings page could be opened, otherwise

MODIFY
geolocator/pubspec.yaml
geolocator/pubspec.yaml
@@ -11,8 +11,8 @@ dependencies:
flutter:
sdk: flutter
- geolocator_platform_interface: ^2.0.2
- geolocator_web: ^2.0.1
+ geolocator_platform_interface:
+ path: ../geolocator_platform_interface
dev_dependencies:
flutter_test:

MODIFY
geolocator/test/geolocator_test.dart
geolocator/test/geolocator_test.dart
@@ -53,6 +53,16 @@ void main() {
expect(position, mockPosition);
});
+ test('getServiceStatusStream', () async {
+ when(GeolocatorPlatform.instance.getServiceStatusStream())
+ .thenAnswer((_) => Stream.value(ServiceStatus.enabled));
+
+ final locationService = await Geolocator.getServiceStatusStream();
+
+ expect(locationService,
+ emitsInOrder([emits(ServiceStatus.enabled), emitsDone]));
+ });
+
test('getPositionStream', () async {
when(GeolocatorPlatform.instance.getPositionStream(
desiredAccuracy: LocationAccuracy.best,
@@ -163,6 +173,17 @@ class MockGeolocatorPlatform extends Mock
}) =>
Future.value(mockPosition);
+ @override
+ Stream<ServiceStatus> getServiceStatusStream() {
+ return super.noSuchMethod(
+ Invocation.method(
+ #getServiceStatusStream,
+ null,
+ ),
+ returnValue: Stream.value(ServiceStatus.enabled),
+ );
+ }
+
@override
Stream<Position> getPositionStream({
LocationAccuracy? desiredAccuracy = LocationAccuracy.best,

Test added to geolocator