Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic generation of Timestamp for Positioned.fromMap if it is not… #1411

Merged
merged 4 commits into from
Jan 31, 2024
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
11 changes: 8 additions & 3 deletions geolocator_platform_interface/lib/src/models/position.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,14 @@ class Position {
'The supplied map doesn\'t contain the mandatory key `longitude`.');
}

final timestamp = DateTime.fromMillisecondsSinceEpoch(
positionMap['timestamp'].toInt(),
isUtc: true);
// Assume that the timestamp is null if the map does not contain one
dynamic timestampInMap = positionMap['timestamp'];
final timestamp = timestampInMap == null
? DateTime.now()
: DateTime.fromMillisecondsSinceEpoch(
timestampInMap.toInt(),
isUtc: true,
);

return Position(
latitude: positionMap['latitude'],
Expand Down
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.0
version: 4.2.1

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ void main() {

expect(bearing, -90.0);
});

test('generate Position object from map without timestamp', () async {
final Position position = Position.fromMap({
'latitude': 0.0,
'longitude': 0.0,
});

expect(position, isNotNull);
});
});
}

Expand Down
Loading