Skip to content

Make LocationData.accuracy and LocationData.time non-nullable - #1102

Open
matasb-google wants to merge 2 commits into
Lyokone:masterfrom
matasb-google:non-nullable-coordinates
Open

Make LocationData.accuracy and LocationData.time non-nullable#1102
matasb-google wants to merge 2 commits into
Lyokone:masterfrom
matasb-google:non-nullable-coordinates

Conversation

@matasb-google

Copy link
Copy Markdown

This PR makes LocationData.accuracy and LocationData.time non-nullable (double instead of double?).

Every platform implementation now consistently provides both values:

  • Android: Always provides both (via Location.getAccuracy() and Location.getTime()).
  • iOS/macOS: Always provides both (via CLLocation.horizontalAccuracy and CLLocation.timestamp).
  • Web: Always provides both (via GeolocationCoordinates.accuracy and GeolocationPosition.timestamp).
  • Windows: Always provides both (via Geocoordinate.Accuracy and Geocoordinate.Timestamp).
  • Linux: Updated in this PR to populate time (derived from GeoClue2 Timestamp property). Previously, time was omitted on Linux (resulting in null in Dart).

As a result, accuracy and time are now guaranteed to be present in LocationData.

💥 Breaking Change

This is a breaking change for:

  • Users of LocationData.fromMap or LocationData.fromJson who omit accuracy or time in the map/json.
  • Test doubles/mocks that construct LocationData without these fields.

All package tests have been updated to include these fields in mock data.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the LocationData model in location_platform_interface to guarantee accuracy and time are always present (non-nullable), aligning behavior across platform implementations and updating Linux to populate time from GeoClue2.

Changes:

  • Make LocationData.accuracy and LocationData.time non-nullable and update their parsing/docs in LocationData.fromMap / fromJson.
  • Update Linux implementation to map GeoClue2 Timestamp into time (ms since epoch).
  • Update package tests to include accuracy and time in mocked LocationData inputs.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/location/test/location_test.dart Updates mock LocationData.fromMap inputs to include required accuracy and time.
packages/location/linux/location_plugin.cc Populates time from GeoClue2 Timestamp (seconds + microseconds → ms).
packages/location_platform_interface/test/types_test.dart Updates LocationData serialization/parsing tests to include accuracy and time.
packages/location_platform_interface/test/method_channel_location_test.dart Updates method-channel test stubs/stream events to include required accuracy and time.
packages/location_platform_interface/lib/src/types.dart Makes accuracy/time non-nullable in LocationData and updates JSON/map parsing and docs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/location_platform_interface/lib/src/types.dart Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants