33 lines
788 B
Dart
33 lines
788 B
Dart
import 'package:cloud_firestore/cloud_firestore.dart';
|
|
|
|
class SensorData {
|
|
final String name;
|
|
final double value;
|
|
final DateTime timestamp;
|
|
|
|
SensorData({
|
|
required this.name,
|
|
required this.value,
|
|
required this.timestamp,
|
|
});
|
|
|
|
// Konversi dari Firestore ke SensorData
|
|
factory SensorData.fromFirestore(DocumentSnapshot doc) {
|
|
Map<String, dynamic> data = doc.data() as Map<String, dynamic>;
|
|
return SensorData(
|
|
name: data['name'] ?? '',
|
|
value: (data['value'] ?? 0.0).toDouble(),
|
|
timestamp: (data['timestamp'] as Timestamp).toDate(),
|
|
);
|
|
}
|
|
|
|
// Konversi ke format Map untuk Firestore
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'name': name,
|
|
'value': value,
|
|
'timestamp': Timestamp.fromDate(timestamp),
|
|
};
|
|
}
|
|
}
|