Skip to content
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
17 changes: 15 additions & 2 deletions .github/workflows/location-prepare.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: location prepare

on:
workflow_dispatch:
pull_request:
branches: [master, develop]

Expand Down Expand Up @@ -53,7 +54,13 @@ jobs:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.27.x
flutter-version: ${{ matrix.flutter-version }}

- name: Set up Melos
run: dart pub global activate melos ^3.0.0

- name: melos bootstrap
run: melos bootstrap

- name: Set up Java
uses: actions/setup-java@v4
Expand All @@ -80,7 +87,13 @@ jobs:
- name: Set up Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.27.x
flutter-version: ${{ matrix.flutter-version }}

- name: Set up Melos
run: dart pub global activate melos ^3.0.0

- name: melos bootstrap
run: melos bootstrap

- name: Install tools
run: brew install clang-format
Expand Down
4 changes: 4 additions & 0 deletions packages/location/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.0.1

- Bump dependency on `location_platform_interface` to `^6.0.1` (#933)

## 8.0.0

- Bump minimum Dart version to 3.4, minimum Flutter version to 3.22
Expand Down
28 changes: 14 additions & 14 deletions packages/location/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,29 +98,29 @@ import 'package:location/location.dart';
In order to request location, you should always check Location Service status and Permission status manually

```dart
Location location = new Location();
Location location = Location();

bool _serviceEnabled;
PermissionStatus _permissionGranted;
LocationData _locationData;
bool serviceEnabled;
PermissionStatus permissionGranted;
LocationData locationData;

_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
serviceEnabled = await location.serviceEnabled();
if (!serviceEnabled) {
serviceEnabled = await location.requestService();
if (!serviceEnabled) {
return;
}
}

_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
_permissionGranted = await location.requestPermission();
if (_permissionGranted != PermissionStatus.granted) {
permissionGranted = await location.hasPermission();
if (permissionGranted == PermissionStatus.denied) {
permissionGranted = await location.requestPermission();
if (permissionGranted != PermissionStatus.granted) {
return;
}
}

_locationData = await location.getLocation();
locationData = await location.getLocation();
```

You can also get continuous callbacks when your position is changing:
Expand Down Expand Up @@ -156,7 +156,7 @@ On iOS, while the app is in the background and gets the location, the blue syste
| Future\<PermissionStatus> | **hasPermission()** <br>Return a PermissionStatus to know the state of the location permission. |
| Future\<bool> | **serviceEnabled()** <br>Return a boolean to know if the Location Service is enabled or if the user manually deactivated it. |
| Future\<bool> | **requestService()** <br>Show an alert dialog to request the user to activate the Location Service. On iOS, will only display an alert due to Apple Guidelines, the user having to manually go to Settings. Return a boolean to know if the Location Service has been activated (always `false` on iOS). |
| Future\<bool> | **changeSettings(LocationAccuracy accuracy = LocationAccuracy.HIGH, int interval = 1000, double distanceFilter = 0)** <br>Will change the settings of futur requests. `accuracy`will describe the accuracy of the request (see the LocationAccuracy object). `interval` will set the desired interval for active location updates, in milliseconds (only affects Android). `distanceFilter` set the minimum displacement between location updates in meters. |
| Future\<bool> | **changeSettings(LocationAccuracy accuracy = LocationAccuracy.HIGH, int interval = 1000, double distanceFilter = 0)** <br>Will change the settings of future requests. `accuracy`will describe the accuracy of the request (see the LocationAccuracy object). `interval` will set the desired interval for active location updates, in milliseconds (only affects Android). `distanceFilter` set the minimum displacement between location updates in meters. |
| Future\<LocationData> | **getLocation()** <br>Allow to get a one time position of the user. It will try to request permission if not granted yet and will throw a `PERMISSION_DENIED` error code if permission still not granted. |
| Stream\<LocationData> | **onLocationChanged** <br>Get the stream of the user's location. It will try to request permission if not granted yet and will throw a `PERMISSION_DENIED` error code if permission still not granted. |
| Future\<bool> | **enableBackgroundMode({bool enable})** <br>Allow or disallow to retrieve location events in the background. Return a boolean to know if background mode was successfully enabled. |
Expand Down
31 changes: 31 additions & 0 deletions packages/location/example/lib/change_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class _ChangeSettingsState extends State<ChangeSettings> {
);

LocationAccuracy _locationAccuracy = LocationAccuracy.high;
bool _pausesLocationUpdatesAutomatically = true;

@override
void dispose() {
Expand Down Expand Up @@ -83,6 +84,34 @@ class _ChangeSettingsState extends State<ChangeSettings> {
child: Text('Powersave'),
),
],
decoration: const InputDecoration(
labelText: 'LocationAccuracy',
),
),
const SizedBox(height: 4),
DropdownButtonFormField<bool>(
value: _pausesLocationUpdatesAutomatically,
onChanged: (value) {
if (value == null) {
return;
}
setState(() {
_pausesLocationUpdatesAutomatically = value;
});
},
items: const <DropdownMenuItem<bool>>[
DropdownMenuItem(
value: true,
child: Text('True'),
),
DropdownMenuItem(
value: false,
child: Text('False'),
),
],
decoration: const InputDecoration(
labelText: 'PausesLocationUpdatesAutomatically',
),
),
const SizedBox(height: 4),
ElevatedButton(
Expand All @@ -91,6 +120,8 @@ class _ChangeSettingsState extends State<ChangeSettings> {
accuracy: _locationAccuracy,
interval: int.parse(_intervalController.text),
distanceFilter: double.parse(_distanceFilterController.text),
pausesLocationUpdatesAutomatically:
_pausesLocationUpdatesAutomatically,
);
},
child: const Text('Change'),
Expand Down
7 changes: 7 additions & 0 deletions packages/location/ios/Classes/LocationPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ - (void)initLocation {
self.clLocationManager = [[CLLocationManager alloc] init];
self.clLocationManager.delegate = self;
self.clLocationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.clLocationManager.pausesLocationUpdatesAutomatically = true;
}
}

