Files
GeoShare/bin/models/geoposition.dart
T

35 lines
834 B
Dart

class Geoposition {
final int id;
final double xValue;
final double yValue;
final DateTime lastUpdate;
final DateTime expiresAt;
Geoposition({
required this.id,
required this.xValue,
required this.yValue,
required this.lastUpdate,
required this.expiresAt,
});
Map<String, dynamic> toJson() {
return {
'id': id,
'x': xValue,
'y': yValue,
'lastUpdate': lastUpdate.toIso8601String(),
'remainingSeconds': expiresAt.difference(DateTime.now()).inSeconds,
};
}
factory Geoposition.fromMap(Map<String, dynamic> map) {
return Geoposition(
id: map['id'],
xValue: map['x_value'].toDouble(),
yValue: map['y_value'].toDouble(),
lastUpdate: map['last_update'] as DateTime,
expiresAt: map['expires_at'] as DateTime,
);
}
}