Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to null-safety #71

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {

}

Expand Down
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -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":[]}]}
{"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"}
18 changes: 0 additions & 18 deletions example/ios/Flutter/Flutter.podspec

This file was deleted.

34 changes: 17 additions & 17 deletions example/lib/tab_location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ class _TabLocationState extends State<TabLocation> {

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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -204,7 +204,7 @@ class _HeaderButton extends StatelessWidget {
}

class _Item extends StatelessWidget {
_Item({@required this.data});
_Item({required this.data});

final LocationData data;

Expand All @@ -213,14 +213,14 @@ class _Item extends StatelessWidget {
final List<Widget> content = <Widget>[];

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';
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
24 changes: 12 additions & 12 deletions example/lib/tab_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class TabSettings extends StatefulWidget {
}

class _TabSettingsState extends State<TabSettings> {
GeolocationResult _locationOperationalResult;
GeolocationResult _requestPermissionResult;
GeolocationResult? _locationOperationalResult;
GeolocationResult? _requestPermissionResult;

_checkLocationOperational() async {
final GeolocationResult result = await Geolocation.isLocationOperational();
Expand Down Expand Up @@ -71,32 +71,32 @@ class _TabSettingsState extends State<TabSettings> {

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';
Expand All @@ -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;
}

Expand Down
36 changes: 18 additions & 18 deletions example/lib/tab_track.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class TabTrack extends StatefulWidget {

class _TabTrackState extends State<TabTrack> {
List<_LocationData> _locations = [];
StreamSubscription<LocationResult> _subscription;
int _subscriptionStartedTimestamp;
StreamSubscription<LocationResult>? _subscription;
int? _subscriptionStartedTimestamp;
bool _isTracking = false;

@override
dispose() {
super.dispose();
_subscription.cancel();
_subscription!.cancel();
}

_onTogglePressed() {
Expand All @@ -32,7 +32,7 @@ class _TabTrackState extends State<TabTrack> {
_isTracking = false;
});

_subscription.cancel();
_subscription!.cancel();
_subscription = null;
_subscriptionStartedTimestamp = null;
} else {
Expand All @@ -49,7 +49,7 @@ class _TabTrackState extends State<TabTrack> {
final location = new _LocationData(
result: result,
elapsedTimeSeconds: (new DateTime.now().millisecondsSinceEpoch -
_subscriptionStartedTimestamp) ~/
_subscriptionStartedTimestamp!) ~/
1000,
);

Expand All @@ -58,7 +58,7 @@ class _TabTrackState extends State<TabTrack> {
});
});

_subscription.onDone(() {
_subscription!.onDone(() {
setState(() {
_isTracking = false;
});
Expand Down Expand Up @@ -92,10 +92,10 @@ class _TabTrackState extends State<TabTrack> {
}

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) {
Expand All @@ -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) {
Expand All @@ -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';
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions lib/channel/codec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -50,8 +50,8 @@ class _Codec {
}

static Map<String, dynamic> platformSpecificMap({
@required Map<String, dynamic> android,
@required Map<String, dynamic> ios,
required Map<String, dynamic> android,
required Map<String, dynamic> ios,
}) {
if (Platform.isAndroid) {
return android;
Expand All @@ -72,7 +72,7 @@ class _JsonCodec {
);

static GeolocationResultError resultErrorFromJson(Map<String, dynamic> json) {
final GeolocationResultErrorType type =
final GeolocationResultErrorType? type =
_mapResultErrorTypeJson(json['type']);

var additionalInfo;
Expand Down
Loading