Skip to content

Commit

Permalink
Automatic generation of Timestamp for Positioned.fromMap if it is not…
Browse files Browse the repository at this point in the history
… existent
  • Loading branch information
guplem committed Jan 22, 2024
1 parent a578c8a commit 898f762
Showing 1 changed file with 8 additions and 3 deletions.
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()

Check warning on line 147 in geolocator_platform_interface/lib/src/models/position.dart

View check run for this annotation

Codecov / codecov/patch

geolocator_platform_interface/lib/src/models/position.dart#L147

Added line #L147 was not covered by tests
: DateTime.fromMillisecondsSinceEpoch(
timestampInMap.toInt(),
isUtc: true,
);

return Position(
latitude: positionMap['latitude'],
Expand Down

0 comments on commit 898f762

Please sign in to comment.