From 0e90908b2d0be0c5d6c1954db46e272fff7c77eb Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Sat, 9 May 2026 15:44:00 +0700 Subject: [PATCH] Revert "Fix evaporasi dashboard: firebase history list + sync chart labels" This reverts commit 42bac0c98054df4b68fa8de4179690bf2b04b5b2. --- .../evaporasi/blocs/evaporasi_bloc.dart | 30 ------ .../evaporasi/blocs/evaporasi_state.dart | 15 --- .../evaporasi/views/evaporasi_screen.dart | 101 ++---------------- .../views/widgets/evaporasi_chart_widget.dart | 23 ++-- .../widgets/evaporasi_period_selector.dart | 15 +-- 5 files changed, 21 insertions(+), 163 deletions(-) diff --git a/lib/screens/monitoring/evaporasi/blocs/evaporasi_bloc.dart b/lib/screens/monitoring/evaporasi/blocs/evaporasi_bloc.dart index 011dd9f..32cee33 100644 --- a/lib/screens/monitoring/evaporasi/blocs/evaporasi_bloc.dart +++ b/lib/screens/monitoring/evaporasi/blocs/evaporasi_bloc.dart @@ -34,8 +34,6 @@ class EvaporasiBloc extends Bloc { WatchEvaporasiStarted event, Emitter 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 { (json) => Evaporasi.fromJson(json), ); - // listData dipakai untuk tab/list di UI (default: ambil data yang sudah ada di Firebase) - final listData = List.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 { 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 { emit(state.copyWith( dailyValues: updated, dailyTemperatures: updatedTemp, - chartLabels: _buildChartLabels(period: event.period), isLoading: false, )); } @@ -204,7 +191,6 @@ class EvaporasiBloc extends Bloc { emit(state.copyWith( dailyValues: updated, dailyTemperatures: updatedTemp, - chartLabels: _buildChartLabels(period: 'Tanggal Khusus'), isLoading: false, )); } @@ -239,22 +225,6 @@ class EvaporasiBloc extends Bloc { return ('Buruk', true); } - List _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; diff --git a/lib/screens/monitoring/evaporasi/blocs/evaporasi_state.dart b/lib/screens/monitoring/evaporasi/blocs/evaporasi_state.dart index fcbd8cf..640d2dd 100644 --- a/lib/screens/monitoring/evaporasi/blocs/evaporasi_state.dart +++ b/lib/screens/monitoring/evaporasi/blocs/evaporasi_state.dart @@ -12,15 +12,6 @@ class EvaporasiState extends Equatable { final List dailyValues; // untuk grafik evaporasi final List 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 chartLabels; - - /// Data untuk list (timestamp asli dari firebase) - final List listData; final List 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? dailyValues, List? dailyTemperatures, - List? chartLabels, - List? listData, List? 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, diff --git a/lib/screens/monitoring/evaporasi/views/evaporasi_screen.dart b/lib/screens/monitoring/evaporasi/views/evaporasi_screen.dart index cc403a7..eb3343a 100644 --- a/lib/screens/monitoring/evaporasi/views/evaporasi_screen.dart +++ b/lib/screens/monitoring/evaporasi/views/evaporasi_screen.dart @@ -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().state; @@ -84,24 +83,16 @@ class EvaporasiScreen extends StatelessWidget { Builder( builder: (context) { final state = context.watch().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) /// ========================= diff --git a/lib/screens/monitoring/evaporasi/views/widgets/evaporasi_chart_widget.dart b/lib/screens/monitoring/evaporasi/views/widgets/evaporasi_chart_widget.dart index af307b4..fe0a686 100644 --- a/lib/screens/monitoring/evaporasi/views/widgets/evaporasi_chart_widget.dart +++ b/lib/screens/monitoring/evaporasi/views/widgets/evaporasi_chart_widget.dart @@ -5,18 +5,14 @@ class EvaporasiChartWidget extends StatelessWidget { final List dailyValues; final List dailyTemperatures; final String period; - final List chartLabels; - const EvaporasiChartWidget({ super.key, required this.dailyValues, required this.dailyTemperatures, required this.period, - required this.chartLabels, }); - double _getMaxY(List 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; diff --git a/lib/screens/monitoring/evaporasi/views/widgets/evaporasi_period_selector.dart b/lib/screens/monitoring/evaporasi/views/widgets/evaporasi_period_selector.dart index 45b79ff..ee5ea72 100644 --- a/lib/screens/monitoring/evaporasi/views/widgets/evaporasi_period_selector.dart +++ b/lib/screens/monitoring/evaporasi/views/widgets/evaporasi_period_selector.dart @@ -68,20 +68,7 @@ Widget _buildDatePickerButton(BuildContext context, EvaporasiViewMode viewMode, context.read().add( const EvaporasiViewModeChanged(EvaporasiViewMode.customDate), ); - - // Penting: pastikan bottom sheet masih punya context yang memiliki EvaporasiBloc - final bloc = context.read(); - 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),