diff --git a/lib/models/device.dart b/lib/models/device.dart index 735822c..2bd48e8 100644 --- a/lib/models/device.dart +++ b/lib/models/device.dart @@ -70,8 +70,8 @@ class Device { colorcode: json['colorcode'] as int?, status: json['status'] as int?, lastKnownMaster: json['last_known_master'] as int?, - lat: json['lat'] as double?, - lng: json['lng'] as double?, + lat: _toDouble(json['lat']), + lng: _toDouble(json['lng']), website: json['website'] as String?, pep: json['pep'] as int?, agl: json['agl'] as int?, @@ -85,6 +85,14 @@ class Device { ); } + static double? _toDouble(dynamic value) { + if (value == null) return null; + if (value is double) return value; + if (value is int) return value.toDouble(); + if (value is String) return double.tryParse(value); + return null; + } + Map toJson() { return { 'id': id,