File tree Expand file tree Collapse file tree 3 files changed +32
-3
lines changed
Expand file tree Collapse file tree 3 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import '../exceptions/incorrect_setup_exception.dart';
99import '../exceptions/permission_denied_exception.dart' as lm;
1010import '../exceptions/permission_requesting_exception.dart' as lm;
1111import '../exceptions/service_disabled_exception.dart' ;
12+ import '../exceptions/unsupported_exception.dart' ;
1213import '../widgets/current_location_layer.dart' ;
1314import 'data.dart' ;
1415
@@ -63,8 +64,12 @@ class LocationMarkerDataStreamFactory {
6364 /// Create a heading stream which is used as default value of
6465 /// [CurrentLocationLayer.headingStream] .
6566 Stream <OrientationEvent > defaultHeadingStreamSource () {
66- RotationSensor .samplingPeriod = SensorInterval .uiInterval;
67- return RotationSensor .orientationStream;
67+ if (RotationSensor .isPlatformSupported) {
68+ RotationSensor .samplingPeriod = SensorInterval .uiInterval;
69+ return RotationSensor .orientationStream;
70+ } else {
71+ return Stream .error (UnsupportedException ());
72+ }
6873 }
6974}
7075
Original file line number Diff line number Diff line change 1+ import 'package:flutter/foundation.dart' ;
2+
3+ /// An exception thrown when an operation is not supported on the current
4+ /// platform.
5+ class UnsupportedException implements Exception {
6+ /// Create an UnsupportedException.
7+ const UnsupportedException ();
8+
9+ @override
10+ String toString () {
11+ final platform = kIsWeb ? 'web' : defaultTargetPlatform.name;
12+ return 'FlutterRotationSensor does not support the $platform platform.' ;
13+ }
14+ }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import '../exceptions/incorrect_setup_exception.dart';
1313import '../exceptions/permission_denied_exception.dart' ;
1414import '../exceptions/permission_requesting_exception.dart' ;
1515import '../exceptions/service_disabled_exception.dart' ;
16+ import '../exceptions/unsupported_exception.dart' ;
1617import '../options/align_on_update.dart' ;
1718import '../options/focal_point.dart' ;
1819import '../options/indicators.dart' ;
@@ -413,6 +414,10 @@ class _CurrentLocationLayerState extends State<CurrentLocationLayer>
413414 setState (() => _status = _Status .permissionDenied);
414415 case ServiceDisabledException _:
415416 setState (() => _status = _Status .serviceDisabled);
417+ case UnsupportedException unsupportedException:
418+ if (kDebugMode) {
419+ print (unsupportedException);
420+ }
416421 }
417422 _headingSubscription? .cancel ();
418423 },
@@ -455,7 +460,12 @@ class _CurrentLocationLayerState extends State<CurrentLocationLayer>
455460 }
456461 }
457462 },
458- onError: (_) {
463+ onError: (error) {
464+ if (error is UnsupportedException ) {
465+ if (kDebugMode) {
466+ print (error);
467+ }
468+ }
459469 if (_animatingHeading != null ) {
460470 setState (() => _animatingHeading = null );
461471 }
You can’t perform that action at this time.
0 commit comments