Skip to content

Commit

Permalink
Merge branch 'main' into web-settings
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanbeusekom authored Aug 5, 2024
2 parents 0549032 + b741647 commit 7104d81
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 35 deletions.
4 changes: 2 additions & 2 deletions geolocator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ The TL;DR version is:
android.useAndroidX=true
android.enableJetifier=true
```
2. Make sure you set the `compileSdkVersion` in your "android/app/build.gradle" file to 33:
2. Make sure you set the `compileSdkVersion` in your "android/app/build.gradle" file to 34:

```
android {
compileSdkVersion 33
compileSdkVersion 34
...
}
Expand Down
4 changes: 4 additions & 0 deletions geolocator_android/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.6.1

* Fixes a bug where the plugin throws an exception while requesting locations updates with coarse location permission only.

## 4.6.0

* Adds support to read NMEA messages from other satellites constellations.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.baseflow.geolocator.location;

import android.Manifest;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.GnssStatus;
import android.location.Location;
import android.location.LocationManager;
Expand Down Expand Up @@ -73,9 +75,12 @@ public void start() {

if (locationOptions != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && locationManager != null) {
locationManager.addNmeaListener(nmeaMessageListener, null);
locationManager.registerGnssStatusCallback(gnssCallback, null);
listenerAdded = true;
if (context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
locationManager.addNmeaListener(nmeaMessageListener, null);
locationManager.registerGnssStatusCallback(gnssCallback, null);
listenerAdded = true;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion geolocator_android/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: geolocator_android
description: Geolocation plugin for Flutter. This plugin provides the Android implementation for the geolocator.
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_android
issue_tracker: https://github.com/baseflow/flutter-geolocator/issues?q=is%3Aissue+is%3Aopen
version: 4.6.0
version: 4.6.1

environment:
sdk: ">=2.15.0 <4.0.0"
Expand Down
2 changes: 1 addition & 1 deletion geolocator_apple/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
ExamplePage(
Icons.location_on,
(context) => Scaffold(
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,
body: ListView.builder(
itemCount: _positionItems.length,
itemBuilder: (context, index) {
Expand Down
2 changes: 1 addition & 1 deletion geolocator_linux/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
);

return Scaffold(
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,
body: ListView.builder(
itemCount: _positionItems.length,
itemBuilder: (context, index) {
Expand Down
4 changes: 4 additions & 0 deletions geolocator_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 4.2.4

- Correctly handle integer-like numbers when decoding `Position` from JSON.

## 4.2.3

- Fixes several grammar mistakes in the API documentation.
Expand Down
22 changes: 15 additions & 7 deletions geolocator_platform_interface/lib/src/models/position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ class Position {
latitude: positionMap['latitude'],
longitude: positionMap['longitude'],
timestamp: timestamp,
altitude: positionMap['altitude'] ?? 0.0,
altitudeAccuracy: positionMap['altitude_accuracy'] ?? 0.0,
accuracy: positionMap['accuracy'] ?? 0.0,
heading: positionMap['heading'] ?? 0.0,
headingAccuracy: positionMap['heading_accuracy'] ?? 0.0,
altitude: _toDouble(positionMap['altitude']),
altitudeAccuracy: _toDouble(positionMap['altitude_accuracy']),
accuracy: _toDouble(positionMap['accuracy']),
heading: _toDouble(positionMap['heading']),
headingAccuracy: _toDouble(positionMap['heading_accuracy']),
floor: positionMap['floor'],
speed: positionMap['speed'] ?? 0.0,
speedAccuracy: positionMap['speed_accuracy'] ?? 0.0,
speed: _toDouble(positionMap['speed']),
speedAccuracy: _toDouble(positionMap['speed_accuracy']),
isMocked: positionMap['is_mocked'] ?? false,
);
}
Expand All @@ -182,4 +182,12 @@ class Position {
'speed_accuracy': speedAccuracy,
'is_mocked': isMocked,
};

static double _toDouble(dynamic value) {
if (value == null) {
return 0.0;
}

return value.toDouble();
}
}
2 changes: 1 addition & 1 deletion geolocator_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the geolocator plugin.
repository: https://github.com/baseflow/flutter-geolocator/tree/main/geolocator_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 4.2.3
version: 4.2.4

dependencies:
flutter:
Expand Down
18 changes: 18 additions & 0 deletions geolocator_platform_interface/test/src/models/position_test.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:flutter_test/flutter_test.dart';
import 'package:geolocator_platform_interface/geolocator_platform_interface.dart';

Expand Down Expand Up @@ -512,6 +514,22 @@ void main() {
// Act & Assert
expect(() => Position.fromMap(map), throwsArgumentError);
});

test('fromMap should handle a map returned by jsonDecode', () {
// Arrange
const json = '''{
"is_mocked": true,
"longitude": -122.406417,
"timestamp": 1718643179305.9131,
"latitude": 37.785834000000001,
"heading_accuracy": -1,
"accuracy": 5,
"heading": -1.5
}''';

// Act & Assert
expect(() => Position.fromMap(jsonDecode(json)), returnsNormally);
});
});

group('toString tests:', () {
Expand Down
24 changes: 16 additions & 8 deletions geolocator_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
## 4.1.0
- Adds WebSettings class, allowing a location maximumAge to be specified
- Supports maximumAge parameter in `getCurrentPosition` and `watchPosition` methods

- Adds WebSettings class, allowing a location maximumAge to be specified.
- Supports maximumAge parameter in `getCurrentPosition` and `watchPosition` methods.

## 4.0.1

- Upgrades the package:web dependency to version 1.0.0.
- Upgrades Dart SDK from 3.3.0 to 3.4.0 for geolocator_web.

## 4.0.0

**BREAKING CHANGE:**
- Migrates from dart:html to package:web and dart:js_interop
- Migrates to Dart SDK 3.3.0 and Flutter 3.16.0.

- Migrates from dart:html to package:web and dart:js_interop
- Migrates to Dart SDK 3.3.0 and Flutter 3.16.0.

## 3.0.0

**BREAKING CHANGE:**

- `getServiceStatusStream` on web returns a PlatformException i.s.o. UnimplementedError. As the concept of location service doesn't exist on the web platform.

## 2.2.1
Expand All @@ -23,7 +31,7 @@

## 2.1.7

- Mark `geolocator_web` as implementation of `geolocator`
- Mark `geolocator_web` as implementation of `geolocator`

## 2.1.6

Expand All @@ -39,7 +47,7 @@

## 2.1.3

- Updated to the latest version of the `geolocator_platform_interface': `4.0.0`.
- Updated to the latest version of the `geolocator_platform_interface':`4.0.0`.

## 2.1.2

Expand All @@ -51,7 +59,7 @@

## 2.1.0

- Made changes to the implementation of the `getCurrentPosition` and `getPositionStream` method to match new platform interface.
- Made changes to the implementation of the `getCurrentPosition` and `getPositionStream` method to match new platform interface.
- Fixes issues where geolocator doesn't work on Safari due to missing implementation of `query` method in the browser.

## 2.0.6
Expand All @@ -76,7 +84,7 @@

## 2.0.1

- Solve bug causing error when requesting permissions (see issue [#673](https://github.com/Baseflow/flutter-geolocator/issues/673)).
- Solve bug causing error when requesting permissions (see issue [#673](https://github.com/Baseflow/flutter-geolocator/issues/673)).

## 2.0.0

Expand Down
15 changes: 8 additions & 7 deletions geolocator_web/lib/src/utils.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
import 'dart:async';
import 'package:web/web.dart' as web;

import 'package:flutter/services.dart';
import 'package:geolocator_platform_interface/geolocator_platform_interface.dart';
import 'package:web/web.dart' as web;

/// Converts the Geoposition object into a [Position] object.
Position toPosition(web.GeolocationPosition webPosition) {
final coords = webPosition.coords;

return Position(
latitude: coords.latitude as double,
longitude: coords.longitude as double,
latitude: coords.latitude,
longitude: coords.longitude,
timestamp: DateTime.fromMillisecondsSinceEpoch(webPosition.timestamp),
altitude: coords.altitude as double? ?? 0.0,
altitudeAccuracy: coords.altitudeAccuracy as double? ?? 0.0,
altitude: coords.altitude ?? 0.0,
altitudeAccuracy: coords.altitudeAccuracy ?? 0.0,
accuracy: coords.accuracy as double? ?? 0.0,
heading: coords.heading as double? ?? 0.0,
heading: coords.heading ?? 0.0,
headingAccuracy: 0.0,
floor: null,
speed: coords.speed as double? ?? 0.0,
speed: coords.speed ?? 0.0,
speedAccuracy: 0.0,
isMocked: false,
);
Expand Down
4 changes: 1 addition & 3 deletions geolocator_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ dependencies:
flutter_web_plugins:
sdk: flutter
geolocator_platform_interface: ^4.2.3
web: ^0.5.1

dev_dependencies:
build_runner: ^2.4.8
Expand All @@ -27,7 +26,6 @@ dev_dependencies:
flutter_lints: ">=3.0.1 <5.0.0"
mockito: ^5.4.0


environment:
sdk: '>=3.3.0 <4.0.0'
sdk: ">=3.4.0 <4.0.0"
flutter: ">=3.16.0"
2 changes: 1 addition & 1 deletion geolocator_windows/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class _GeolocatorWidgetState extends State<GeolocatorWidget> {
ExamplePage(
Icons.location_on,
(context) => Scaffold(
backgroundColor: Theme.of(context).colorScheme.background,
backgroundColor: Theme.of(context).colorScheme.surface,
body: ListView.builder(
itemCount: _positionItems.length,
itemBuilder: (context, index) {
Expand Down

0 comments on commit 7104d81

Please sign in to comment.