// sensor_models.dart class SensorReading { final int? id; final double? temperature; final int? ppm; final double waterLevel; final DateTime createdAt; SensorReading({ required this.id, required this.temperature, required this.ppm, required this.waterLevel, required this.createdAt, }); factory SensorReading.fromJson(Map json) { try{ return SensorReading( id: json['id'], temperature: (json['temperature'] as num?)?.toDouble(), ppm: json['ppm'], waterLevel: json['water_level'].toDouble(), createdAt: DateTime.parse(json['created_at']), ); } catch (e) { throw FormatException('Failed to parse SensorReading: $e'); } } get length => null; } class SensorHistory { final String message; final Map date; // Perhatikan ini berbeda dari sebelumnya SensorHistory({ required this.message, required this.date, }); factory SensorHistory.fromJson(Map json) { return SensorHistory( message: json['message'], date: json['date'], // Sesuaikan dengan response API ); } } class DailySensorData { final String message; final List data; DailySensorData({ required this.message, required this.data, }); factory DailySensorData.fromJson(Map json) { return DailySensorData( message: json['message'] ?? 'No message', data: json['data'] != null ? (json['data'] as List).map((e) => SensorReading.fromJson(e)).toList() : [], ); } }