Skip to content

Commit deaa857

Browse files
committed
Refactor code formatting in geolocator_android.dart and foreground_settings.dart for improved readability
1 parent ac62031 commit deaa857

File tree

2 files changed

+64
-68
lines changed

2 files changed

+64
-68
lines changed

geolocator_android/lib/src/geolocator_android.dart

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,21 @@ import 'package:uuid/uuid.dart';
88
/// An implementation of [GeolocatorPlatform] that uses method channels.
99
class GeolocatorAndroid extends GeolocatorPlatform {
1010
/// The method channel used to interact with the native platform.
11-
static const _methodChannel =
12-
MethodChannel('flutter.baseflow.com/geolocator_android');
11+
static const _methodChannel = MethodChannel(
12+
'flutter.baseflow.com/geolocator_android',
13+
);
1314

1415
/// The event channel used to receive [Position] updates from the native
1516
/// platform.
16-
static const _eventChannel =
17-
EventChannel('flutter.baseflow.com/geolocator_updates_android');
17+
static const _eventChannel = EventChannel(
18+
'flutter.baseflow.com/geolocator_updates_android',
19+
);
1820

1921
/// The event channel used to receive [LocationServiceStatus] updates from the
2022
/// native platform.
21-
static const _serviceStatusEventChannel =
22-
EventChannel('flutter.baseflow.com/geolocator_service_updates_android');
23+
static const _serviceStatusEventChannel = EventChannel(
24+
'flutter.baseflow.com/geolocator_service_updates_android',
25+
);
2326

2427
/// Registers this class as the default instance of [GeolocatorPlatform].
2528
static void registerWith() {
@@ -41,8 +44,9 @@ class GeolocatorAndroid extends GeolocatorPlatform {
4144
Future<LocationPermission> checkPermission() async {
4245
try {
4346
// ignore: omit_local_variable_types
44-
final int permission =
45-
await _methodChannel.invokeMethod('checkPermission');
47+
final int permission = await _methodChannel.invokeMethod(
48+
'checkPermission',
49+
);
4650

4751
return permission.toLocationPermission();
4852
} on PlatformException catch (e) {
@@ -56,8 +60,9 @@ class GeolocatorAndroid extends GeolocatorPlatform {
5660
Future<LocationPermission> requestPermission() async {
5761
try {
5862
// ignore: omit_local_variable_types
59-
final int permission =
60-
await _methodChannel.invokeMethod('requestPermission');
63+
final int permission = await _methodChannel.invokeMethod(
64+
'requestPermission',
65+
);
6166

6267
return permission.toLocationPermission();
6368
} on PlatformException catch (e) {
@@ -81,8 +86,10 @@ class GeolocatorAndroid extends GeolocatorPlatform {
8186
'forceLocationManager': forceLocationManager,
8287
};
8388

84-
final positionMap =
85-
await _methodChannel.invokeMethod('getLastKnownPosition', parameters);
89+
final positionMap = await _methodChannel.invokeMethod(
90+
'getLastKnownPosition',
91+
parameters,
92+
);
8693

8794
return positionMap != null ? AndroidPosition.fromMap(positionMap) : null;
8895
} on PlatformException catch (e) {
@@ -94,8 +101,9 @@ class GeolocatorAndroid extends GeolocatorPlatform {
94101

95102
@override
96103
Future<LocationAccuracyStatus> getLocationAccuracy() async {
97-
final int accuracy =
98-
await _methodChannel.invokeMethod('getLocationAccuracy');
104+
final int accuracy = await _methodChannel.invokeMethod(
105+
'getLocationAccuracy',
106+
);
99107
return LocationAccuracyStatus.values[accuracy];
100108
}
101109

@@ -111,13 +119,10 @@ class GeolocatorAndroid extends GeolocatorPlatform {
111119

112120
final Duration? timeLimit = locationSettings?.timeLimit;
113121

114-
positionFuture = _methodChannel.invokeMethod(
115-
'getCurrentPosition',
116-
{
117-
...?locationSettings?.toJson(),
118-
'requestId': requestId,
119-
},
120-
);
122+
positionFuture = _methodChannel.invokeMethod('getCurrentPosition', {
123+
...?locationSettings?.toJson(),
124+
'requestId': requestId,
125+
});
121126

122127
if (timeLimit != null) {
123128
positionFuture = positionFuture.timeout(timeLimit);
@@ -126,13 +131,8 @@ class GeolocatorAndroid extends GeolocatorPlatform {
126131
final positionMap = await positionFuture;
127132
return AndroidPosition.fromMap(positionMap);
128133
} on TimeoutException {
129-
final parameters = <String, dynamic>{
130-
'requestId': requestId,
131-
};
132-
_methodChannel.invokeMethod(
133-
'cancelGetCurrentPosition',
134-
parameters,
135-
);
134+
final parameters = <String, dynamic>{'requestId': requestId};
135+
_methodChannel.invokeMethod('cancelGetCurrentPosition', parameters);
136136
rethrow;
137137
} on PlatformException catch (e) {
138138
final error = _handlePlatformException(e);
@@ -152,20 +152,18 @@ class GeolocatorAndroid extends GeolocatorPlatform {
152152
_serviceStatusStream = serviceStatusStream
153153
.map((dynamic element) => ServiceStatus.values[element as int])
154154
.handleError((error) {
155-
_serviceStatusStream = null;
156-
if (error is PlatformException) {
157-
error = _handlePlatformException(error);
158-
}
159-
throw error;
160-
});
155+
_serviceStatusStream = null;
156+
if (error is PlatformException) {
157+
error = _handlePlatformException(error);
158+
}
159+
throw error;
160+
});
161161

162162
return _serviceStatusStream!;
163163
}
164164

165165
@override
166-
Stream<Position> getPositionStream({
167-
LocationSettings? locationSettings,
168-
}) {
166+
Stream<Position> getPositionStream({LocationSettings? locationSettings}) {
169167
if (_positionStream != null) {
170168
return _positionStream!;
171169
}
@@ -181,34 +179,38 @@ class GeolocatorAndroid extends GeolocatorPlatform {
181179
timeLimit,
182180
onTimeout: (s) {
183181
_positionStream = null;
184-
s.addError(TimeoutException(
185-
'Time limit reached while waiting for position update.',
186-
timeLimit,
187-
));
182+
s.addError(
183+
TimeoutException(
184+
'Time limit reached while waiting for position update.',
185+
timeLimit,
186+
),
187+
);
188188
s.close();
189189
},
190190
);
191191
}
192192

193193
_positionStream = positionStream
194-
.map<Position>((dynamic element) =>
195-
AndroidPosition.fromMap(element.cast<String, dynamic>()))
196-
.handleError(
197-
(error) {
198-
if (error is PlatformException) {
199-
error = _handlePlatformException(error);
200-
}
201-
throw error;
202-
},
203-
);
194+
.map<Position>(
195+
(dynamic element) =>
196+
AndroidPosition.fromMap(element.cast<String, dynamic>()),
197+
)
198+
.handleError((error) {
199+
if (error is PlatformException) {
200+
error = _handlePlatformException(error);
201+
}
202+
throw error;
203+
});
204204
return _positionStream!;
205205
}
206206

207207
Stream<dynamic> _wrapStream(Stream<dynamic> incoming) {
208-
return incoming.asBroadcastStream(onCancel: (subscription) {
209-
subscription.cancel();
210-
_positionStream = null;
211-
});
208+
return incoming.asBroadcastStream(
209+
onCancel: (subscription) {
210+
subscription.cancel();
211+
_positionStream = null;
212+
},
213+
);
212214
}
213215

214216
@override
@@ -218,9 +220,7 @@ class GeolocatorAndroid extends GeolocatorPlatform {
218220
try {
219221
final int status = await _methodChannel.invokeMethod(
220222
'requestTemporaryFullAccuracy',
221-
<String, dynamic>{
222-
'purposeKey': purposeKey,
223-
},
223+
<String, dynamic>{'purposeKey': purposeKey},
224224
);
225225
return LocationAccuracyStatus.values[status];
226226
} on PlatformException catch (e) {

geolocator_android/lib/src/types/foreground_settings.dart

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,11 @@ class AndroidResource {
1111
final String defType;
1212

1313
/// Uniquely identifies an Android resource.
14-
const AndroidResource({
15-
required this.name,
16-
this.defType = 'drawable',
17-
});
14+
const AndroidResource({required this.name, this.defType = 'drawable'});
1815

1916
/// Returns a JSON representation of this class.
2017
Map<String, dynamic> toJson() {
21-
return {
22-
'name': name,
23-
'defType': defType,
24-
};
18+
return {'name': name, 'defType': defType};
2519
}
2620
}
2721

@@ -53,8 +47,10 @@ class ForegroundNotificationConfig {
5347
required this.notificationTitle,
5448
required this.notificationText,
5549
this.notificationChannelName = 'Background Location',
56-
this.notificationIcon =
57-
const AndroidResource(name: 'ic_launcher', defType: 'mipmap'),
50+
this.notificationIcon = const AndroidResource(
51+
name: 'ic_launcher',
52+
defType: 'mipmap',
53+
),
5854
this.enableWifiLock = false,
5955
this.enableWakeLock = false,
6056
this.setOngoing = false,

0 commit comments

Comments
 (0)