From 0be5d4799463eb66ecd1c42d0e5f2b3caa6ef17f Mon Sep 17 00:00:00 2001 From: taleb Date: Sat, 5 Jun 2021 17:35:12 +0430 Subject: [PATCH 1/5] migrate to null-safety --- example/.flutter-plugins-dependencies | 2 +- example/ios/Flutter/Flutter.podspec | 18 -------------- example/lib/tab_location.dart | 34 ++++++++++++------------- example/lib/tab_settings.dart | 24 +++++++++--------- example/lib/tab_track.dart | 36 +++++++++++++-------------- example/pubspec.yaml | 4 +-- lib/channel/codec.dart | 12 ++++----- lib/channel/helper.dart | 4 +-- lib/channel/location_channel.dart | 30 +++++++++++----------- lib/channel/param.dart | 4 +-- lib/data/location.dart | 8 +++--- lib/data/location_result.dart | 6 ++--- lib/data/result.dart | 16 ++++++------ lib/facet_android/location.dart | 12 ++++----- lib/facet_android/result.dart | 2 +- lib/geolocation.dart | 10 ++++---- pubspec.yaml | 2 +- 17 files changed, 103 insertions(+), 121 deletions(-) delete mode 100644 example/ios/Flutter/Flutter.podspec diff --git a/example/.flutter-plugins-dependencies b/example/.flutter-plugins-dependencies index 5b9d6d4..f489970 100644 --- a/example/.flutter-plugins-dependencies +++ b/example/.flutter-plugins-dependencies @@ -1 +1 @@ -{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"geolocation","dependencies":["streams_channel"]},{"name":"streams_channel","dependencies":[]}]} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"geolocation","path":"/Users/taleb/FlutterProjects/geolocation/","dependencies":["streams_channel"]},{"name":"streams_channel","path":"/Users/taleb/.pub-cache/hosted/pub.dartlang.org/streams_channel-0.3.0/","dependencies":[]}],"android":[{"name":"geolocation","path":"/Users/taleb/FlutterProjects/geolocation/","dependencies":["streams_channel"]},{"name":"streams_channel","path":"/Users/taleb/.pub-cache/hosted/pub.dartlang.org/streams_channel-0.3.0/","dependencies":[]}],"macos":[],"linux":[],"windows":[],"web":[]},"dependencyGraph":[{"name":"geolocation","dependencies":["streams_channel"]},{"name":"streams_channel","dependencies":[]}],"date_created":"2021-06-05 17:32:11.340882","version":"2.2.1"} \ No newline at end of file diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec deleted file mode 100644 index 5ca3041..0000000 --- a/example/ios/Flutter/Flutter.podspec +++ /dev/null @@ -1,18 +0,0 @@ -# -# NOTE: This podspec is NOT to be published. It is only used as a local source! -# - -Pod::Spec.new do |s| - s.name = 'Flutter' - s.version = '1.0.0' - s.summary = 'High-performance, high-fidelity mobile apps.' - s.description = <<-DESC -Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS. - DESC - s.homepage = 'https://flutter.io' - s.license = { :type => 'MIT' } - s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } - s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } - s.ios.deployment_target = '8.0' - s.vendored_frameworks = 'Flutter.framework' -end diff --git a/example/lib/tab_location.dart b/example/lib/tab_location.dart index 943ccf9..c5b59ab 100644 --- a/example/lib/tab_location.dart +++ b/example/lib/tab_location.dart @@ -128,9 +128,9 @@ class _TabLocationState extends State { class _Header extends StatelessWidget { _Header( - {@required this.onLastKnownPressed, - @required this.onCurrentPressed, - @required this.onSingleUpdatePressed}); + {required this.onLastKnownPressed, + required this.onCurrentPressed, + required this.onSingleUpdatePressed}); final VoidCallback onLastKnownPressed; final VoidCallback onCurrentPressed; @@ -173,7 +173,7 @@ class _Header extends StatelessWidget { class _HeaderButton extends StatelessWidget { _HeaderButton( - {@required this.title, @required this.color, @required this.onTap}); + {required this.title, required this.color, required this.onTap}); final String title; final Color color; @@ -204,7 +204,7 @@ class _HeaderButton extends StatelessWidget { } class _Item extends StatelessWidget { - _Item({@required this.data}); + _Item({required this.data}); final LocationData data; @@ -213,14 +213,14 @@ class _Item extends StatelessWidget { final List content = []; if (data.result != null) { - String text; - if (data.result.isSuccessful) { + late String text; + if (data.result!.isSuccessful!) { text = - 'Lat: ${data.result.location.latitude} - Lng: ${data.result.location.longitude}'; + 'Lat: ${data.result!.location.latitude} - Lng: ${data.result!.location.longitude}'; } else { - switch (data.result.error.type) { + switch (data.result!.error!.type) { case GeolocationResultErrorType.runtime: - text = 'Failure: ${data.result.error.message}'; + text = 'Failure: ${data.result!.error!.message}'; break; case GeolocationResultErrorType.locationNotFound: text = 'Location not found'; @@ -236,7 +236,7 @@ class _Item extends StatelessWidget { break; case GeolocationResultErrorType.playServicesUnavailable: text = - 'Play services unavailable: ${data.result.error.additionalInfo}'; + 'Play services unavailable: ${data.result!.error!.additionalInfo}'; break; } } @@ -310,18 +310,18 @@ class _Item extends StatelessWidget { class LocationData { LocationData({ - @required this.id, + required this.id, this.result, - @required this.origin, - @required this.color, - @required this.createdAtTimestamp, + required this.origin, + required this.color, + required this.createdAtTimestamp, this.elapsedTimeSeconds, }); final int id; - final LocationResult result; + final LocationResult? result; final String origin; final Color color; final int createdAtTimestamp; - final int elapsedTimeSeconds; + final int? elapsedTimeSeconds; } diff --git a/example/lib/tab_settings.dart b/example/lib/tab_settings.dart index aafe01c..cd3b828 100644 --- a/example/lib/tab_settings.dart +++ b/example/lib/tab_settings.dart @@ -13,8 +13,8 @@ class TabSettings extends StatefulWidget { } class _TabSettingsState extends State { - GeolocationResult _locationOperationalResult; - GeolocationResult _requestPermissionResult; + GeolocationResult? _locationOperationalResult; + GeolocationResult? _requestPermissionResult; _checkLocationOperational() async { final GeolocationResult result = await Geolocation.isLocationOperational(); @@ -71,32 +71,32 @@ class _TabSettingsState extends State { class _Item extends StatelessWidget { _Item({ - @required this.title, - @required this.successLabel, - @required this.result, - @required this.onPressed, + required this.title, + required this.successLabel, + required this.result, + required this.onPressed, }); final String title; final String successLabel; - final GeolocationResult result; + final GeolocationResult? result; final VoidCallback onPressed; @override Widget build(BuildContext context) { - String value; + String? value; String status; Color color; if (result != null) { - if (result.isSuccessful) { + if (result!.isSuccessful!) { value = successLabel; status = 'success'; color = Colors.green; } else { - switch (result.error.type) { + switch (result!.error!.type) { case GeolocationResultErrorType.runtime: - value = 'Failure: ${result.error.message}'; + value = 'Failure: ${result!.error!.message}'; break; case GeolocationResultErrorType.locationNotFound: value = 'Location not found'; @@ -111,7 +111,7 @@ class _Item extends StatelessWidget { value = 'Permission denied'; break; case GeolocationResultErrorType.playServicesUnavailable: - value = 'Play services unavailable: ${result.error.additionalInfo}'; + value = 'Play services unavailable: ${result!.error!.additionalInfo}'; break; } diff --git a/example/lib/tab_track.dart b/example/lib/tab_track.dart index 53e09c6..6360839 100644 --- a/example/lib/tab_track.dart +++ b/example/lib/tab_track.dart @@ -16,14 +16,14 @@ class TabTrack extends StatefulWidget { class _TabTrackState extends State { List<_LocationData> _locations = []; - StreamSubscription _subscription; - int _subscriptionStartedTimestamp; + StreamSubscription? _subscription; + int? _subscriptionStartedTimestamp; bool _isTracking = false; @override dispose() { super.dispose(); - _subscription.cancel(); + _subscription!.cancel(); } _onTogglePressed() { @@ -32,7 +32,7 @@ class _TabTrackState extends State { _isTracking = false; }); - _subscription.cancel(); + _subscription!.cancel(); _subscription = null; _subscriptionStartedTimestamp = null; } else { @@ -49,7 +49,7 @@ class _TabTrackState extends State { final location = new _LocationData( result: result, elapsedTimeSeconds: (new DateTime.now().millisecondsSinceEpoch - - _subscriptionStartedTimestamp) ~/ + _subscriptionStartedTimestamp!) ~/ 1000, ); @@ -58,7 +58,7 @@ class _TabTrackState extends State { }); }); - _subscription.onDone(() { + _subscription!.onDone(() { setState(() { _isTracking = false; }); @@ -92,10 +92,10 @@ class _TabTrackState extends State { } class _Header extends StatelessWidget { - _Header({@required this.isRunning, this.onTogglePressed}); + _Header({required this.isRunning, this.onTogglePressed}); final bool isRunning; - final VoidCallback onTogglePressed; + final VoidCallback? onTogglePressed; @override Widget build(BuildContext context) { @@ -114,11 +114,11 @@ class _Header extends StatelessWidget { class _HeaderButton extends StatelessWidget { _HeaderButton( - {@required this.title, @required this.color, @required this.onTap}); + {required this.title, required this.color, required this.onTap}); final String title; final Color color; - final VoidCallback onTap; + final VoidCallback? onTap; @override Widget build(BuildContext context) { @@ -145,25 +145,25 @@ class _HeaderButton extends StatelessWidget { } class _Item extends StatelessWidget { - _Item({@required this.data}); + _Item({required this.data}); final _LocationData data; @override Widget build(BuildContext context) { - String text; + late String text; String status; Color color; - if (data.result.isSuccessful) { + if (data.result.isSuccessful!) { text = 'Lat: ${data.result.location.latitude} - Lng: ${data.result.location.longitude}'; status = 'success'; color = Colors.green; } else { - switch (data.result.error.type) { + switch (data.result.error!.type) { case GeolocationResultErrorType.runtime: - text = 'Failure: ${data.result.error.message}'; + text = 'Failure: ${data.result.error!.message}'; break; case GeolocationResultErrorType.locationNotFound: text = 'Location not found'; @@ -179,7 +179,7 @@ class _Item extends StatelessWidget { break; case GeolocationResultErrorType.playServicesUnavailable: text = - 'Play services unavailable: ${data.result.error.additionalInfo}'; + 'Play services unavailable: ${data.result.error!.additionalInfo}'; break; } @@ -249,8 +249,8 @@ class _Item extends StatelessWidget { class _LocationData { _LocationData({ - @required this.result, - @required this.elapsedTimeSeconds, + required this.result, + required this.elapsedTimeSeconds, }); final LocationResult result; diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 8125a58..a2c8459 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -4,13 +4,13 @@ version: 1.0.0+1 publish_to: "none" environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: sdk: flutter - cupertino_icons: ^0.1.2 + cupertino_icons: ^1.0.3 dev_dependencies: geolocation: diff --git a/lib/channel/codec.dart b/lib/channel/codec.dart index d99b6b1..159626d 100644 --- a/lib/channel/codec.dart +++ b/lib/channel/codec.dart @@ -23,7 +23,7 @@ class _Codec { json.encode(_JsonCodec.permissionRequestToJson(request)); // see: https://stackoverflow.com/questions/49611724/dart-how-to-json-decode-0-as-double - static double parseJsonNumber(dynamic value) { + static double? parseJsonNumber(dynamic value) { return value.runtimeType == int ? (value as int).toDouble() : value; } @@ -36,8 +36,8 @@ class _Codec { } static dynamic platformSpecific({ - @required dynamic android, - @required dynamic ios, + required dynamic android, + required dynamic ios, }) { if (Platform.isAndroid) { return android; @@ -50,8 +50,8 @@ class _Codec { } static Map platformSpecificMap({ - @required Map android, - @required Map ios, + required Map android, + required Map ios, }) { if (Platform.isAndroid) { return android; @@ -72,7 +72,7 @@ class _JsonCodec { ); static GeolocationResultError resultErrorFromJson(Map json) { - final GeolocationResultErrorType type = + final GeolocationResultErrorType? type = _mapResultErrorTypeJson(json['type']); var additionalInfo; diff --git a/lib/channel/helper.dart b/lib/channel/helper.dart index fbd7030..980eae8 100644 --- a/lib/channel/helper.dart +++ b/lib/channel/helper.dart @@ -3,11 +3,11 @@ part of geolocation; -Future _invokeChannelMethod( +Future _invokeChannelMethod( String tag, MethodChannel channel, String method, [dynamic arguments]) async { _log('invoke ${channel.name}->$method [$arguments]', tag: tag); - String data; + String? data; try { data = await channel.invokeMethod(method, arguments); } catch (exception, stack) { diff --git a/lib/channel/location_channel.dart b/lib/channel/location_channel.dart index 54e340d..e8690f5 100644 --- a/lib/channel/location_channel.dart +++ b/lib/channel/location_channel.dart @@ -36,40 +36,40 @@ class _LocationChannel { Future isLocationOperational( LocationPermission permission) async { - final response = await _invokeChannelMethod( + final response = await (_invokeChannelMethod( _loggingTag, _channel, 'isLocationOperational', _Codec.encodeLocationPermission(permission), - ); + ) as FutureOr); return _Codec.decodeResult(response); } Future requestLocationPermission( _PermissionRequest request) async { - final response = await _invokeChannelMethod( + final response = await (_invokeChannelMethod( _loggingTag, _channel, 'requestLocationPermission', _Codec.encodePermissionRequest(request), - ); + ) as FutureOr); return _Codec.decodeResult(response); } Future enableLocationServices() async { - final response = await _invokeChannelMethod( - _loggingTag, _channel, 'enableLocationServices', ''); + final response = await (_invokeChannelMethod( + _loggingTag, _channel, 'enableLocationServices', '') as FutureOr); return _Codec.decodeResult(response); } Future lastKnownLocation( LocationPermission permission) async { - final response = await _invokeChannelMethod( + final response = await (_invokeChannelMethod( _loggingTag, _channel, 'lastKnownLocation', _Codec.encodeLocationPermission(permission), - ); + ) as FutureOr); return _Codec.decodeLocationResult(response); } @@ -78,8 +78,8 @@ class _LocationChannel { // can start the location request if it's the first subscription or update ongoing request with new params if needed Stream locationUpdates(_LocationUpdatesRequest request) { // The stream that will be returned for the current updates request - StreamController controller; - _LocationUpdatesSubscription subscription; + late StreamController controller; + _LocationUpdatesSubscription? subscription; final StreamSubscription updatesSubscription = _updatesStream.listen((LocationResult result) { @@ -88,7 +88,7 @@ class _LocationChannel { // [_LocationUpdateStrategy.current] and [_LocationUpdateStrategy.single] only get a single result, then closes if (request.strategy != _LocationUpdateStrategy.continuous) { - subscription.subscription.cancel(); + subscription!.subscription.cancel(); _updatesSubscriptions.remove(subscription); controller.close(); } @@ -100,7 +100,7 @@ class _LocationChannel { // Uniquely identify each request, in order to be able to manipulate each request of platform side request.id = (_updatesSubscriptions.isNotEmpty - ? _updatesSubscriptions.map((it) => it.requestId).reduce(math.max) + ? _updatesSubscriptions.map((it) => it.requestId ?? -1).reduce(math.max) : 0) + 1; @@ -112,7 +112,7 @@ class _LocationChannel { controller = new StreamController.broadcast( onListen: () { - _log('add location updates [id=${subscription.requestId}]'); + _log('add location updates [id=${subscription!.requestId}]'); _invokeChannelMethod( _loggingTag, _channel, @@ -121,7 +121,7 @@ class _LocationChannel { ); }, onCancel: () { - _log('remove location updates [id=${subscription.requestId}]'); + _log('remove location updates [id=${subscription!.requestId}]'); subscription.subscription.cancel(); _updatesSubscriptions.remove(subscription); @@ -141,6 +141,6 @@ class _LocationChannel { class _LocationUpdatesSubscription { _LocationUpdatesSubscription(this.requestId, this.subscription); - final int requestId; + final int? requestId; final StreamSubscription subscription; } diff --git a/lib/channel/param.dart b/lib/channel/param.dart index 784d099..1ced844 100644 --- a/lib/channel/param.dart +++ b/lib/channel/param.dart @@ -16,7 +16,7 @@ class _LocationUpdatesRequest { assert(displacementFilter >= 0.0); } - int id; + int? id; final _LocationUpdateStrategy strategy; final LocationPermission permission; final LocationAccuracy accuracy; @@ -31,7 +31,7 @@ enum _LocationUpdateStrategy { current, single, continuous } class _PermissionRequest { _PermissionRequest( this.value, { - @required this.openSettingsIfDenied, + required this.openSettingsIfDenied, }); final LocationPermission value; final bool openSettingsIfDenied; diff --git a/lib/data/location.dart b/lib/data/location.dart index 43f0dab..6875b0a 100644 --- a/lib/data/location.dart +++ b/lib/data/location.dart @@ -7,13 +7,13 @@ class Location { Location._(this.latitude, this.longitude, this.altitude, this.isMocked); /// Latitude in degrees - final double latitude; + final double? latitude; /// Longitude in degrees - final double longitude; + final double? longitude; /// Altitude measured in meters. - final double altitude; + final double? altitude; final bool isMocked; @@ -36,7 +36,7 @@ class Location { class LocationAccuracy { /// In case the common ground constants are not satisfactory, you can build a custom [LocationAccuracy] /// using specific platform values. - const LocationAccuracy({@required this.android, @required this.ios}); + const LocationAccuracy({required this.android, required this.ios}); final LocationPriorityAndroid android; final LocationAccuracyIOS ios; diff --git a/lib/data/location_result.dart b/lib/data/location_result.dart index 1ee372e..3f90749 100644 --- a/lib/data/location_result.dart +++ b/lib/data/location_result.dart @@ -13,18 +13,18 @@ part of geolocation; /// * [GeolocationResultError], which contains details on why/what failed. class LocationResult extends GeolocationResult { LocationResult._( - bool isSuccessful, GeolocationResultError error, this.locations) + bool? isSuccessful, GeolocationResultError? error, this.locations) : super._(isSuccessful, error); /// Location updates might return more than one location at once. It contains /// all the locations that were retrieved by the device since the previous result. /// Locations are ordered from oldest to newest. /// If [isSuccessful] is `true`, [locations] is guaranteed to contain at least one [Location]. - final List locations; + final List? locations; /// Most up-to-date location. /// If [isSuccessful] is `true`, [location] is guaranteed to contain a [Location]. - Location get location => locations.last; + Location get location => locations!.last; @override String dataToString() { diff --git a/lib/data/result.dart b/lib/data/result.dart index ff4b72c..a3d4c1e 100644 --- a/lib/data/result.dart +++ b/lib/data/result.dart @@ -17,11 +17,11 @@ class GeolocationResult { this.error, ) { assert(isSuccessful != null); - assert(isSuccessful || error != null); + assert(isSuccessful! || error != null); } - final bool isSuccessful; - final GeolocationResultError error; + final bool? isSuccessful; + final GeolocationResultError? error; String dataToString() { return "without additional data"; @@ -29,7 +29,7 @@ class GeolocationResult { @override String toString() { - if (isSuccessful) { + if (isSuccessful!) { return '{success: ${dataToString()} }'; } else { return '{failure: $error }'; @@ -44,8 +44,8 @@ class GeolocationResultError { this.additionalInfo, ); - final GeolocationResultErrorType type; - final String message; + final GeolocationResultErrorType? type; + final String? message; final dynamic additionalInfo; @override @@ -63,7 +63,7 @@ class GeolocationResultError { return 'play services -> $additionalInfo'; default: assert(false); - return null; + return ''; } } } @@ -77,7 +77,7 @@ enum GeolocationResultErrorType { playServicesUnavailable, } -GeolocationResultErrorType _mapResultErrorTypeJson(String jsonValue) { +GeolocationResultErrorType? _mapResultErrorTypeJson(String? jsonValue) { switch (jsonValue) { case 'runtime': return GeolocationResultErrorType.runtime; diff --git a/lib/facet_android/location.dart b/lib/facet_android/location.dart index aba51ce..b12e159 100644 --- a/lib/facet_android/location.dart +++ b/lib/facet_android/location.dart @@ -36,14 +36,14 @@ class LocationOptionsAndroid { fastestInterval: 2500, ); - final int interval; - final int fastestInterval; - final int expirationTime; - final int expirationDuration; - final int maxWaitTime; + final int? interval; + final int? fastestInterval; + final int? expirationTime; + final int? expirationDuration; + final int? maxWaitTime; /// Always `1` in single location request - final int numUpdates; + final int? numUpdates; Map toJson() => { 'interval': interval, diff --git a/lib/facet_android/result.dart b/lib/facet_android/result.dart index 3595487..39bea7d 100644 --- a/lib/facet_android/result.dart +++ b/lib/facet_android/result.dart @@ -11,7 +11,7 @@ enum GeolocationAndroidPlayServices { invalid, } -GeolocationAndroidPlayServices _mapPlayServicesJson(String jsonValue) { +GeolocationAndroidPlayServices? _mapPlayServicesJson(String? jsonValue) { switch (jsonValue) { case 'missing': return GeolocationAndroidPlayServices.missing; diff --git a/lib/geolocation.dart b/lib/geolocation.dart index 9e5b4ec..3081c60 100644 --- a/lib/geolocation.dart +++ b/lib/geolocation.dart @@ -123,7 +123,7 @@ class Geolocation { /// * Android behaviour: /// * iOS behaviour: static Stream singleLocationUpdate({ - @required LocationAccuracy accuracy, + required LocationAccuracy accuracy, bool inBackground = false, LocationPermission permission = const LocationPermission(), LocationOptionsAndroid androidOptions = @@ -162,7 +162,7 @@ class Geolocation { /// * [singleLocationUpdate], for more explanation on how single location update work. /// * [LocationResult], the result you can expect from this request. static Stream currentLocation({ - @required LocationAccuracy accuracy, + required LocationAccuracy accuracy, bool inBackground = false, LocationPermission permission = const LocationPermission(), LocationOptionsAndroid androidOptions = @@ -197,7 +197,7 @@ class Geolocation { /// * Android behaviour: /// * iOS behaviour: static Stream locationUpdates({ - @required LocationAccuracy accuracy, + required LocationAccuracy accuracy, double displacementFilter = 0.0, bool inBackground = false, LocationPermission permission = const LocationPermission(), @@ -224,7 +224,7 @@ class Geolocation { class GeolocationException implements Exception { GeolocationException(this.message); - final String message; + final String? message; @override String toString() { @@ -232,7 +232,7 @@ class GeolocationException implements Exception { } } -_log(String message, {String tag}) { +_log(String? message, {String? tag}) { if (Geolocation.loggingEnabled) { debugPrint(tag != null ? '$tag: $message' : message); } diff --git a/pubspec.yaml b/pubspec.yaml index 0101585..5767f33 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,7 +6,7 @@ version: 1.1.2 homepage: https://github.com/loup-v/geolocation/ environment: - sdk: ">=2.1.0 <3.0.0" + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: From a5b8328a42c28323041a1d0876e1f65f0db7d9c8 Mon Sep 17 00:00:00 2001 From: taleb Date: Sat, 5 Jun 2021 19:33:33 +0430 Subject: [PATCH 2/5] migrate to null-saftey --- lib/channel/location_channel.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/channel/location_channel.dart b/lib/channel/location_channel.dart index e8690f5..0db3cb8 100644 --- a/lib/channel/location_channel.dart +++ b/lib/channel/location_channel.dart @@ -69,7 +69,7 @@ class _LocationChannel { _channel, 'lastKnownLocation', _Codec.encodeLocationPermission(permission), - ) as FutureOr); + ) as FutureOr); return _Codec.decodeLocationResult(response); } From 1cdedb067d2b8b11003717e03e076000e076c2d5 Mon Sep 17 00:00:00 2001 From: taleb Date: Sat, 5 Jun 2021 19:34:30 +0430 Subject: [PATCH 3/5] migrate to null-saftey --- lib/channel/location_channel.dart | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/channel/location_channel.dart b/lib/channel/location_channel.dart index 0db3cb8..342407e 100644 --- a/lib/channel/location_channel.dart +++ b/lib/channel/location_channel.dart @@ -58,19 +58,20 @@ class _LocationChannel { Future enableLocationServices() async { final response = await (_invokeChannelMethod( - _loggingTag, _channel, 'enableLocationServices', '') as FutureOr); + _loggingTag, _channel, 'enableLocationServices', '') + as FutureOr); return _Codec.decodeResult(response); } Future lastKnownLocation( LocationPermission permission) async { - final response = await (_invokeChannelMethod( + final response = await _invokeChannelMethod( _loggingTag, _channel, 'lastKnownLocation', _Codec.encodeLocationPermission(permission), - ) as FutureOr); - return _Codec.decodeLocationResult(response); + ); + return _Codec.decodeLocationResult(response ?? ''); } // Creates a new subscription to the channel stream and notifies @@ -100,7 +101,9 @@ class _LocationChannel { // Uniquely identify each request, in order to be able to manipulate each request of platform side request.id = (_updatesSubscriptions.isNotEmpty - ? _updatesSubscriptions.map((it) => it.requestId ?? -1).reduce(math.max) + ? _updatesSubscriptions + .map((it) => it.requestId ?? -1) + .reduce(math.max) : 0) + 1; From ca41ef495dee1c8b98f285eab9694876d99159dd Mon Sep 17 00:00:00 2001 From: taleb Date: Sun, 13 Jun 2021 00:50:05 +0430 Subject: [PATCH 4/5] fix ovveride of Application.ActivityLifecycleCallbacks methods --- .../app/loup/geolocation/GeolocationPlugin.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/android/src/main/kotlin/app/loup/geolocation/GeolocationPlugin.kt b/android/src/main/kotlin/app/loup/geolocation/GeolocationPlugin.kt index 9630b88..84f557c 100644 --- a/android/src/main/kotlin/app/loup/geolocation/GeolocationPlugin.kt +++ b/android/src/main/kotlin/app/loup/geolocation/GeolocationPlugin.kt @@ -103,31 +103,31 @@ public class GeolocationPlugin : FlutterPlugin, ActivityAware, Application.Activ // Application.ActivityLifecycleCallbacks - override fun onActivityPaused(activity: Activity?) { + override fun onActivityPaused(activity: Activity) { locationClient.pause() } - override fun onActivityResumed(activity: Activity?) { + override fun onActivityResumed(activity: Activity) { locationClient.resume() } - override fun onActivityStarted(activity: Activity?) { + override fun onActivityStarted(activity: Activity) { } - override fun onActivityDestroyed(activity: Activity?) { + override fun onActivityDestroyed(activity: Activity) { } - override fun onActivitySaveInstanceState(activity: Activity?, outState: Bundle?) { + override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) { } - override fun onActivityStopped(activity: Activity?) { + override fun onActivityStopped(activity: Activity) { } - override fun onActivityCreated(activity: Activity?, savedInstanceState: Bundle?) { + override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { } From b008dcf0dd897302873447ac9f9edd88cdc9281e Mon Sep 17 00:00:00 2001 From: taleb Date: Sun, 13 Jun 2021 00:55:43 +0430 Subject: [PATCH 5/5] fix ovveride of Application.ActivityLifecycleCallbacks methods --- .../src/main/kotlin/app/loup/geolocation/GeolocationPlugin.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/kotlin/app/loup/geolocation/GeolocationPlugin.kt b/android/src/main/kotlin/app/loup/geolocation/GeolocationPlugin.kt index 84f557c..119ea5c 100644 --- a/android/src/main/kotlin/app/loup/geolocation/GeolocationPlugin.kt +++ b/android/src/main/kotlin/app/loup/geolocation/GeolocationPlugin.kt @@ -119,7 +119,7 @@ public class GeolocationPlugin : FlutterPlugin, ActivityAware, Application.Activ } - override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle?) { + override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) { }