oke
This commit is contained in:
parent
2d2c8c0cab
commit
2ff3bd3306
|
|
@ -99,6 +99,7 @@ class EvaporasiBloc extends Bloc<EvaporasiEvent, EvaporasiState> {
|
|||
weatherStatus: status,
|
||||
willRain: rain,
|
||||
listData: listData,
|
||||
currentData: history.isNotEmpty ? history.last : null,
|
||||
isLoading: false,
|
||||
));
|
||||
|
||||
|
|
@ -116,17 +117,9 @@ class EvaporasiBloc extends Bloc<EvaporasiEvent, EvaporasiState> {
|
|||
final previous =
|
||||
state.history.isNotEmpty ? state.history.last.timestamp : null;
|
||||
|
||||
final updatedHistory = List<Evaporasi>.from(state.history)..add(event.data);
|
||||
|
||||
final isDuplicate =
|
||||
previous != null && event.data.timestamp.toUtc() == previous.toUtc();
|
||||
|
||||
// Update bucket berdasarkan timestamp event (bukan jam lokal sekarang).
|
||||
final updated =
|
||||
isDuplicate ? state.dailyValues : List<double>.from(state.dailyValues);
|
||||
final updatedTemp = isDuplicate
|
||||
? state.dailyTemperatures
|
||||
: List<double>.from(state.dailyTemperatures);
|
||||
final updated = List<double>.from(state.dailyValues);
|
||||
final updatedTemp = List<double>.from(state.dailyTemperatures);
|
||||
|
||||
final eventTime = event.data.timestamp;
|
||||
final now = DateTime.now();
|
||||
|
|
@ -147,8 +140,6 @@ class EvaporasiBloc extends Bloc<EvaporasiEvent, EvaporasiState> {
|
|||
_emitEvaporasiAlert(status, rain, event.data.evaporasi);
|
||||
|
||||
emit(state.copyWith(
|
||||
history: updatedHistory,
|
||||
listData: updatedHistory,
|
||||
currentValue: event.data.evaporasi,
|
||||
temperature: event.data.suhu,
|
||||
waterLevel: event.data.tinggiAir,
|
||||
|
|
@ -156,6 +147,7 @@ class EvaporasiBloc extends Bloc<EvaporasiEvent, EvaporasiState> {
|
|||
dailyTemperatures: updatedTemp,
|
||||
weatherStatus: status,
|
||||
willRain: rain,
|
||||
currentData: event.data,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ class EvaporasiState extends Equatable {
|
|||
final String weatherStatus;
|
||||
final bool willRain;
|
||||
|
||||
final Evaporasi? currentData; // data realtime terbaru
|
||||
|
||||
final bool isLoading;
|
||||
|
||||
const EvaporasiState({
|
||||
|
|
@ -51,6 +53,7 @@ class EvaporasiState extends Equatable {
|
|||
this.history = const [],
|
||||
this.weatherStatus = 'Baik',
|
||||
this.willRain = false,
|
||||
this.currentData,
|
||||
this.isLoading = true,
|
||||
});
|
||||
|
||||
|
|
@ -72,6 +75,7 @@ class EvaporasiState extends Equatable {
|
|||
List<Evaporasi>? history,
|
||||
String? weatherStatus,
|
||||
bool? willRain,
|
||||
Evaporasi? currentData,
|
||||
bool? isLoading,
|
||||
}) {
|
||||
return EvaporasiState(
|
||||
|
|
@ -92,6 +96,7 @@ class EvaporasiState extends Equatable {
|
|||
history: history ?? this.history,
|
||||
weatherStatus: weatherStatus ?? this.weatherStatus,
|
||||
willRain: willRain ?? this.willRain,
|
||||
currentData: currentData ?? this.currentData,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
);
|
||||
}
|
||||
|
|
@ -115,7 +120,7 @@ class EvaporasiState extends Equatable {
|
|||
history,
|
||||
weatherStatus,
|
||||
willRain,
|
||||
currentData,
|
||||
isLoading,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -290,15 +290,21 @@ class _EvaporasiScreenState extends State<EvaporasiScreen> {
|
|||
/// 🧾 LIST DATA EVAPORASI
|
||||
/// =========================
|
||||
Widget _evaporasiList(EvaporasiState state) {
|
||||
final data = state.viewMode == EvaporasiViewMode.customDate &&
|
||||
final allData = [...state.history];
|
||||
if (state.currentData != null) {
|
||||
allData.add(state.currentData!);
|
||||
}
|
||||
|
||||
final data = (state.viewMode == EvaporasiViewMode.customDate &&
|
||||
state.selectedDate != null
|
||||
? state.history
|
||||
? allData
|
||||
.where((e) =>
|
||||
e.timestamp.year == state.selectedDate!.year &&
|
||||
e.timestamp.month == state.selectedDate!.month &&
|
||||
e.timestamp.day == state.selectedDate!.day)
|
||||
.toList()
|
||||
: state.history;
|
||||
: List.of(allData))
|
||||
..sort((a, b) => b.timestamp.compareTo(a.timestamp));
|
||||
|
||||
if (data.isEmpty) {
|
||||
return Container(
|
||||
|
|
@ -423,7 +429,6 @@ class _EvaporasiScreenState extends State<EvaporasiScreen> {
|
|||
}
|
||||
|
||||
String _formatDateInfo(DateTime date) {
|
||||
|
||||
final now = DateTime.now();
|
||||
|
||||
final today = DateTime(now.year, now.month, now.day);
|
||||
|
|
@ -439,4 +444,3 @@ class _EvaporasiScreenState extends State<EvaporasiScreen> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ class Evaporasi {
|
|||
|
||||
// Default timestamp: fallback now (kalau field waktu tidak ada).
|
||||
// Catatan: untuk Firebase seharusnya timestamp dikirim konsisten (ms atau ISO string).
|
||||
DateTime timestamp = DateTime.now();
|
||||
DateTime timestamp = DateTime.fromMillisecondsSinceEpoch(0);
|
||||
|
||||
// dukung beberapa kemungkinan penamaan timestamp
|
||||
final rawTimestamp = json['timestamp'] ?? json['time'] ?? json['datetime'];
|
||||
|
|
@ -120,7 +120,7 @@ class Evaporasi {
|
|||
} else {
|
||||
final parsed = DateTime.tryParse(s);
|
||||
if (parsed != null) {
|
||||
timestamp = parsed;
|
||||
timestamp = parsed.toLocal();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -129,7 +129,7 @@ class Evaporasi {
|
|||
final datetimeStr = json['datetime'] as String?;
|
||||
if (datetimeStr != null) {
|
||||
final parsed = DateTime.tryParse(datetimeStr);
|
||||
if (parsed != null) timestamp = parsed;
|
||||
if (parsed != null) timestamp = parsed.toLocal();
|
||||
}
|
||||
|
||||
final waktuStr = json['waktu'] as String?;
|
||||
|
|
|
|||
Loading…
Reference in New Issue