- (void)handleMethodCall:(FlutterMethodCall *)call
result:(FlutterResult)result {
[self initLocation];
if ([call.method isEqualToString:@"changeSettings"]) {
#ifdef DEBUG
NSLog(@"[Location] changeSettings(%@)", call.arguments);
#endif
if ([CLLocationManager locationServicesEnabled]) {
CLLocationAccuracy reducedAccuracy = kCLLocationAccuracyHundredMeters;
if (@available(iOS 14, *)) {
Expand All @@ -88,6 +92,9 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
distanceFilter = kCLDistanceFilterNone;
}
self.clLocationManager.distanceFilter = distanceFilter;
self.clLocationManager.pausesLocationUpdatesAutomatically =
[dictionary[call.arguments[@"pausesLocationUpdatesAutomatically"]]
boolValue];
result(@1);
}
} else if ([call.method isEqualToString:@"isBackgroundModeEnabled"]) {
Expand Down
6 changes: 5 additions & 1 deletion packages/location/lib/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ class Location implements LocationPlatform {
///
/// The [accuracy] argument is controlling the precision of the
/// [LocationData]. The [interval] and [distanceFilter] are controlling how
/// often a new location is sent through [onLocationChanged].
/// often a new location is sent through [onLocationChanged]. The
/// [pausesLocationUpdatesAutomatically] argument indicates whether the
/// underlying location manager object may pause location updates.
///
/// [interval] and [distanceFilter] are not used on web.
@override
Future<bool> changeSettings({
LocationAccuracy? accuracy = LocationAccuracy.high,
int? interval = 1000,
double? distanceFilter = 0,
bool? pausesLocationUpdatesAutomatically = true,
}) {
return LocationPlatform.instance.changeSettings(
accuracy: accuracy,
interval: interval,
distanceFilter: distanceFilter,
pausesLocationUpdatesAutomatically: pausesLocationUpdatesAutomatically,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/location/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: location
description: Cross-platform plugin for easy access to device's location in real-time.
version: 8.0.0
version: 8.0.1
homepage: https://docs.page/Lyokone/flutterlocation
repository: https://github.com/Lyokone/flutterlocation
issue_tracker: https://github.com/Lyokone/flutterlocation/issues
Expand Down
7 changes: 5 additions & 2 deletions packages/location/test/location_test.mocks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ class MockLocation extends _i1.Mock implements _i3.Location {
_i4.Future<bool> changeSettings(
{_i2.LocationAccuracy? accuracy = _i2.LocationAccuracy.high,
int? interval = 1000,
double? distanceFilter = 0.0}) =>
double? distanceFilter = 0.0,
bool? pausesLocationUpdatesAutomatically = true}) =>
(super.noSuchMethod(
Invocation.method(#changeSettings, [], {
#accuracy: accuracy,
#interval: interval,
#distanceFilter: distanceFilter
#distanceFilter: distanceFilter,
#pausesLocationUpdatesAutomatically:
pausesLocationUpdatesAutomatically
}),
returnValue: Future<bool>.value(false)) as _i4.Future<bool>);
@override
Expand Down
4 changes: 4 additions & 0 deletions packages/location_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.0.1

- Configure `pausesLocationUpdatesAutomatically` on iOS (#933)

## 6.0.0

- Bump dependencies (#952)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ class LocationPlatform extends PlatformInterface {
///
/// The [accuracy] argument is controlling the precision of the
/// [LocationData]. The [interval] and [distanceFilter] are controlling how
/// often a new location is sent through [onLocationChanged].
/// often a new location is sent through [onLocationChanged]. The
/// [pausesLocationUpdatesAutomatically] argument indicates whether the
/// underlying location manager object may pause location updates.
Future<bool> changeSettings({
LocationAccuracy? accuracy,
int? interval,
double? distanceFilter,
bool? pausesLocationUpdatesAutomatically,
}) {
throw UnimplementedError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,24 @@ class MethodChannelLocation extends LocationPlatform {
///
/// The [accuracy] argument is controlling the precision of the
/// [LocationData]. The [interval] and [distanceFilter] are controlling how
/// often a new location is sent through [onLocationChanged].
/// often a new location is sent through [onLocationChanged]. The
/// [pausesLocationUpdatesAutomatically] argument indicates whether the
/// underlying location manager object may pause location updates.
@override
Future<bool> changeSettings({
LocationAccuracy? accuracy = LocationAccuracy.high,
int? interval = 1000,
double? distanceFilter = 0,
bool? pausesLocationUpdatesAutomatically = true,
}) async {
final result = await _methodChannel!.invokeMethod(
'changeSettings',
<String, dynamic>{
'accuracy': accuracy!.index,
'interval': interval,
'distanceFilter': distanceFilter,
'pausesLocationUpdatesAutomatically':
pausesLocationUpdatesAutomatically,
},
);

Expand Down
2 changes: 1 addition & 1 deletion packages/location_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: location_platform_interface
description: A common platform interface for the location plugin.
version: 6.0.0
version: 6.0.1
homepage: https://github.com/Lyokone/flutterlocation

environment:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ void main() {
'accuracy': LocationAccuracy.high.index,
'interval': 1000,
'distanceFilter': 0,
'pausesLocationUpdatesAutomatically': true,
},
),
]);
Expand Down
4 changes: 4 additions & 0 deletions packages/location_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 6.0.1

- Configure `pausesLocationUpdatesAutomatically` on iOS. Should fix (#933)

## 6.0.0

- Bump minimum Dart version to 3.6, minimum Flutter version to 3.27 (#952)
Expand Down
1 change: 1 addition & 0 deletions packages/location_web/lib/location_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class LocationWebPlugin extends LocationPlatform {
LocationAccuracy? accuracy,
int? interval,
double? distanceFilter,
bool? pausesLocationUpdatesAutomatically,
}) async {
_accuracy = accuracy;
return true;
Expand Down
2 changes: 1 addition & 1 deletion packages/location_web/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: location_web
description: The web implementation of the location plugin.
version: 6.0.0
version: 6.0.1
homepage: https://github.com/Lyokone/flutterlocation
repository: https://github.com/Lyokone/flutterlocation
issue_tracker: https://github.com/Lyokone/flutterlocation/issues
Expand Down