Skip to content

Commit a57e19b

Browse files
Returns unsupported errors on web (#1440)
* Returns unsupported errors on web * Changed PlatformException for Unsupported error * Fix analysis * Fixed tests * removed unused import
1 parent bc2142e commit a57e19b

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

geolocator/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,12 @@ The second key (in this example called `YourPurposeKey`) should match the purpos
150150

151151
To use the Geolocator plugin on the web you need to be using Flutter 1.20 or higher. Flutter will automatically add the endorsed [geolocator_web]() package to your application when you add the `geolocator: ^6.2.0` dependency to your `pubspec.yaml`.
152152

153-
The following methods of the geolocator API are not supported on the web and will result in a `PlatformException` with the code `UNSUPPORTED_OPERATION`:
153+
The following methods of the geolocator API are not supported on the web and will result in a `UnsupportedError`:
154154

155155
- `getLastKnownPosition({ bool forceAndroidLocationManager = true })`
156156
- `openAppSettings()`
157157
- `openLocationSettings()`
158+
- `getServiceStatusStream()`
158159

159160
**NOTE**
160161

geolocator_platform_interface/lib/src/geolocator_platform_interface.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ abstract class GeolocatorPlatform extends PlatformInterface {
130130
///
131131
/// An instance of [LocationServiceStatus] will be emitted each time the
132132
/// location service is enabled or disabled.
133-
/// Throws an [UnimplementedError] on the web as the concept of location
134-
/// service doesn't exist on the web platform.
135133
Stream<ServiceStatus> getServiceStatusStream() {
136134
throw UnimplementedError(
137135
'getServiceStatusStream() has not been implemented.');

geolocator_web/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 3.0.0
2+
3+
**BREAKING CHANGE:**
4+
- `getServiceStatusStream` on web returns a PlatformException i.s.o. UnimplementedError. As the concept of location service doesn't exist on the web platform.
5+
16
## 2.2.1
27

38
- Migrates tests to support sound null safety.

geolocator_web/lib/geolocator_web.dart

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'dart:async';
22

33
import 'package:flutter/material.dart';
4-
import 'package:flutter/services.dart';
54
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
65
import 'package:geolocator_platform_interface/geolocator_platform_interface.dart';
76
import 'src/geolocation_manager.dart';
@@ -115,6 +114,10 @@ class GeolocatorPlugin extends GeolocatorPlatform {
115114
});
116115
}
117116

117+
@override
118+
Stream<ServiceStatus> getServiceStatusStream() =>
119+
throw _unsupported('getServiceStatusStream');
120+
118121
@override
119122
Future<bool> openAppSettings() => throw _unsupported('openAppSettings');
120123

@@ -139,10 +142,9 @@ class GeolocatorPlugin extends GeolocatorPlatform {
139142
}
140143
}
141144

142-
PlatformException _unsupported(String method) {
143-
return PlatformException(
144-
code: 'UNSUPPORTED_OPERATION',
145-
message: '$method is not supported on the web platform.',
145+
UnsupportedError _unsupported(String method) {
146+
return UnsupportedError(
147+
'$method is not supported on the web platform.',
146148
);
147149
}
148150
}

geolocator_web/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: geolocator_web
22
description: Official web implementation of the geolocator plugin.
33
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_web
44
issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen
5-
version: 2.2.1
5+
version: 3.0.0
66

77
flutter:
88
plugin:

geolocator_web/test/geolocator_web_test.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import 'package:flutter/services.dart';
21
import 'package:flutter_test/flutter_test.dart';
32
import 'package:geolocator_web/geolocator_web.dart';
43
import 'package:geolocator_web/src/geolocation_manager.dart';
@@ -117,17 +116,22 @@ void main() {
117116
group('Unsupported exceptions', () {
118117
test('getLastKnownPosition throws unsupported exception', () async {
119118
expect(geolocatorPlugin.getLastKnownPosition,
120-
throwsA(isA<PlatformException>()));
119+
throwsA(isA<UnsupportedError>()));
121120
});
122121

123122
test('openAppSettings throws unsupported exception', () async {
124123
expect(
125-
geolocatorPlugin.openAppSettings, throwsA(isA<PlatformException>()));
124+
geolocatorPlugin.openAppSettings, throwsA(isA<UnsupportedError>()));
126125
});
127126

128127
test('openLocationSettings throws unsupported exception', () async {
129128
expect(geolocatorPlugin.openLocationSettings,
130-
throwsA(isA<PlatformException>()));
129+
throwsA(isA<UnsupportedError>()));
130+
});
131+
132+
test('getServiceStatusStream throws unsupported exception', () async {
133+
expect(geolocatorPlugin.getServiceStatusStream,
134+
throwsA(isA<UnsupportedError>()));
131135
});
132136
});
133137
}

0 commit comments

Comments
 (0)