Skip to content
Merged
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
16 changes: 14 additions & 2 deletions .github/workflows/location-prepare.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,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 +86,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
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
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
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