Revert "Fix evaporasi dashboard: firebase history list + sync chart labels"
This reverts commit 42bac0c980.
This commit is contained in:
parent
b5539715f3
commit
0e90908b2d
|
|
@ -34,8 +34,6 @@ class EvaporasiBloc extends Bloc<EvaporasiEvent, EvaporasiState> {
|
|||
WatchEvaporasiStarted event,
|
||||
Emitter<EvaporasiState> emit,
|
||||
) async {
|
||||
// chartLabels & listData untuk list/label di UI
|
||||
|
||||
emit(state.copyWith(isLoading: true));
|
||||
|
||||
final history = await _repository.getSensorHistory(
|
||||
|
|
@ -43,13 +41,7 @@ class EvaporasiBloc extends Bloc<EvaporasiEvent, EvaporasiState> {
|
|||
(json) => Evaporasi.fromJson(json),
|
||||
);
|
||||
|
||||
// listData dipakai untuk tab/list di UI (default: ambil data yang sudah ada di Firebase)
|
||||
final listData = List<Evaporasi>.from(history)
|
||||
..sort((a, b) => a.timestamp.compareTo(b.timestamp));
|
||||
|
||||
|
||||
final dailyGraph = TimeSeriesMapper.toDaily(
|
||||
|
||||
data: history,
|
||||
getTime: (e) => e.timestamp,
|
||||
getValue: (e) => e.evaporasi,
|
||||
|
|
@ -68,12 +60,8 @@ class EvaporasiBloc extends Bloc<EvaporasiEvent, EvaporasiState> {
|
|||
|
||||
emit(state.copyWith(
|
||||
history: history,
|
||||
listData: listData,
|
||||
dailyValues: dailyGraph,
|
||||
dailyTemperatures: dailyTempGraph,
|
||||
chartLabels: _buildChartLabels(
|
||||
period: 'Hari Ini',
|
||||
),
|
||||
weatherStatus: status,
|
||||
willRain: rain,
|
||||
isLoading: false,
|
||||
|
|
@ -167,7 +155,6 @@ class EvaporasiBloc extends Bloc<EvaporasiEvent, EvaporasiState> {
|
|||
emit(state.copyWith(
|
||||
dailyValues: updated,
|
||||
dailyTemperatures: updatedTemp,
|
||||
chartLabels: _buildChartLabels(period: event.period),
|
||||
isLoading: false,
|
||||
));
|
||||
}
|
||||
|
|
@ -204,7 +191,6 @@ class EvaporasiBloc extends Bloc<EvaporasiEvent, EvaporasiState> {
|
|||
emit(state.copyWith(
|
||||
dailyValues: updated,
|
||||
dailyTemperatures: updatedTemp,
|
||||
chartLabels: _buildChartLabels(period: 'Tanggal Khusus'),
|
||||
isLoading: false,
|
||||
));
|
||||
}
|
||||
|
|
@ -239,22 +225,6 @@ class EvaporasiBloc extends Bloc<EvaporasiEvent, EvaporasiState> {
|
|||
return ('Buruk', true);
|
||||
}
|
||||
|
||||
List<String> _buildChartLabels({required String period}) {
|
||||
if (period == 'Minggu Ini') {
|
||||
return const ['Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab', 'Min'];
|
||||
}
|
||||
|
||||
// Untuk Bulan Ini & Tanggal Khusus/ Hari Ini, biarkan chart pakai 0..23 / 0..days
|
||||
final now = DateTime.now();
|
||||
if (period == 'Bulan Ini') {
|
||||
final daysInMonth = DateTime(now.year, now.month + 1, 0).day;
|
||||
return List.generate(daysInMonth, (i) => '${i + 1}');
|
||||
}
|
||||
|
||||
// Hari Ini / Tanggal Khusus => 24 jam
|
||||
return List.generate(24, (i) => '${i.toString().padLeft(2, '0')}:00');
|
||||
}
|
||||
|
||||
void _emitEvaporasiAlert(String status, bool willRain, double value) {
|
||||
final AlertSeverity severity;
|
||||
final String message;
|
||||
|
|
|
|||
|
|
@ -12,15 +12,6 @@ class EvaporasiState extends Equatable {
|
|||
|
||||
final List<double> dailyValues; // untuk grafik evaporasi
|
||||
final List<double> dailyTemperatures; // untuk grafik suhu
|
||||
|
||||
/// Label X-axis sesuai agregasi period
|
||||
/// Contoh: Hari Ini => ["00:00","01:00",...]
|
||||
/// Minggu Ini => ["Sen","Sel",...]
|
||||
/// Bulan Ini => ["1","2",...]
|
||||
final List<String> chartLabels;
|
||||
|
||||
/// Data untuk list (timestamp asli dari firebase)
|
||||
final List<Evaporasi> listData;
|
||||
final List<Evaporasi> history;
|
||||
|
||||
final String weatherStatus; // Baik / Sedang / Buruk
|
||||
|
|
@ -37,8 +28,6 @@ class EvaporasiState extends Equatable {
|
|||
this.viewMode = EvaporasiViewMode.period,
|
||||
this.dailyValues = const [],
|
||||
this.dailyTemperatures = const [],
|
||||
this.chartLabels = const [],
|
||||
this.listData = const [],
|
||||
this.history = const [],
|
||||
this.weatherStatus = "Baik",
|
||||
this.willRain = false,
|
||||
|
|
@ -54,8 +43,6 @@ EvaporasiState copyWith({
|
|||
EvaporasiViewMode? viewMode,
|
||||
List<double>? dailyValues,
|
||||
List<double>? dailyTemperatures,
|
||||
List<String>? chartLabels,
|
||||
List<Evaporasi>? listData,
|
||||
List<Evaporasi>? history,
|
||||
String? weatherStatus,
|
||||
bool? willRain,
|
||||
|
|
@ -71,8 +58,6 @@ EvaporasiState copyWith({
|
|||
dailyValues: dailyValues ?? this.dailyValues,
|
||||
dailyTemperatures: dailyTemperatures ?? this.dailyTemperatures,
|
||||
history: history ?? this.history,
|
||||
chartLabels: chartLabels ?? this.chartLabels,
|
||||
listData: listData ?? this.listData,
|
||||
weatherStatus: weatherStatus ?? this.weatherStatus,
|
||||
willRain: willRain ?? this.willRain,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
|
|
|
|||
|
|
@ -53,8 +53,7 @@ class EvaporasiScreen extends StatelessWidget {
|
|||
style:
|
||||
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// Period selector with date picker
|
||||
// Period selector with date picker
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final state = context.watch<EvaporasiBloc>().state;
|
||||
|
|
@ -84,24 +83,16 @@ class EvaporasiScreen extends StatelessWidget {
|
|||
Builder(
|
||||
builder: (context) {
|
||||
final state = context.watch<EvaporasiBloc>().state;
|
||||
return Column(
|
||||
children: [
|
||||
EvaporasiChartWidget(
|
||||
dailyValues: state.dailyValues,
|
||||
dailyTemperatures: state.dailyTemperatures,
|
||||
period: state.viewMode == EvaporasiViewMode.customDate
|
||||
? "Tanggal Khusus"
|
||||
: state.selectedPeriod,
|
||||
chartLabels: state.chartLabels,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
_evaporasiList(state),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
return EvaporasiChartWidget(
|
||||
dailyValues: state.dailyValues,
|
||||
dailyTemperatures: state.dailyTemperatures,
|
||||
period: state.viewMode == EvaporasiViewMode.customDate
|
||||
? "Tanggal Khusus"
|
||||
: state.selectedPeriod,
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const SizedBox(height: 25),
|
||||
ExportPdfButton(
|
||||
onExport: () => PdfExportService.evaporasi(
|
||||
evaporasi: state.currentValue,
|
||||
|
|
@ -270,82 +261,6 @@ class EvaporasiScreen extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
/// =========================
|
||||
/// 🧾 LIST DATA EVAPORASI
|
||||
/// =========================
|
||||
Widget _evaporasiList(EvaporasiState state) {
|
||||
final data = state.listData;
|
||||
if (data.isEmpty) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: const Text('Belum ada data evaporasi',
|
||||
style: TextStyle(color: Colors.grey)),
|
||||
);
|
||||
}
|
||||
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'List Data Evaporasi',
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ListView.separated(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: data.length,
|
||||
separatorBuilder: (_, __) => const Divider(height: 1),
|
||||
itemBuilder: (context, index) {
|
||||
final e = data[index];
|
||||
final dateLabel = DateFormat('dd MMM yyyy HH:mm:ss', 'id_ID')
|
||||
.format(e.timestamp);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
dateLabel,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.black87,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
'${e.evaporasi.toStringAsFixed(1)} mm',
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: Colors.blue,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// =========================
|
||||
/// 📅 FORMAT DATE INFO (for custom date display)
|
||||
/// =========================
|
||||
|
|
|
|||
|
|
@ -5,18 +5,14 @@ class EvaporasiChartWidget extends StatelessWidget {
|
|||
final List<double> dailyValues;
|
||||
final List<double> dailyTemperatures;
|
||||
final String period;
|
||||
final List<String> chartLabels;
|
||||
|
||||
|
||||
const EvaporasiChartWidget({
|
||||
super.key,
|
||||
required this.dailyValues,
|
||||
required this.dailyTemperatures,
|
||||
required this.period,
|
||||
required this.chartLabels,
|
||||
});
|
||||
|
||||
|
||||
double _getMaxY(List<double> data) {
|
||||
if (data.isEmpty) return 10;
|
||||
final max = data.reduce((a, b) => a > b ? a : b);
|
||||
|
|
@ -97,7 +93,6 @@ class EvaporasiChartWidget extends StatelessWidget {
|
|||
_getBottomTitle(value),
|
||||
style: const TextStyle(
|
||||
color: Colors.grey, fontSize: 10),
|
||||
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
@ -232,14 +227,20 @@ class EvaporasiChartWidget extends StatelessWidget {
|
|||
}
|
||||
|
||||
String _getBottomTitle(double value) {
|
||||
final index = value.toInt();
|
||||
if (chartLabels.isEmpty) return '';
|
||||
if (index < 0 || index >= chartLabels.length) return '';
|
||||
return chartLabels[index];
|
||||
int index = value.toInt();
|
||||
final len = dailyValues.length;
|
||||
if (index < 0 || index >= len) return '';
|
||||
|
||||
if (period == "Hari Ini") {
|
||||
return index % 4 == 0 ? "${index.toString().padLeft(2, '0')}:00" : "";
|
||||
} else if (period == "Minggu Ini") {
|
||||
const days = ["Sen", "Sel", "Rab", "Kam", "Jum", "Sab", "Min"];
|
||||
return days[index % 7];
|
||||
} else {
|
||||
return (index + 1) % 5 == 0 ? "${index + 1}" : "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
double _getInterval() {
|
||||
if (period == "Hari Ini") return 1;
|
||||
if (period == "Minggu Ini") return 1;
|
||||
|
|
|
|||
|
|
@ -68,20 +68,7 @@ Widget _buildDatePickerButton(BuildContext context, EvaporasiViewMode viewMode,
|
|||
context.read<EvaporasiBloc>().add(
|
||||
const EvaporasiViewModeChanged(EvaporasiViewMode.customDate),
|
||||
);
|
||||
|
||||
// Penting: pastikan bottom sheet masih punya context yang memiliki EvaporasiBloc
|
||||
final bloc = context.read<EvaporasiBloc>();
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
builder: (sheetContext) {
|
||||
return BlocProvider.value(
|
||||
value: bloc,
|
||||
child: const EvaporasiDatePicker(),
|
||||
);
|
||||
},
|
||||
);
|
||||
showEvaporasiDatePicker(context);
|
||||
},
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
|
|
|
|||
Loading…
Reference in New Issue