From 9ec9beda7bfbbcd667b9032e6ebd19a8610c8b49 Mon Sep 17 00:00:00 2001 From: Mochamad ongki ramadani Date: Thu, 12 Feb 2026 22:59:01 +0700 Subject: [PATCH 01/28] sistem pengukuran evaporasi home page --- lib/app_view.dart | 7 +- lib/screens/home/home_screen.dart | 474 +++++++++++ lib/screens/home/views/home_screen.dart | 12 - .../air_quality_monitoring_screen.dart | 677 ++++++++++++++++ .../evaporasi_monitoring_screen.dart | 741 ++++++++++++++++++ .../monitoring/widgets/monitoring_shared.dart | 130 +++ .../wind_speed_monitoring_screen.dart | 677 ++++++++++++++++ packages/user_repository/pubspec.lock | 62 +- pubspec.lock | 8 + pubspec.yaml | 5 + 10 files changed, 2750 insertions(+), 43 deletions(-) create mode 100644 lib/screens/home/home_screen.dart delete mode 100644 lib/screens/home/views/home_screen.dart create mode 100644 lib/screens/monitoring/air_quality_monitoring_screen.dart create mode 100644 lib/screens/monitoring/evaporasi_monitoring_screen.dart create mode 100644 lib/screens/monitoring/widgets/monitoring_shared.dart create mode 100644 lib/screens/monitoring/wind_speed_monitoring_screen.dart diff --git a/lib/app_view.dart b/lib/app_view.dart index 3fd5d03..60dc938 100644 --- a/lib/app_view.dart +++ b/lib/app_view.dart @@ -1,9 +1,8 @@ import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:klimatologiot/blocs/authentication_bloc/authentication_bloc.dart'; +// import 'package:flutter_bloc/flutter_bloc.dart'; +// import 'package:klimatologiot/blocs/authentication_bloc/authentication_bloc.dart'; -import 'package:klimatologiot/screens/auth/views/welcome_screen.dart'; -import 'package:klimatologiot/screens/home/views/home_screen.dart'; +import 'package:klimatologiot/screens/home/home_screen.dart'; class MyAppView extends StatelessWidget { const MyAppView({super.key}); diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/home_screen.dart new file mode 100644 index 0000000..4bb2f06 --- /dev/null +++ b/lib/screens/home/home_screen.dart @@ -0,0 +1,474 @@ +import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; +import '../monitoring/evaporasi_monitoring_screen.dart'; +import '../monitoring/wind_speed_monitoring_screen.dart'; +import '../monitoring/air_quality_monitoring_screen.dart'; + +class HomeScreen extends StatelessWidget { + const HomeScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Monitoring Klimatologi"), + centerTitle: true, + ), + + /// 🔹 SIDEBAR (MENU 3 GARIS DI KIRI) + drawer: Drawer( + child: SafeArea( + child: ListView( + padding: EdgeInsets.zero, + children: [ + // 🔹 HEADER DENGAN AKUN INFO + UserAccountsDrawerHeader( + accountName: const Text( + "Admin Klimatologi", + style: TextStyle(fontWeight: FontWeight.bold), + ), + accountEmail: const Text("admin@klimatologi.com"), + currentAccountPicture: CircleAvatar( + backgroundColor: Colors.blue, + child: const Text( + "A", + style: TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + ), + ), + + // 🔹 DASHBOARD MENU + ListTile( + leading: const Icon(Icons.dashboard), + title: const Text("Dashboard"), + onTap: () { + Navigator.pop(context); + }, + ), + + const Divider(), + + // 🔹 MONITORING MENU + const Padding( + padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8), + child: Text( + "Monitoring", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, + color: Colors.grey, + ), + ), + ), + + _buildDrawerItem( + context, + "Evaporasi", + Icons.opacity, + ), + _buildDrawerItem( + context, + "Kecepatan Angin", + Icons.air, + ), + _buildDrawerItem( + context, + "Kualitas Udara", + Icons.cloud, + ), + ], + ), + ), + ), + + /// 🔹 DASHBOARD UTAMA - 3 MONITORING + body: Padding( + padding: const EdgeInsets.all(16), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Selamat Datang Admin Klimatologi", + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 20), + + // 🔹 3 BLOCK DATA HARI INI + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + _buildDataBlock( + "Evaporasi", + "45.2", + "mm", + Colors.blue, + Icons.opacity, + ), + _buildDataBlock( + "Kec. Angin", + "12.5", + "km/h", + Colors.green, + Icons.air, + ), + _buildDataBlock( + "Kualitas Udara", + "78", + "AQI", + Colors.orange, + Icons.cloud, + ), + ], + ), + + const SizedBox(height: 30), + + const Text( + "Grafik Monitoring", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 15), + + _buildDashboardCard(context, "Evaporasi"), + const SizedBox(height: 20), + _buildDashboardCard(context, "Kecepatan Angin"), + const SizedBox(height: 20), + _buildDashboardCard(context, "Kualitas Udara"), + ], + ), + ), + ), + ); + } + + /// DATA BLOCK - PREVIEW DATA HARI INI + Widget _buildDataBlock( + String title, + String value, + String unit, + Color color, + IconData icon, + ) { + return Expanded( + child: Container( + margin: const EdgeInsets.symmetric(horizontal: 4), + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: color.withOpacity(0.1), + borderRadius: BorderRadius.circular(12), + border: Border.all(color: color, width: 2), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Icon(icon, color: color, size: 28), + const SizedBox(height: 8), + Text( + title, + style: const TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + ), + textAlign: TextAlign.center, + ), + const SizedBox(height: 6), + Row( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.baseline, + textBaseline: TextBaseline.alphabetic, + children: [ + Text( + value, + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + color: color, + ), + ), + const SizedBox(width: 4), + Text( + unit, + style: TextStyle( + fontSize: 11, + color: Colors.grey.shade700, + ), + ), + ], + ), + ], + ), + ), + ); + } + + /// DRAWER ITEM + Widget _buildDrawerItem( + BuildContext context, + String title, + IconData icon, + ) { + return ListTile( + leading: Icon(icon), + title: Text(title), + onTap: () { + Navigator.pop(context); + Widget screen; + if (title == "Evaporasi") { + screen = const EvaporasiMonitoringScreen(); + } else if (title == "Kecepatan Angin") { + screen = const WindSpeedMonitoringScreen(); + } else if (title == "Kualitas Udara") { + screen = const AirQualityMonitoringScreen(); + } else { + return; + } + Navigator.push( + context, + MaterialPageRoute(builder: (context) => screen), + ); + }, + ); + } + + /// DASHBOARD CARD - PREVIEW GRAFIK 24 JAM + Widget _buildDashboardCard(BuildContext context, String title) { + return GestureDetector( + onTap: () { + Widget screen; + if (title == "Evaporasi") { + screen = const EvaporasiMonitoringScreen(); + } else if (title == "Kecepatan Angin") { + screen = const WindSpeedMonitoringScreen(); + } else if (title == "Kualitas Udara") { + screen = const AirQualityMonitoringScreen(); + } else { + return; + } + Navigator.push( + context, + MaterialPageRoute(builder: (context) => screen), + ); + }, + child: Card( + elevation: 4, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + title, + style: const TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 12, + vertical: 6, + ), + decoration: BoxDecoration( + color: Colors.green.shade100, + borderRadius: BorderRadius.circular(20), + ), + child: const Text( + "24 Jam", + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.w600, + color: Colors.green, + ), + ), + ), + ], + ), + const SizedBox(height: 16), + SizedBox( + height: 200, + child: LineChart( + LineChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 1, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.shade300, + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: 3, + getTitlesWidget: (value, meta) { + return Text( + '${value.toInt()}h', + style: const TextStyle( + fontSize: 10, + color: Colors.grey, + ), + ); + }, + ), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: 1, + getTitlesWidget: (value, meta) { + return Text( + value.toInt().toString(), + style: const TextStyle( + fontSize: 9, + color: Colors.grey, + ), + ); + }, + reservedSize: 28, + ), + ), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + lineBarsData: [ + LineChartBarData( + spots: _getMonitoringData(title), + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: _getColorByTitle(title), + strokeWidth: 0, + ); + }, + ), + color: _getColorByTitle(title), + belowBarData: BarAreaData( + show: true, + color: _getColorByTitle(title).withOpacity(0.1), + ), + ), + ], + ), + ), + ), + const SizedBox(height: 12), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Rata-rata: ${_getAverageData(title)}", + style: TextStyle( + fontSize: 12, + color: Colors.grey.shade700, + fontWeight: FontWeight.w600, + ), + ), + Text( + "Tap untuk detail", + style: TextStyle( + fontSize: 12, + color: Colors.grey.shade600, + fontStyle: FontStyle.italic, + ), + ), + ], + ), + ], + ), + ), + ), + ); + } + + /// GET MONITORING DATA FOR 24 HOURS + List _getMonitoringData(String title) { + final dataMap = { + "Evaporasi": [ + 2.1, 2.3, 2.0, 1.9, 2.2, 2.5, 3.0, 3.5, 4.0, 4.2, + 4.5, 4.8, 5.0, 5.2, 5.1, 4.9, 4.5, 4.0, 3.5, 3.0, 2.8, 2.5, 2.3, 2.2 + ], + "Kecepatan Angin": [ + 5.0, 5.2, 4.8, 4.5, 4.3, 4.6, 5.1, 6.0, 7.2, 8.5, + 9.0, 10.2, 11.0, 10.5, 10.0, 9.2, 8.0, 6.5, 5.5, 5.0, 4.8, 4.5, 5.0, 5.2 + ], + "Kualitas Udara": [ + 68.0, 70.0, 72.0, 75.0, 78.0, 80.0, 78.0, 75.0, 72.0, 70.0, + 68.0, 65.0, 60.0, 58.0, 60.0, 62.0, 65.0, 68.0, 70.0, 72.0, 75.0, 78.0, 76.0, 74.0 + ], + }; + + final data = dataMap[title] ?? []; + return List.generate( + data.length, + (index) => FlSpot(index.toDouble(), data[index]), + ); + } + + /// GET AVERAGE VALUE + String _getAverageData(String title) { + final dataMap = { + "Evaporasi": "3.5 mm", + "Kecepatan Angin": "6.8 km/h", + "Kualitas Udara": "70 AQI", + }; + return dataMap[title] ?? "N/A"; + } + + /// GET COLOR BY TITLE + Color _getColorByTitle(String title) { + switch (title) { + case "Evaporasi": + return Colors.blue; + case "Kecepatan Angin": + return Colors.green; + case "Kualitas Udara": + return Colors.orange; + default: + return Colors.grey; + } + } +} diff --git a/lib/screens/home/views/home_screen.dart b/lib/screens/home/views/home_screen.dart deleted file mode 100644 index 0ebe19b..0000000 --- a/lib/screens/home/views/home_screen.dart +++ /dev/null @@ -1,12 +0,0 @@ -import 'package:flutter/material.dart'; - -class HomeScreen extends StatelessWidget{ - const HomeScreen ({super.key}); - - @override - Widget build(BuildContext context) { - return Scaffold( - - ); - } -} \ No newline at end of file diff --git a/lib/screens/monitoring/air_quality_monitoring_screen.dart b/lib/screens/monitoring/air_quality_monitoring_screen.dart new file mode 100644 index 0000000..32059d7 --- /dev/null +++ b/lib/screens/monitoring/air_quality_monitoring_screen.dart @@ -0,0 +1,677 @@ +import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; +import 'widgets/monitoring_shared.dart'; + +/// AIR QUALITY MONITORING SCREEN +class AirQualityMonitoringScreen extends StatefulWidget { + const AirQualityMonitoringScreen({super.key}); + + @override + State createState() => _AirQualityMonitoringScreenState(); +} + +class _AirQualityMonitoringScreenState extends State { + String _selectedPeriod = "Hari Ini"; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Monitoring Kualitas Udara"), + centerTitle: true, + ), + body: Padding( + padding: const EdgeInsets.all(16), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Kualitas Udara", + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 20), + + /// GRAFIK MONITORING + _buildMonitoringGraphBlock(), + const SizedBox(height: 25), + + /// PENJELASAN + _buildAirQualityExplanation(), + const SizedBox(height: 25), + + /// STATISTIK TAHUNAN + _buildAnnualAirQualityGraphSection(), + ], + ), + ), + ), + ); + } + + /// EXPORT FUNCTIONS + void _exportDailyAirQualityData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KUALITAS UDARA - HARIAN (24 JAM)"); + csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); + csvContent.writeln(""); + csvContent.writeln("Jam,AQI (Air Quality Index)"); + + final dailyData = [ + 68.0, 70.0, 72.0, 75.0, 78.0, 80.0, 78.0, 75.0, 72.0, 70.0, + 68.0, 65.0, 60.0, 58.0, 60.0, 62.0, 65.0, 68.0, 70.0, 72.0, 75.0, 78.0, 76.0, 74.0 + ]; + for (int i = 0; i < dailyData.length; i++) { + csvContent.writeln("$i:00,${dailyData[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Harian"); + csvContent.writeln("Total: 1709 AQI"); + csvContent.writeln("Rata-rata: 71.2 AQI"); + csvContent.writeln("Maksimal: 80 AQI"); + csvContent.writeln("Minimal: 58 AQI"); + + showExportPreview(context, csvContent.toString(), "Data Harian Kualitas Udara"); + } + + void _exportWeeklyAirQualityData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KUALITAS UDARA - MINGGUAN"); + csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); + csvContent.writeln(""); + csvContent.writeln("Hari,Rata-rata AQI"); + + final days = ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu']; + final weeklyData = [68.0, 72.0, 75.0, 78.0, 72.0, 68.0, 62.0]; + + for (int i = 0; i < days.length; i++) { + csvContent.writeln("${days[i]},${weeklyData[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Mingguan"); + csvContent.writeln("Total: 495 AQI"); + csvContent.writeln("Rata-rata: 70.7 AQI"); + csvContent.writeln("Maksimal: 78 AQI"); + csvContent.writeln("Minimal: 62 AQI"); + + showExportPreview(context, csvContent.toString(), "Data Mingguan Kualitas Udara"); + } + + void _exportMonthlyAirQualityData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KUALITAS UDARA - BULANAN"); + csvContent.writeln("Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); + csvContent.writeln(""); + csvContent.writeln("Tanggal,Rata-rata AQI"); + + for (int i = 1; i <= 28; i++) { + final value = (70.0 + (i % 6) * 2.5).toStringAsFixed(1); + csvContent.writeln("$i,$value"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Bulanan"); + csvContent.writeln("Total: 1990 AQI"); + csvContent.writeln("Rata-rata: 71.1 AQI"); + csvContent.writeln("Maksimal: 82 AQI"); + csvContent.writeln("Minimal: 55 AQI"); + + showExportPreview(context, csvContent.toString(), "Data Bulanan Kualitas Udara"); + } + + void _exportAnnualAirQualityData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KUALITAS UDARA - TAHUNAN"); + csvContent.writeln("Tahun: 2025"); + csvContent.writeln(""); + csvContent.writeln("Bulan,Rata-rata AQI,AQI Max"); + + final months = [ + 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', + 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' + ]; + final averages = [68.0, 70.0, 72.5, 75.0, 78.0, 80.0, 82.0, 80.0, 75.0, 70.0, 68.0, 65.0]; + final maxAqi = [85.0, 88.0, 90.0, 95.0, 98.0, 100.0, 102.0, 100.0, 95.0, 90.0, 85.0, 80.0]; + + for (int i = 0; i < months.length; i++) { + csvContent.writeln("${months[i]},${averages[i]},${maxAqi[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("STATISTIK TAHUNAN"); + csvContent.writeln("Rata-rata Tahunan: 74.2 AQI"); + csvContent.writeln("AQI Max Teringgi: 102.0"); + csvContent.writeln("AQI Min Terendah: 65.0"); + + showExportPreview(context, csvContent.toString(), "Data Tahunan Kualitas Udara"); + } + + /// DATA GENERATORS + List _getAirQualityPeriodData() { + switch (_selectedPeriod) { + case "Hari Ini": + return List.generate(24, (i) { + final values = [ + 68.0, 70.0, 72.0, 75.0, 78.0, 80.0, 78.0, 75.0, 72.0, 70.0, + 68.0, 65.0, 60.0, 58.0, 60.0, 62.0, 65.0, 68.0, 70.0, 72.0, 75.0, 78.0, 76.0, 74.0 + ]; + return FlSpot(i.toDouble(), values[i]); + }); + case "Minggu Ini": + return [ + const FlSpot(0, 68.0), + const FlSpot(1, 72.0), + const FlSpot(2, 75.0), + const FlSpot(3, 78.0), + const FlSpot(4, 72.0), + const FlSpot(5, 68.0), + const FlSpot(6, 62.0), + ]; + case "Bulan Ini": + return [ + const FlSpot(0, 70.0), + const FlSpot(1, 72.5), + const FlSpot(2, 75.0), + const FlSpot(3, 77.5), + const FlSpot(4, 80.0), + const FlSpot(5, 82.0), + const FlSpot(6, 80.0), + const FlSpot(7, 78.0), + const FlSpot(8, 75.0), + const FlSpot(9, 72.0), + const FlSpot(10, 70.0), + const FlSpot(11, 68.0), + ]; + default: + return []; + } + } + + /// UI BUILDERS + Widget _buildMonitoringGraphBlock() { + return Card( + elevation: 4, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + "Status Kualitas Udara", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 5, + ), + decoration: BoxDecoration( + color: Colors.amber.shade100, + borderRadius: BorderRadius.circular(20), + ), + child: const Text( + "Normal", + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.w600, + color: Colors.amber, + ), + ), + ), + ], + ), + const SizedBox(height: 16), + + /// PERIOD SELECTOR + EXPORT + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { + return Padding( + padding: const EdgeInsets.only(right: 8), + child: ChoiceChip( + label: Text(period), + selected: _selectedPeriod == period, + onSelected: (selected) { + setState(() { + _selectedPeriod = period; + }); + }, + selectedColor: Colors.orange, + labelStyle: TextStyle( + color: _selectedPeriod == period + ? Colors.white + : Colors.black, + ), + ), + ); + }).toList(), + ), + ), + ), + const SizedBox(width: 8), + ElevatedButton.icon( + onPressed: () { + if (_selectedPeriod == "Hari Ini") { + _exportDailyAirQualityData(); + } else if (_selectedPeriod == "Minggu Ini") { + _exportWeeklyAirQualityData(); + } else if (_selectedPeriod == "Bulan Ini") { + _exportMonthlyAirQualityData(); + } + }, + icon: const Icon(Icons.download, size: 16), + label: const Text("Export"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.orange, + foregroundColor: Colors.white, + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 6, + ), + textStyle: const TextStyle(fontSize: 11), + ), + ), + ], + ), + const SizedBox(height: 16), + + /// GRAPH + SizedBox( + height: 300, + child: LineChart( + LineChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 1, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.shade300, + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: getPeriodInterval(_selectedPeriod), + getTitlesWidget: (value, meta) { + return Text( + getPeriodLabel(_selectedPeriod, value), + style: const TextStyle( + fontSize: 10, + color: Colors.grey, + ), + ); + }, + ), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: 1, + getTitlesWidget: (value, meta) { + return Text( + value.toInt().toString(), + style: const TextStyle( + fontSize: 9, + color: Colors.grey, + ), + ); + }, + reservedSize: 28, + ), + ), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + lineBarsData: [ + LineChartBarData( + spots: _getAirQualityPeriodData(), + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.orange, + strokeWidth: 0, + ); + }, + ), + color: Colors.orange, + belowBarData: BarAreaData( + show: true, + color: Colors.orange.withOpacity(0.1), + ), + ), + ], + ), + ), + ), + ], + ), + ), + ); + } + + Widget _buildAirQualityExplanation() { + return Container( + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.orange.shade50, + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.orange.shade200), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Penjelasan Kualitas Udara", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, + color: Colors.orange, + ), + ), + const SizedBox(height: 10), + const Text( + "Kualitas udara diukur menggunakan Air Quality Index (AQI) yang menunjukkan tingkat polusi udara. AQI berkisar dari 0-500, dengan nilai lebih rendah menunjukkan udara lebih bersih. Monitoring kualitas udara penting untuk kesehatan masyarakat, perencanaan lingkungan, dan identifikasi sumber polusi. Kategori: 0-50 (Baik), 51-100 (Wajar), 101-150 (Tidak Sehat), 151+ (Sangat Tidak Sehat).", + style: TextStyle( + fontSize: 12, + height: 1.6, + color: Colors.orange, + ), + ), + ], + ), + ); + } + + Widget _buildAnnualAirQualityGraphSection() { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Statistik Tahunan Kualitas Udara", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 15), + + /// STATS + Row( + children: [ + Expanded( + child: StatCard( + title: "Rata-rata Tahunan", + value: "74.2 AQI", + color: Colors.orange, + icon: Icons.cloud, + ), + ), + const SizedBox(width: 10), + Expanded( + child: StatCard( + title: "AQI Maksimal", + value: "102.0", + color: Colors.red, + icon: Icons.warning, + ), + ), + ], + ), + const SizedBox(height: 20), + + /// CHART + const Text( + "Grafik Tahunan - Rata-rata & AQI Maksimal", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + ), + ), + const SizedBox(height: 12), + Card( + elevation: 3, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: SizedBox( + height: 320, + child: LineChart( + LineChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 5, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.shade300, + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + getTitlesWidget: (value, meta) { + final months = [ + 'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', + 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des' + ]; + return Text( + months[value.toInt()], + style: const TextStyle( + fontSize: 10, + color: Colors.grey, + ), + ); + }, + reservedSize: 30, + ), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + getTitlesWidget: (value, meta) { + return Text( + '${value.toInt()} AQI', + style: const TextStyle( + fontSize: 9, + color: Colors.grey, + ), + ); + }, + reservedSize: 50, + ), + ), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + lineBarsData: [ + /// Rata-rata + LineChartBarData( + spots: const [ + FlSpot(0, 68.0), + FlSpot(1, 70.0), + FlSpot(2, 72.5), + FlSpot(3, 75.0), + FlSpot(4, 78.0), + FlSpot(5, 80.0), + FlSpot(6, 82.0), + FlSpot(7, 80.0), + FlSpot(8, 75.0), + FlSpot(9, 70.0), + FlSpot(10, 68.0), + FlSpot(11, 65.0), + ], + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.orange, + strokeWidth: 0, + ); + }, + ), + color: Colors.orange, + belowBarData: BarAreaData( + show: true, + color: Colors.orange.withOpacity(0.1), + ), + ), + /// AQI Max + LineChartBarData( + spots: const [ + FlSpot(0, 85.0), + FlSpot(1, 88.0), + FlSpot(2, 90.0), + FlSpot(3, 95.0), + FlSpot(4, 98.0), + FlSpot(5, 100.0), + FlSpot(6, 102.0), + FlSpot(7, 100.0), + FlSpot(8, 95.0), + FlSpot(9, 90.0), + FlSpot(10, 85.0), + FlSpot(11, 80.0), + ], + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.red, + strokeWidth: 0, + ); + }, + ), + color: Colors.red, + ), + ], + ), + ), + ), + ), + ), + const SizedBox(height: 15), + + /// LEGEND + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.orange, + borderRadius: BorderRadius.circular(3), + ), + ), + const SizedBox(width: 8), + const Text( + "Rata-rata AQI", + style: TextStyle(fontSize: 12), + ), + const SizedBox(width: 20), + Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(3), + ), + ), + const SizedBox(width: 8), + const Text( + "AQI Maksimal", + style: TextStyle(fontSize: 12), + ), + ], + ), + const SizedBox(height: 15), + Center( + child: ElevatedButton.icon( + onPressed: () => _exportAnnualAirQualityData(), + icon: const Icon(Icons.file_download), + label: const Text("Download Excel Tahunan"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.green, + foregroundColor: Colors.white, + ), + ), + ), + ], + ); + } +} diff --git a/lib/screens/monitoring/evaporasi_monitoring_screen.dart b/lib/screens/monitoring/evaporasi_monitoring_screen.dart new file mode 100644 index 0000000..9618d26 --- /dev/null +++ b/lib/screens/monitoring/evaporasi_monitoring_screen.dart @@ -0,0 +1,741 @@ +import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; +import 'widgets/monitoring_shared.dart'; + +/// EVAPORASI MONITORING SCREEN +class EvaporasiMonitoringScreen extends StatefulWidget { + const EvaporasiMonitoringScreen({super.key}); + + @override + State createState() => _EvaporasiMonitoringScreenState(); +} + +class _EvaporasiMonitoringScreenState extends State { + String _selectedPeriod = "Hari Ini"; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Monitoring Evaporasi"), + centerTitle: true, + ), + body: Padding( + padding: const EdgeInsets.all(16), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Evaporasi", + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 20), + + /// SISTEM KONTROL AIR OTOMATIS + _buildAutomaticWaterControlSystem(), + const SizedBox(height: 25), + + /// GRAFIK MONITORING + _buildMonitoringGraphBlock(), + const SizedBox(height: 25), + + /// PENJELASAN + _buildMonitoringExplanation(), + const SizedBox(height: 25), + + /// STATISTIK TAHUNAN + _buildAnnualCombinedGraphSection(), + ], + ), + ), + ), + ); + } + + /// EXPORT FUNCTIONS + void _exportDailyData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING EVAPORASI - HARIAN (24 JAM)"); + csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); + csvContent.writeln(""); + csvContent.writeln("Jam,Nilai (mm)"); + + final dailyData = [ + 2.1, 2.3, 2.0, 1.9, 2.2, 2.5, 3.0, 3.5, 4.0, 4.2, + 4.5, 4.8, 5.0, 5.2, 5.1, 4.9, 4.5, 4.0, 3.5, 3.0, 2.8, 2.5, 2.3, 2.2 + ]; + for (int i = 0; i < dailyData.length; i++) { + csvContent.writeln("$i:00,${dailyData[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Harian"); + csvContent.writeln("Total: 79.4 mm"); + csvContent.writeln("Rata-rata: 3.3 mm"); + csvContent.writeln("Maksimal: 5.2 mm"); + csvContent.writeln("Minimal: 1.9 mm"); + + showExportPreview(context, csvContent.toString(), "Data Harian"); + } + + void _exportWeeklyData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING EVAPORASI - MINGGUAN"); + csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); + csvContent.writeln(""); + csvContent.writeln("Hari,Nilai (mm)"); + + final days = ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu']; + final weeklyData = [3.5, 3.8, 4.2, 4.5, 4.0, 3.8, 3.2]; + + for (int i = 0; i < days.length; i++) { + csvContent.writeln("${days[i]},${weeklyData[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Mingguan"); + csvContent.writeln("Total: 27.0 mm"); + csvContent.writeln("Rata-rata: 3.86 mm"); + csvContent.writeln("Maksimal: 4.5 mm"); + csvContent.writeln("Minimal: 3.2 mm"); + + showExportPreview(context, csvContent.toString(), "Data Mingguan"); + } + + void _exportMonthlyData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING EVAPORASI - BULANAN"); + csvContent.writeln("Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); + csvContent.writeln(""); + csvContent.writeln("Tanggal,Nilai (mm)"); + + for (int i = 1; i <= 28; i++) { + final value = (3.0 + (i % 6) * 0.5).toStringAsFixed(1); + csvContent.writeln("$i,$value"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Bulanan"); + csvContent.writeln("Total: 99.2 mm"); + csvContent.writeln("Rata-rata: 3.54 mm"); + csvContent.writeln("Maksimal: 5.0 mm"); + csvContent.writeln("Minimal: 2.5 mm"); + + showExportPreview(context, csvContent.toString(), "Data Bulanan"); + } + + void _exportAnnualData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING EVAPORASI - TAHUNAN"); + csvContent.writeln("Tahun: 2025"); + csvContent.writeln(""); + csvContent.writeln("Bulan,Pengisian (x),Rata-rata (mm)"); + + final months = [ + 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', + 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' + ]; + final fillings = [12, 13, 15, 14, 13, 12, 14, 16, 13, 14, 15, 13]; + final averages = [3.5, 3.8, 4.2, 4.5, 5.0, 5.2, 5.5, 5.8, 5.0, 4.5, 4.0, 3.7]; + + for (int i = 0; i < months.length; i++) { + csvContent.writeln("${months[i]},${fillings[i]},${averages[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("STATISTIK TAHUNAN"); + csvContent.writeln("Total Pengisian: 156x"); + csvContent.writeln("Rata-rata Evaporasi: 4.4 mm"); + csvContent.writeln("Total Evaporasi: 52.8 mm"); + + showExportPreview(context, csvContent.toString(), "Data Tahunan"); + } + + /// DATA GENERATORS + List _getEvaporationPeriodData() { + switch (_selectedPeriod) { + case "Hari Ini": + return List.generate(24, (i) { + final values = [ + 2.1, 2.3, 2.0, 1.9, 2.2, 2.5, 3.0, 3.5, 4.0, 4.2, + 4.5, 4.8, 5.0, 5.2, 5.1, 4.9, 4.5, 4.0, 3.5, 3.0, 2.8, 2.5, 2.3, 2.2 + ]; + return FlSpot(i.toDouble(), values[i]); + }); + case "Minggu Ini": + return [ + const FlSpot(0, 3.5), + const FlSpot(1, 3.8), + const FlSpot(2, 4.2), + const FlSpot(3, 4.5), + const FlSpot(4, 4.0), + const FlSpot(5, 3.8), + const FlSpot(6, 3.2), + ]; + case "Bulan Ini": + return [ + const FlSpot(0, 3.5), + const FlSpot(1, 3.8), + const FlSpot(2, 4.2), + const FlSpot(3, 4.5), + const FlSpot(4, 5.0), + const FlSpot(5, 5.2), + const FlSpot(6, 5.5), + const FlSpot(7, 5.8), + const FlSpot(8, 5.0), + const FlSpot(9, 4.5), + const FlSpot(10, 4.0), + const FlSpot(11, 3.7), + ]; + default: + return []; + } + } + + /// UI BUILDERS + Widget _buildAutomaticWaterControlSystem() { + bool isActive = DateTime.now().hour >= 6 && DateTime.now().hour < 7; + + return Container( + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.grey.shade50, + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.grey.shade300), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Sistem Kontrol Air Otomatis", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 12), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Jadwal Operasional", + style: TextStyle( + fontSize: 12, + color: Colors.grey, + ), + ), + const SizedBox(height: 4), + const Text( + "06.00 - 07.00 WIB", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + ), + ), + ], + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 10, + ), + decoration: BoxDecoration( + color: isActive ? Colors.blue : Colors.grey.shade300, + borderRadius: BorderRadius.circular(20), + ), + child: Text( + isActive ? "AKTIF" : "TIDAK AKTIF", + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.bold, + color: isActive ? Colors.white : Colors.grey.shade700, + ), + ), + ), + ], + ), + const SizedBox(height: 12), + Container( + padding: const EdgeInsets.all(10), + decoration: BoxDecoration( + color: Colors.blue.shade50, + borderRadius: BorderRadius.circular(8), + ), + child: const Text( + "Sistem otomatis akan mengisi air pada waktu yang telah ditentukan untuk menjaga tingkat evaporasi pada level optimal.", + style: TextStyle( + fontSize: 11, + color: Colors.blue, + height: 1.5, + ), + ), + ), + ], + ), + ); + } + + Widget _buildMonitoringGraphBlock() { + return Card( + elevation: 4, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + "Status Evaporasi", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 5, + ), + decoration: BoxDecoration( + color: Colors.amber.shade100, + borderRadius: BorderRadius.circular(20), + ), + child: const Text( + "Normal", + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.w600, + color: Colors.amber, + ), + ), + ), + ], + ), + const SizedBox(height: 16), + + /// PERIOD SELECTOR + EXPORT + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { + return Padding( + padding: const EdgeInsets.only(right: 8), + child: ChoiceChip( + label: Text(period), + selected: _selectedPeriod == period, + onSelected: (selected) { + setState(() { + _selectedPeriod = period; + }); + }, + selectedColor: Colors.blue, + labelStyle: TextStyle( + color: _selectedPeriod == period + ? Colors.white + : Colors.black, + ), + ), + ); + }).toList(), + ), + ), + ), + const SizedBox(width: 8), + ElevatedButton.icon( + onPressed: () { + if (_selectedPeriod == "Hari Ini") { + _exportDailyData(); + } else if (_selectedPeriod == "Minggu Ini") { + _exportWeeklyData(); + } else if (_selectedPeriod == "Bulan Ini") { + _exportMonthlyData(); + } + }, + icon: const Icon(Icons.download, size: 16), + label: const Text("Export"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.orange, + foregroundColor: Colors.white, + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 6, + ), + textStyle: const TextStyle(fontSize: 11), + ), + ), + ], + ), + const SizedBox(height: 16), + + /// GRAPH + SizedBox( + height: 300, + child: LineChart( + LineChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 1, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.shade300, + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: getPeriodInterval(_selectedPeriod), + getTitlesWidget: (value, meta) { + return Text( + getPeriodLabel(_selectedPeriod, value), + style: const TextStyle( + fontSize: 10, + color: Colors.grey, + ), + ); + }, + ), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: 1, + getTitlesWidget: (value, meta) { + return Text( + value.toInt().toString(), + style: const TextStyle( + fontSize: 9, + color: Colors.grey, + ), + ); + }, + reservedSize: 28, + ), + ), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + lineBarsData: [ + LineChartBarData( + spots: _getEvaporationPeriodData(), + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.blue, + strokeWidth: 0, + ); + }, + ), + color: Colors.blue, + belowBarData: BarAreaData( + show: true, + color: Colors.blue.withOpacity(0.1), + ), + ), + ], + ), + ), + ), + ], + ), + ), + ); + } + + Widget _buildMonitoringExplanation() { + return Container( + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.blue.shade50, + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.blue.shade200), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Penjelasan Evaporasi", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, + color: Colors.blue, + ), + ), + const SizedBox(height: 10), + const Text( + "Evaporasi adalah proses penguapan air dari permukaan tanah atau air menuju atmosfer. Tingkat evaporasi dipengaruhi oleh suhu, kelembaban udara, kecepatan angin, dan intensitas cahaya matahari. Data ini penting untuk manajemen irigasi dan perencanaan kebutuhan air.", + style: TextStyle( + fontSize: 12, + height: 1.6, + color: Colors.blue, + ), + ), + ], + ), + ); + } + + Widget _buildAnnualCombinedGraphSection() { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Statistik Tahunan & Rata-rata", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 15), + + /// STATS + Row( + children: [ + Expanded( + child: StatCard( + title: "Total Pengisian", + value: "156x", + color: Colors.blue, + icon: Icons.water_drop, + ), + ), + const SizedBox(width: 10), + Expanded( + child: StatCard( + title: "Rata-rata", + value: "4.2 mm", + color: Colors.green, + icon: Icons.trending_up, + ), + ), + ], + ), + const SizedBox(height: 20), + + /// CHART + const Text( + "Grafik Tahunan - Pengisian Air & Rata-rata Evaporasi", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + ), + ), + const SizedBox(height: 12), + Card( + elevation: 3, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + children: [ + SizedBox( + height: 320, + child: BarChart( + BarChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 2, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.shade300, + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + getTitlesWidget: (value, meta) { + final months = [ + 'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', + 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des' + ]; + return Text( + months[value.toInt()], + style: const TextStyle( + fontSize: 10, + color: Colors.grey, + ), + ); + }, + reservedSize: 30, + ), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + getTitlesWidget: (value, meta) { + return Text( + value.toInt().toString(), + style: const TextStyle( + fontSize: 9, + color: Colors.grey, + ), + ); + }, + reservedSize: 28, + ), + ), + rightTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + getTitlesWidget: (value, meta) { + return Text( + '${value.toInt()} mm', + style: const TextStyle( + fontSize: 9, + color: Colors.green, + ), + ); + }, + reservedSize: 45, + ), + ), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + right: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + barGroups: [ + buildBarGroup(0, 12), + buildBarGroup(1, 13), + buildBarGroup(2, 15), + buildBarGroup(3, 14), + buildBarGroup(4, 13), + buildBarGroup(5, 12), + buildBarGroup(6, 14), + buildBarGroup(7, 16), + buildBarGroup(8, 13), + buildBarGroup(9, 14), + buildBarGroup(10, 15), + buildBarGroup(11, 13), + ], + rangeAnnotations: RangeAnnotations( + horizontalRangeAnnotations: [ + HorizontalRangeAnnotation( + y1: 3.5, + y2: 5.8, + color: Colors.green.withOpacity(0.1), + ), + ], + ), + ), + ), + ), + const SizedBox(height: 20), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.blue, + borderRadius: BorderRadius.circular(3), + ), + ), + const SizedBox(width: 8), + const Text( + "Pengisian Air (kali)", + style: TextStyle(fontSize: 12), + ), + const SizedBox(width: 20), + Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.green.withOpacity(0.3), + borderRadius: BorderRadius.circular(3), + ), + ), + const SizedBox(width: 8), + const Text( + "Area Rata-rata (mm)", + style: TextStyle(fontSize: 12), + ), + ], + ), + ], + ), + ), + ), + const SizedBox(height: 15), + Center( + child: ElevatedButton.icon( + onPressed: () => _exportAnnualData(), + icon: const Icon(Icons.file_download), + label: const Text("Download Excel Tahunan"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.green, + foregroundColor: Colors.white, + ), + ), + ), + ], + ); + } +} diff --git a/lib/screens/monitoring/widgets/monitoring_shared.dart b/lib/screens/monitoring/widgets/monitoring_shared.dart new file mode 100644 index 0000000..db78b10 --- /dev/null +++ b/lib/screens/monitoring/widgets/monitoring_shared.dart @@ -0,0 +1,130 @@ +import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; + +/// SHOW EXPORT PREVIEW DIALOG +/// Helper function untuk menampilkan preview export data +void showExportPreview(BuildContext context, String content, String title) { + showDialog( + context: context, + builder: (context) => AlertDialog( + title: Text("Preview Export - $title"), + content: SizedBox( + width: double.maxFinite, + child: SingleChildScrollView( + child: Text( + content, + style: const TextStyle( + fontFamily: 'monospace', + fontSize: 10, + ), + ), + ), + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text("Tutup"), + ), + ], + ), + ); +} + +/// STAT CARD WIDGET +/// Reusable card untuk menampilkan statistik +class StatCard extends StatelessWidget { + final String title; + final String value; + final Color color; + final IconData icon; + + const StatCard({ + super.key, + required this.title, + required this.value, + required this.color, + required this.icon, + }); + + @override + Widget build(BuildContext context) { + return Container( + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: color.withOpacity(0.1), + borderRadius: BorderRadius.circular(12), + border: Border.all(color: color, width: 1), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(icon, color: color, size: 20), + const SizedBox(height: 8), + Text( + title, + style: const TextStyle( + fontSize: 11, + color: Colors.grey, + ), + ), + const SizedBox(height: 4), + Text( + value, + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + color: color, + ), + ), + ], + ), + ); + } +} + +/// BUILD BAR GROUP FOR CHART +/// Helper untuk membuat bar group di BarChart +BarChartGroupData buildBarGroup(int x, double value) { + return BarChartGroupData( + x: x, + barRods: [ + BarChartRodData( + toY: value.toDouble(), + color: Colors.blue, + width: 12, + borderRadius: const BorderRadius.vertical(top: Radius.circular(6)), + ), + ], + ); +} + +/// GET PERIOD INTERVAL +/// Menentukan spacing interval berdasarkan periode +double getPeriodInterval(String period) { + switch (period) { + case "Hari Ini": + return 3; + case "Minggu Ini": + return 1; + case "Bulan Ini": + return 2; + default: + return 1; + } +} + +/// GET PERIOD LABEL +/// Menentukan label untuk X-axis berdasarkan periode +String getPeriodLabel(String period, double value) { + switch (period) { + case "Hari Ini": + return '${value.toInt()}h'; + case "Minggu Ini": + final days = ['Sen', 'Sel', 'Rab', 'Kam', 'Jum', 'Sab', 'Min']; + return days[value.toInt()]; + case "Bulan Ini": + return 'M${value.toInt() + 1}'; + default: + return ''; + } +} diff --git a/lib/screens/monitoring/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed_monitoring_screen.dart new file mode 100644 index 0000000..f56b33f --- /dev/null +++ b/lib/screens/monitoring/wind_speed_monitoring_screen.dart @@ -0,0 +1,677 @@ +import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; +import 'widgets/monitoring_shared.dart'; + +/// WIND SPEED MONITORING SCREEN +class WindSpeedMonitoringScreen extends StatefulWidget { + const WindSpeedMonitoringScreen({super.key}); + + @override + State createState() => _WindSpeedMonitoringScreenState(); +} + +class _WindSpeedMonitoringScreenState extends State { + String _selectedPeriod = "Hari Ini"; + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Monitoring Kecepatan Angin"), + centerTitle: true, + ), + body: Padding( + padding: const EdgeInsets.all(16), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Kecepatan Angin", + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 20), + + /// GRAFIK MONITORING + _buildMonitoringGraphBlock(), + const SizedBox(height: 25), + + /// PENJELASAN + _buildWindSpeedExplanation(), + const SizedBox(height: 25), + + /// STATISTIK TAHUNAN + _buildAnnualWindGraphSection(), + ], + ), + ), + ), + ); + } + + /// EXPORT FUNCTIONS + void _exportDailyWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - HARIAN (24 JAM)"); + csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); + csvContent.writeln(""); + csvContent.writeln("Jam,Kecepatan (km/h)"); + + final dailyData = [ + 5.0, 5.2, 4.8, 4.5, 4.3, 4.6, 5.1, 6.0, 7.2, 8.5, + 9.0, 10.2, 11.0, 10.5, 10.0, 9.2, 8.0, 6.5, 5.5, 5.0, 4.8, 4.5, 5.0, 5.2 + ]; + for (int i = 0; i < dailyData.length; i++) { + csvContent.writeln("$i:00,${dailyData[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Harian"); + csvContent.writeln("Total: 165.8 km/h"); + csvContent.writeln("Rata-rata: 6.9 km/h"); + csvContent.writeln("Maksimal: 11.0 km/h"); + csvContent.writeln("Minimal: 4.3 km/h"); + + showExportPreview(context, csvContent.toString(), "Data Harian Kecepatan Angin"); + } + + void _exportWeeklyWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - MINGGUAN"); + csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); + csvContent.writeln(""); + csvContent.writeln("Hari,Rata-rata (km/h)"); + + final days = ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu']; + final weeklyData = [6.5, 7.2, 7.8, 8.0, 7.5, 6.8, 5.5]; + + for (int i = 0; i < days.length; i++) { + csvContent.writeln("${days[i]},${weeklyData[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Mingguan"); + csvContent.writeln("Total: 49.3 km/h"); + csvContent.writeln("Rata-rata: 7.0 km/h"); + csvContent.writeln("Maksimal: 8.0 km/h"); + csvContent.writeln("Minimal: 5.5 km/h"); + + showExportPreview(context, csvContent.toString(), "Data Mingguan Kecepatan Angin"); + } + + void _exportMonthlyWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - BULANAN"); + csvContent.writeln("Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); + csvContent.writeln(""); + csvContent.writeln("Tanggal,Rata-rata (km/h)"); + + for (int i = 1; i <= 28; i++) { + final value = (6.0 + (i % 6) * 0.8).toStringAsFixed(1); + csvContent.writeln("$i,$value"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Bulanan"); + csvContent.writeln("Total: 180.5 km/h"); + csvContent.writeln("Rata-rata: 6.4 km/h"); + csvContent.writeln("Maksimal: 9.0 km/h"); + csvContent.writeln("Minimal: 4.0 km/h"); + + showExportPreview(context, csvContent.toString(), "Data Bulanan Kecepatan Angin"); + } + + void _exportAnnualWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - TAHUNAN"); + csvContent.writeln("Tahun: 2025"); + csvContent.writeln(""); + csvContent.writeln("Bulan,Rata-rata (km/h),Kecepatan Max (km/h)"); + + final months = [ + 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', + 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' + ]; + final averages = [5.5, 6.2, 6.8, 7.5, 7.8, 8.0, 8.2, 8.0, 7.2, 6.5, 5.8, 5.2]; + final maxSpeed = [12.0, 13.5, 14.0, 15.5, 16.0, 16.2, 16.5, 16.0, 15.0, 14.0, 12.5, 11.0]; + + for (int i = 0; i < months.length; i++) { + csvContent.writeln("${months[i]},${averages[i]},${maxSpeed[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("STATISTIK TAHUNAN"); + csvContent.writeln("Rata-rata Tahunan: 7.1 km/h"); + csvContent.writeln("Kecepatan Max Tertinggi: 16.5 km/h"); + csvContent.writeln("Kecepatan Min Terendah: 5.2 km/h"); + + showExportPreview(context, csvContent.toString(), "Data Tahunan Kecepatan Angin"); + } + + /// DATA GENERATORS + List _getWindSpeedPeriodData() { + switch (_selectedPeriod) { + case "Hari Ini": + return List.generate(24, (i) { + final values = [ + 5.0, 5.2, 4.8, 4.5, 4.3, 4.6, 5.1, 6.0, 7.2, 8.5, + 9.0, 10.2, 11.0, 10.5, 10.0, 9.2, 8.0, 6.5, 5.5, 5.0, 4.8, 4.5, 5.0, 5.2 + ]; + return FlSpot(i.toDouble(), values[i]); + }); + case "Minggu Ini": + return [ + const FlSpot(0, 6.5), + const FlSpot(1, 7.2), + const FlSpot(2, 7.8), + const FlSpot(3, 8.0), + const FlSpot(4, 7.5), + const FlSpot(5, 6.8), + const FlSpot(6, 5.5), + ]; + case "Bulan Ini": + return [ + const FlSpot(0, 6.0), + const FlSpot(1, 6.5), + const FlSpot(2, 7.0), + const FlSpot(3, 7.5), + const FlSpot(4, 7.8), + const FlSpot(5, 8.0), + const FlSpot(6, 8.2), + const FlSpot(7, 8.0), + const FlSpot(8, 7.5), + const FlSpot(9, 7.0), + const FlSpot(10, 6.5), + const FlSpot(11, 6.0), + ]; + default: + return []; + } + } + + /// UI BUILDERS + Widget _buildMonitoringGraphBlock() { + return Card( + elevation: 4, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + "Status Kecepatan Angin", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 5, + ), + decoration: BoxDecoration( + color: Colors.amber.shade100, + borderRadius: BorderRadius.circular(20), + ), + child: const Text( + "Normal", + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.w600, + color: Colors.amber, + ), + ), + ), + ], + ), + const SizedBox(height: 16), + + /// PERIOD SELECTOR + EXPORT + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { + return Padding( + padding: const EdgeInsets.only(right: 8), + child: ChoiceChip( + label: Text(period), + selected: _selectedPeriod == period, + onSelected: (selected) { + setState(() { + _selectedPeriod = period; + }); + }, + selectedColor: Colors.green, + labelStyle: TextStyle( + color: _selectedPeriod == period + ? Colors.white + : Colors.black, + ), + ), + ); + }).toList(), + ), + ), + ), + const SizedBox(width: 8), + ElevatedButton.icon( + onPressed: () { + if (_selectedPeriod == "Hari Ini") { + _exportDailyWindData(); + } else if (_selectedPeriod == "Minggu Ini") { + _exportWeeklyWindData(); + } else if (_selectedPeriod == "Bulan Ini") { + _exportMonthlyWindData(); + } + }, + icon: const Icon(Icons.download, size: 16), + label: const Text("Export"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.orange, + foregroundColor: Colors.white, + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 6, + ), + textStyle: const TextStyle(fontSize: 11), + ), + ), + ], + ), + const SizedBox(height: 16), + + /// GRAPH + SizedBox( + height: 300, + child: LineChart( + LineChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 1, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.shade300, + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: getPeriodInterval(_selectedPeriod), + getTitlesWidget: (value, meta) { + return Text( + getPeriodLabel(_selectedPeriod, value), + style: const TextStyle( + fontSize: 10, + color: Colors.grey, + ), + ); + }, + ), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: 1, + getTitlesWidget: (value, meta) { + return Text( + value.toInt().toString(), + style: const TextStyle( + fontSize: 9, + color: Colors.grey, + ), + ); + }, + reservedSize: 28, + ), + ), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + lineBarsData: [ + LineChartBarData( + spots: _getWindSpeedPeriodData(), + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.green, + strokeWidth: 0, + ); + }, + ), + color: Colors.green, + belowBarData: BarAreaData( + show: true, + color: Colors.green.withOpacity(0.1), + ), + ), + ], + ), + ), + ), + ], + ), + ), + ); + } + + Widget _buildWindSpeedExplanation() { + return Container( + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.green.shade50, + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.green.shade200), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Penjelasan Kecepatan Angin", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, + color: Colors.green, + ), + ), + const SizedBox(height: 10), + const Text( + "Kecepatan angin adalah laju gerakan massa udara yang mengalir secara horizontal. Data kecepatan angin penting untuk prediksi cuaca, manajemen rawan angin, perencanaan energi terbarukan (angin), serta membantu dalam pengeringan hasil pertanian. Pengukuran dilakukan dalam satuan km/h.", + style: TextStyle( + fontSize: 12, + height: 1.6, + color: Colors.green, + ), + ), + ], + ), + ); + } + + Widget _buildAnnualWindGraphSection() { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Statistik Tahunan Kecepatan Angin", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 15), + + /// STATS + Row( + children: [ + Expanded( + child: StatCard( + title: "Rata-rata Tahunan", + value: "7.1 km/h", + color: Colors.green, + icon: Icons.air, + ), + ), + const SizedBox(width: 10), + Expanded( + child: StatCard( + title: "Kecepatan Max", + value: "16.5 km/h", + color: Colors.red, + icon: Icons.trending_up, + ), + ), + ], + ), + const SizedBox(height: 20), + + /// CHART + const Text( + "Grafik Tahunan - Rata-rata & Kecepatan Maksimal", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + ), + ), + const SizedBox(height: 12), + Card( + elevation: 3, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: SizedBox( + height: 320, + child: LineChart( + LineChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 2, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.shade300, + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + getTitlesWidget: (value, meta) { + final months = [ + 'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', + 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des' + ]; + return Text( + months[value.toInt()], + style: const TextStyle( + fontSize: 10, + color: Colors.grey, + ), + ); + }, + reservedSize: 30, + ), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + getTitlesWidget: (value, meta) { + return Text( + '${value.toInt()} km/h', + style: const TextStyle( + fontSize: 9, + color: Colors.grey, + ), + ); + }, + reservedSize: 50, + ), + ), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + lineBarsData: [ + /// Rata-rata + LineChartBarData( + spots: const [ + FlSpot(0, 5.5), + FlSpot(1, 6.2), + FlSpot(2, 6.8), + FlSpot(3, 7.5), + FlSpot(4, 7.8), + FlSpot(5, 8.0), + FlSpot(6, 8.2), + FlSpot(7, 8.0), + FlSpot(8, 7.2), + FlSpot(9, 6.5), + FlSpot(10, 5.8), + FlSpot(11, 5.2), + ], + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.green, + strokeWidth: 0, + ); + }, + ), + color: Colors.green, + belowBarData: BarAreaData( + show: true, + color: Colors.green.withOpacity(0.1), + ), + ), + /// Max Speed + LineChartBarData( + spots: const [ + FlSpot(0, 12.0), + FlSpot(1, 13.5), + FlSpot(2, 14.0), + FlSpot(3, 15.5), + FlSpot(4, 16.0), + FlSpot(5, 16.2), + FlSpot(6, 16.5), + FlSpot(7, 16.0), + FlSpot(8, 15.0), + FlSpot(9, 14.0), + FlSpot(10, 12.5), + FlSpot(11, 11.0), + ], + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.red, + strokeWidth: 0, + ); + }, + ), + color: Colors.red, + ), + ], + ), + ), + ), + ), + ), + const SizedBox(height: 15), + + /// LEGEND + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.green, + borderRadius: BorderRadius.circular(3), + ), + ), + const SizedBox(width: 8), + const Text( + "Rata-rata (km/h)", + style: TextStyle(fontSize: 12), + ), + const SizedBox(width: 20), + Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(3), + ), + ), + const SizedBox(width: 8), + const Text( + "Kecepatan Max (km/h)", + style: TextStyle(fontSize: 12), + ), + ], + ), + const SizedBox(height: 15), + Center( + child: ElevatedButton.icon( + onPressed: () => _exportAnnualWindData(), + icon: const Icon(Icons.file_download), + label: const Text("Download Excel Tahunan"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.green, + foregroundColor: Colors.white, + ), + ), + ), + ], + ); + } +} diff --git a/packages/user_repository/pubspec.lock b/packages/user_repository/pubspec.lock index 3185b3d..6260b95 100644 --- a/packages/user_repository/pubspec.lock +++ b/packages/user_repository/pubspec.lock @@ -5,10 +5,10 @@ packages: dependency: transitive description: name: _flutterfire_internals - sha256: "37a42d06068e2fe3deddb2da079a8c4d105f241225ba27b7122b37e9865fd8f7" + sha256: cd83f7d6bd4e4c0b0b4fef802e8796784032e1cc23d7b0e982cf5d05d9bbe182 url: "https://pub.dev" source: hosted - version: "1.3.35" + version: "1.3.66" async: dependency: transitive description: @@ -45,26 +45,26 @@ packages: dependency: "direct main" description: name: cloud_firestore - sha256: a0f161b92610e078b4962d7e6ebeb66dc9cce0ada3514aeee442f68165d78185 + sha256: "54484b2fc49f41b46f35b60a54b12351181eeaad22c0e3def276a81e17ae7c9b" url: "https://pub.dev" source: hosted - version: "4.17.5" + version: "6.1.2" cloud_firestore_platform_interface: dependency: transitive description: name: cloud_firestore_platform_interface - sha256: "6a55b319f8d33c307396b9104512e8130a61904528ab7bd8b5402678fca54b81" + sha256: dfaa8b2c0d0a824af289d4159816a5c78417feec264c2194081d645687195158 url: "https://pub.dev" source: hosted - version: "6.2.5" + version: "7.0.6" cloud_firestore_web: dependency: transitive description: name: cloud_firestore_web - sha256: "89dfa1304d3da48b3039abbb2865e3d30896ef858e569a16804a99f4362283a9" + sha256: "35d01f502b3b701d700470d32a8f82704dac8341a66e86c074900cde5bab343d" url: "https://pub.dev" source: hosted - version: "3.12.5" + version: "5.1.2" collection: dependency: transitive description: @@ -85,50 +85,50 @@ packages: dependency: "direct main" description: name: firebase_auth - sha256: cfc2d970829202eca09e2896f0a5aa7c87302817ecc0bdfa954f026046bf10ba + sha256: b20d1540460814c5984474c1e9dd833bdbcff6ecd8d6ad86cc9da8cfd581c172 url: "https://pub.dev" source: hosted - version: "4.20.0" + version: "6.1.4" firebase_auth_platform_interface: dependency: transitive description: name: firebase_auth_platform_interface - sha256: a0270e1db3b2098a14cb2a2342b3cd2e7e458e0c391b1f64f6f78b14296ec093 + sha256: fd0225320b6bbc92460c86352d16b60aea15f9ef88292774cca97b0522ea9f72 url: "https://pub.dev" source: hosted - version: "7.3.0" + version: "8.1.6" firebase_auth_web: dependency: transitive description: name: firebase_auth_web - sha256: "64e067e763c6378b7e774e872f0f59f6812885e43020e25cde08f42e9459837b" + sha256: be7dccb263b89fbda2a564de9d8193118196e8481ffb937222a025cdfdf82c40 url: "https://pub.dev" source: hosted - version: "5.12.0" + version: "6.1.2" firebase_core: dependency: transitive description: name: firebase_core - sha256: "26de145bb9688a90962faec6f838247377b0b0d32cc0abecd9a4e43525fc856c" + sha256: "923085c881663ef685269b013e241b428e1fb03cdd0ebde265d9b40ff18abf80" url: "https://pub.dev" source: hosted - version: "2.32.0" + version: "4.4.0" firebase_core_platform_interface: dependency: transitive description: name: firebase_core_platform_interface - sha256: "8bcfad6d7033f5ea951d15b867622a824b13812178bfec0c779b9d81de011bbb" + sha256: cccb4f572325dc14904c02fcc7db6323ad62ba02536833dddb5c02cac7341c64 url: "https://pub.dev" source: hosted - version: "5.4.2" + version: "6.0.2" firebase_core_web: dependency: transitive description: name: firebase_core_web - sha256: "362e52457ed2b7b180964769c1e04d1e0ea0259fdf7025fdfedd019d4ae2bd88" + sha256: "83e7356c704131ca4d8d8dd57e360d8acecbca38b1a3705c7ae46cc34c708084" url: "https://pub.dev" source: hosted - version: "2.17.5" + version: "3.4.0" flutter: dependency: "direct main" description: flutter @@ -138,10 +138,10 @@ packages: dependency: "direct dev" description: name: flutter_lints - sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04 + sha256: "9e8c3858111da373efc5aa341de011d9bd23e2c5c5e0c62bccf32438e192d7b1" url: "https://pub.dev" source: hosted - version: "2.0.3" + version: "3.0.2" flutter_test: dependency: "direct dev" description: flutter @@ -152,6 +152,14 @@ packages: description: flutter source: sdk version: "0.0.0" + http: + dependency: transitive + description: + name: http + sha256: "87721a4a50b19c7f1d49001e51409bddc46303966ce89a65af4f4e6004896412" + url: "https://pub.dev" + source: hosted + version: "1.6.0" http_parser: dependency: transitive description: @@ -188,10 +196,10 @@ packages: dependency: transitive description: name: lints - sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" + sha256: cbf8d4b858bb0134ef3ef87841abdf8d63bfc255c266b7bf6b39daa1085c4290 url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "3.0.0" matcher: dependency: transitive description: @@ -321,10 +329,10 @@ packages: dependency: transitive description: name: web - sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "1.1.1" sdks: dart: ">=3.8.0-0 <4.0.0" - flutter: ">=3.18.0-18.0.pre.54" + flutter: ">=3.22.0" diff --git a/pubspec.lock b/pubspec.lock index 3b75fe1..7c518d0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -153,6 +153,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.3.1" + fl_chart: + dependency: "direct main" + description: + name: fl_chart + sha256: "00b74ae680df6b1135bdbea00a7d1fc072a9180b7c3f3702e4b19a9943f5ed7d" + url: "https://pub.dev" + source: hosted + version: "0.66.2" flutter: dependency: "direct main" description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index 81e0163..f82e774 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,6 +7,11 @@ environment: dependencies: flutter: sdk: flutter +<<<<<<< Updated upstream +======= + fl_chart: ^0.66.0 + +>>>>>>> Stashed changes firebase_core: ^4.3.0 firebase_auth: ^6.1.3 cloud_firestore: ^6.1.1 From 6cd91f6bb0e8338a133e7e58da384191e67a0949 Mon Sep 17 00:00:00 2001 From: e32232340-Nadif Date: Sat, 14 Feb 2026 19:26:56 +0700 Subject: [PATCH 02/28] branch percobaan --- lib/main.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index 24a3171..540ef62 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,4 +13,6 @@ void main() async { ); Bloc.observer = SimpleBlocObserver(); runApp(MyApp(FirebaseUserRepo())); -} \ No newline at end of file +} + +// bentar ada yang ilang branch nya anjay \ No newline at end of file From def3130903977fe0f691cdd26034cc4d25232748 Mon Sep 17 00:00:00 2001 From: e32232340-Nadif Date: Sat, 14 Feb 2026 19:49:33 +0700 Subject: [PATCH 03/28] ok --- lib/main.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index 540ef62..574b2cf 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -15,4 +15,4 @@ void main() async { runApp(MyApp(FirebaseUserRepo())); } -// bentar ada yang ilang branch nya anjay \ No newline at end of file +// bentar ada yang ilang branch nya anjay dsnaidaodasd \ No newline at end of file From 837ed64e63d0b4ee71aaef0bf170ca14cdcc70ea Mon Sep 17 00:00:00 2001 From: e32232340-Nadif Date: Sat, 14 Feb 2026 19:50:45 +0700 Subject: [PATCH 04/28] Update main.dart --- lib/main.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 574b2cf..24a3171 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,6 +13,4 @@ void main() async { ); Bloc.observer = SimpleBlocObserver(); runApp(MyApp(FirebaseUserRepo())); -} - -// bentar ada yang ilang branch nya anjay dsnaidaodasd \ No newline at end of file +} \ No newline at end of file From 105e2c52d062e1cd73765f39b2285c72cc207a1f Mon Sep 17 00:00:00 2001 From: e32232340-Nadif Date: Sat, 14 Feb 2026 20:51:22 +0700 Subject: [PATCH 05/28] oke masih dari sign_up ke home_screen --- lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart | 2 +- .../auth/blocs/sign_up_bloc/sign_up_state.dart | 11 +++++++++-- lib/screens/auth/views/sign_up_screen.dart | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart b/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart index a61bf58..d113b93 100644 --- a/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart +++ b/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart @@ -16,7 +16,7 @@ class SignUpBloc extends Bloc { await _userRepository.setUserData(myUser); emit(SignUpSuccess()); } catch (e) { - emit(SignUpFailure()); + emit(SignUpFailure(e.toString())); } }); } diff --git a/lib/screens/auth/blocs/sign_up_bloc/sign_up_state.dart b/lib/screens/auth/blocs/sign_up_bloc/sign_up_state.dart index 536f3a9..9f22066 100644 --- a/lib/screens/auth/blocs/sign_up_bloc/sign_up_state.dart +++ b/lib/screens/auth/blocs/sign_up_bloc/sign_up_state.dart @@ -4,11 +4,18 @@ sealed class SignUpState extends Equatable { const SignUpState(); @override - List get props => []; + List get props => []; } final class SignUpInitial extends SignUpState {} final class SignUpSuccess extends SignUpState {} -final class SignUpFailure extends SignUpState {} +final class SignUpFailure extends SignUpState { + final String? message; + const SignUpFailure([this.message]); + + @override + List get props => [message]; +} + final class SignUpProcess extends SignUpState {} \ No newline at end of file diff --git a/lib/screens/auth/views/sign_up_screen.dart b/lib/screens/auth/views/sign_up_screen.dart index 16bd54c..21a71e0 100644 --- a/lib/screens/auth/views/sign_up_screen.dart +++ b/lib/screens/auth/views/sign_up_screen.dart @@ -49,8 +49,9 @@ class _SignUpScreenState extends State { setState(() { signUpRequired = false; }); + final message = (state as SignUpFailure).message ?? 'Registrasi gagal, silakan coba lagi'; ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Registrasi gagal, silakan coba lagi')), + SnackBar(content: Text(message)), ); } }, From 783e623619a23b2d24b7271c1f33eb5c40b53fdf Mon Sep 17 00:00:00 2001 From: Mochamad ongki ramadani Date: Sat, 14 Feb 2026 21:01:55 +0700 Subject: [PATCH 06/28] dari gua --- lib/app_view.dart | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/app_view.dart b/lib/app_view.dart index 60dc938..8d576c4 100644 --- a/lib/app_view.dart +++ b/lib/app_view.dart @@ -20,15 +20,16 @@ class MyAppView extends StatelessWidget { onPrimary: Colors.white ), ), - home: BlocBuilder( - builder: ((context, state){ - if(state.status == AuthenticationStatus.authenticated){ - return HomeScreen(); - } else { - return WelcomeScreen(); - } - }), - ) + home: HomeScreen() + // home: BlocBuilder( + // builder: ((context, state){ + // if(state.status == AuthenticationStatus.authenticated){ + // return HomeScreen(); + // } else { + // return WelcomeScreen(); + // } + // }), + // ) ); } } \ No newline at end of file From d6dd976a69484e7ed53ddb673b2c318236310e0f Mon Sep 17 00:00:00 2001 From: e32232340-Nadif Date: Sat, 14 Feb 2026 23:18:40 +0700 Subject: [PATCH 07/28] oke jadi coba --- lib/app_view.dart | 26 +++++++++---------- lib/screens/auth/views/sign_up_screen.dart | 13 +--------- lib/screens/home/{ => views}/home_screen.dart | 6 ++--- pubspec.lock | 4 +-- pubspec.yaml | 7 ++--- 5 files changed, 21 insertions(+), 35 deletions(-) rename lib/screens/home/{ => views}/home_screen.dart (98%) diff --git a/lib/app_view.dart b/lib/app_view.dart index 8d576c4..3fd5d03 100644 --- a/lib/app_view.dart +++ b/lib/app_view.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; -// import 'package:flutter_bloc/flutter_bloc.dart'; -// import 'package:klimatologiot/blocs/authentication_bloc/authentication_bloc.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:klimatologiot/blocs/authentication_bloc/authentication_bloc.dart'; -import 'package:klimatologiot/screens/home/home_screen.dart'; +import 'package:klimatologiot/screens/auth/views/welcome_screen.dart'; +import 'package:klimatologiot/screens/home/views/home_screen.dart'; class MyAppView extends StatelessWidget { const MyAppView({super.key}); @@ -20,16 +21,15 @@ class MyAppView extends StatelessWidget { onPrimary: Colors.white ), ), - home: HomeScreen() - // home: BlocBuilder( - // builder: ((context, state){ - // if(state.status == AuthenticationStatus.authenticated){ - // return HomeScreen(); - // } else { - // return WelcomeScreen(); - // } - // }), - // ) + home: BlocBuilder( + builder: ((context, state){ + if(state.status == AuthenticationStatus.authenticated){ + return HomeScreen(); + } else { + return WelcomeScreen(); + } + }), + ) ); } } \ No newline at end of file diff --git a/lib/screens/auth/views/sign_up_screen.dart b/lib/screens/auth/views/sign_up_screen.dart index 21a71e0..70c9b31 100644 --- a/lib/screens/auth/views/sign_up_screen.dart +++ b/lib/screens/auth/views/sign_up_screen.dart @@ -36,23 +36,12 @@ class _SignUpScreenState extends State { setState(() { signUpRequired = false; }); - // User sudah terdaftar dan auth state akan otomatis update via AuthenticationBloc - // Tungur sebentar agar Firestore selesai menyimpan data - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Registrasi berhasil! Mengarahkan...')), - ); } else if (state is SignUpProcess) { setState(() { signUpRequired = true; }); } else if (state is SignUpFailure) { - setState(() { - signUpRequired = false; - }); - final message = (state as SignUpFailure).message ?? 'Registrasi gagal, silakan coba lagi'; - ScaffoldMessenger.of(context).showSnackBar( - SnackBar(content: Text(message)), - ); + return; } }, child: Form( diff --git a/lib/screens/home/home_screen.dart b/lib/screens/home/views/home_screen.dart similarity index 98% rename from lib/screens/home/home_screen.dart rename to lib/screens/home/views/home_screen.dart index 4bb2f06..8a9f75e 100644 --- a/lib/screens/home/home_screen.dart +++ b/lib/screens/home/views/home_screen.dart @@ -1,8 +1,8 @@ import 'package:flutter/material.dart'; import 'package:fl_chart/fl_chart.dart'; -import '../monitoring/evaporasi_monitoring_screen.dart'; -import '../monitoring/wind_speed_monitoring_screen.dart'; -import '../monitoring/air_quality_monitoring_screen.dart'; +import '../../monitoring/evaporasi_monitoring_screen.dart'; +import '../../monitoring/wind_speed_monitoring_screen.dart'; +import '../../monitoring/air_quality_monitoring_screen.dart'; class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); diff --git a/pubspec.lock b/pubspec.lock index 7c518d0..bce6ad9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -157,10 +157,10 @@ packages: dependency: "direct main" description: name: fl_chart - sha256: "00b74ae680df6b1135bdbea00a7d1fc072a9180b7c3f3702e4b19a9943f5ed7d" + sha256: "7ca9a40f4eb85949190e54087be8b4d6ac09dc4c54238d782a34cf1f7c011de9" url: "https://pub.dev" source: hosted - version: "0.66.2" + version: "1.1.1" flutter: dependency: "direct main" description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index f82e774..8b9171e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -7,11 +7,6 @@ environment: dependencies: flutter: sdk: flutter -<<<<<<< Updated upstream -======= - fl_chart: ^0.66.0 - ->>>>>>> Stashed changes firebase_core: ^4.3.0 firebase_auth: ^6.1.3 cloud_firestore: ^6.1.1 @@ -23,6 +18,8 @@ dependencies: user_repository: path: packages/user_repository cupertino_icons: ^1.0.8 + fl_chart: ^1.1.1 + dev_dependencies: flutter_test: sdk: flutter From c07c4e97b9fb858f2cba92ed622312a7b69bb1a2 Mon Sep 17 00:00:00 2001 From: Mochamad ongki ramadani Date: Tue, 17 Feb 2026 15:48:32 +0700 Subject: [PATCH 08/28] iki ada ucapan selamat datang --- .../authentication_bloc.dart | 7 ++ .../authentication_event.dart | 4 + lib/screens/home/views/home_screen.dart | 81 +++++++++++++------ 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/lib/blocs/authentication_bloc/authentication_bloc.dart b/lib/blocs/authentication_bloc/authentication_bloc.dart index 74d02c6..7929c1e 100644 --- a/lib/blocs/authentication_bloc/authentication_bloc.dart +++ b/lib/blocs/authentication_bloc/authentication_bloc.dart @@ -26,6 +26,13 @@ class AuthenticationBloc extends Bloc emit(AuthenticationState.unauthenticated()); } }); + on((event, emit) async { + try { + await userRepository.logOut(); + } catch (_) { + // ignore errors here; stream will update state accordingly + } + }); } @override Future close() { diff --git a/lib/blocs/authentication_bloc/authentication_event.dart b/lib/blocs/authentication_bloc/authentication_event.dart index 1b96112..6972fc6 100644 --- a/lib/blocs/authentication_bloc/authentication_event.dart +++ b/lib/blocs/authentication_bloc/authentication_event.dart @@ -11,4 +11,8 @@ class AuthenticationUserChanged extends AuthenticationEvent { final MyUser? user; const AuthenticationUserChanged(this.user); +} + +class AuthenticationLogoutRequested extends AuthenticationEvent { + const AuthenticationLogoutRequested(); } \ No newline at end of file diff --git a/lib/screens/home/views/home_screen.dart b/lib/screens/home/views/home_screen.dart index 8a9f75e..b7a85e1 100644 --- a/lib/screens/home/views/home_screen.dart +++ b/lib/screens/home/views/home_screen.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:fl_chart/fl_chart.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import '../../../blocs/authentication_bloc/authentication_bloc.dart'; import '../../monitoring/evaporasi_monitoring_screen.dart'; import '../../monitoring/wind_speed_monitoring_screen.dart'; import '../../monitoring/air_quality_monitoring_screen.dart'; @@ -21,24 +23,39 @@ class HomeScreen extends StatelessWidget { child: ListView( padding: EdgeInsets.zero, children: [ - // 🔹 HEADER DENGAN AKUN INFO - UserAccountsDrawerHeader( - accountName: const Text( - "Admin Klimatologi", - style: TextStyle(fontWeight: FontWeight.bold), - ), - accountEmail: const Text("admin@klimatologi.com"), - currentAccountPicture: CircleAvatar( - backgroundColor: Colors.blue, - child: const Text( - "A", - style: TextStyle( - fontSize: 24, - fontWeight: FontWeight.bold, - color: Colors.white, + // 🔹 HEADER DENGAN AKUN INFO (dynamic dari AuthenticationBloc) + BlocBuilder( + builder: (context, state) { + final user = state.user; + final displayName = (user != null && user.name.isNotEmpty) + ? user.name + : 'Pengguna'; + final email = (user != null && user.email.isNotEmpty) + ? user.email + : 'Tidak ada email'; + final initials = (displayName.isNotEmpty) + ? displayName.trim().split(' ').map((e) => e.isNotEmpty ? e[0] : '').take(2).join() + : 'U'; + + return UserAccountsDrawerHeader( + accountName: Text( + displayName, + style: const TextStyle(fontWeight: FontWeight.bold), ), - ), - ), + accountEmail: Text(email), + currentAccountPicture: CircleAvatar( + backgroundColor: Colors.blue, + child: Text( + initials.toUpperCase(), + style: const TextStyle( + fontSize: 24, + fontWeight: FontWeight.bold, + color: Colors.white, + ), + ), + ), + ); + }, ), // 🔹 DASHBOARD MENU @@ -80,6 +97,17 @@ class HomeScreen extends StatelessWidget { "Kualitas Udara", Icons.cloud, ), + const Divider(), + ListTile( + leading: const Icon(Icons.logout), + title: const Text('Logout'), + onTap: () async { + Navigator.pop(context); + // trigger logout via bloc + final bloc = context.read(); + bloc.add(const AuthenticationLogoutRequested()); + }, + ), ], ), ), @@ -92,12 +120,19 @@ class HomeScreen extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Text( - "Selamat Datang Admin Klimatologi", - style: TextStyle( - fontSize: 22, - fontWeight: FontWeight.bold, - ), + BlocBuilder( + builder: (context, state) { + final name = state.user?.name.isNotEmpty == true + ? state.user!.name + : 'Pengguna'; + return Text( + 'Selamat Datang $name', + style: const TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + ), + ); + }, ), const SizedBox(height: 20), From 739616275c66719f4466a9b09138d9d5fbe3ed0e Mon Sep 17 00:00:00 2001 From: e32232340-Nadif <158453666+kleponijo@users.noreply.github.com> Date: Sun, 1 Mar 2026 19:05:49 +0700 Subject: [PATCH 09/28] pembaruan backend data --- .../wind_speed_monitoring_screen.dart | 46 ++++++++++++++++--- macos/Flutter/GeneratedPluginRegistrant.swift | 2 + pubspec.lock | 36 ++++++++++++--- pubspec.yaml | 2 + 4 files changed, 73 insertions(+), 13 deletions(-) diff --git a/lib/screens/monitoring/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed_monitoring_screen.dart index f56b33f..eb7ecf5 100644 --- a/lib/screens/monitoring/wind_speed_monitoring_screen.dart +++ b/lib/screens/monitoring/wind_speed_monitoring_screen.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:fl_chart/fl_chart.dart'; +import 'package:firebase_database/firebase_database.dart'; +import 'dart:async'; import 'widgets/monitoring_shared.dart'; /// WIND SPEED MONITORING SCREEN @@ -13,9 +15,41 @@ class WindSpeedMonitoringScreen extends StatefulWidget { class _WindSpeedMonitoringScreenState extends State { String _selectedPeriod = "Hari Ini"; + // realtime database state + final DatabaseReference _realtimeRef = FirebaseDatabase.instance.ref('anemometer/realtime'); + StreamSubscription? _realtimeSub; + double _currentSpeed = 0.0; + List _dailySpeeds = List.filled(24, 0.0); + + + @override + void initState() { + super.initState(); + _realtimeSub = _realtimeRef.onValue.listen(_onRealtimeData); + } + + void _onRealtimeData(DatabaseEvent event) { + final data = event.snapshot.value; + if (data is Map) { + final speed = (data['kecepatan'] ?? 0).toDouble(); + setState(() { + _currentSpeed = speed; + // shift hourly data, keep latest at end + _dailySpeeds.removeAt(0); + _dailySpeeds.add(speed); + }); + } + } + + @override + void dispose() { + _realtimeSub?.cancel(); + super.dispose(); + } + @override Widget build(BuildContext context) { - return Scaffold( + return Scaffold, appBar: AppBar( title: const Text("Monitoring Kecepatan Angin"), centerTitle: true, @@ -155,12 +189,10 @@ class _WindSpeedMonitoringScreenState extends State { List _getWindSpeedPeriodData() { switch (_selectedPeriod) { case "Hari Ini": + // use live-updated hourly speeds if available return List.generate(24, (i) { - final values = [ - 5.0, 5.2, 4.8, 4.5, 4.3, 4.6, 5.1, 6.0, 7.2, 8.5, - 9.0, 10.2, 11.0, 10.5, 10.0, 9.2, 8.0, 6.5, 5.5, 5.0, 4.8, 4.5, 5.0, 5.2 - ]; - return FlSpot(i.toDouble(), values[i]); + final value = _dailySpeeds[i]; + return FlSpot(i.toDouble(), value); }); case "Minggu Ini": return [ @@ -366,7 +398,7 @@ class _WindSpeedMonitoringScreenState extends State { ), lineBarsData: [ LineChartBarData( - spots: _getWindSpeedPeriodData(), + spots: _getWindSpeedPeriodData(), // uses _dailySpeeds now isCurved: true, barWidth: 2.5, dotData: FlDotData( diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 00d0898..608950e 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -8,11 +8,13 @@ import Foundation import cloud_firestore import firebase_auth import firebase_core +import firebase_database import google_sign_in_ios func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseFirestorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseFirestorePlugin")) FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin")) FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) + FLTFirebaseDatabasePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseDatabasePlugin")) FLTGoogleSignInPlugin.register(with: registry.registrar(forPlugin: "FLTGoogleSignInPlugin")) } diff --git a/pubspec.lock b/pubspec.lock index bce6ad9..7d18d73 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -5,10 +5,10 @@ packages: dependency: transitive description: name: _flutterfire_internals - sha256: e4a1b612fd2955908e26116075b3a4baf10c353418ca645b4deae231c82bf144 + sha256: cd83f7d6bd4e4c0b0b4fef802e8796784032e1cc23d7b0e982cf5d05d9bbe182 url: "https://pub.dev" source: hosted - version: "1.3.65" + version: "1.3.66" async: dependency: transitive description: @@ -133,10 +133,10 @@ packages: dependency: "direct main" description: name: firebase_core - sha256: "29cfa93c771d8105484acac340b5ea0835be371672c91405a300303986f4eba9" + sha256: "923085c881663ef685269b013e241b428e1fb03cdd0ebde265d9b40ff18abf80" url: "https://pub.dev" source: hosted - version: "4.3.0" + version: "4.4.0" firebase_core_platform_interface: dependency: transitive description: @@ -149,10 +149,34 @@ packages: dependency: transitive description: name: firebase_core_web - sha256: a631bbfbfa26963d68046aed949df80b228964020e9155b086eff94f462bbf1f + sha256: "83e7356c704131ca4d8d8dd57e360d8acecbca38b1a3705c7ae46cc34c708084" url: "https://pub.dev" source: hosted - version: "3.3.1" + version: "3.4.0" + firebase_database: + dependency: "direct main" + description: + name: firebase_database + sha256: f13676fab84671a808eb5eaeecfa2bcb5a3fed2802798c0dd16cb786139a6492 + url: "https://pub.dev" + source: hosted + version: "12.1.3" + firebase_database_platform_interface: + dependency: transitive + description: + name: firebase_database_platform_interface + sha256: "2444ec9999a7295b0e7f3fea60105dbbe72fdfad5a9e4c93e72d0b51c181f128" + url: "https://pub.dev" + source: hosted + version: "0.3.0+2" + firebase_database_web: + dependency: transitive + description: + name: firebase_database_web + sha256: "211b6deff7ac373bb539f079d909799e9231397daddc9e0f1768f50f6216f034" + url: "https://pub.dev" + source: hosted + version: "0.2.7+3" fl_chart: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 8b9171e..6660d29 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,6 +9,7 @@ dependencies: sdk: flutter firebase_core: ^4.3.0 firebase_auth: ^6.1.3 + firebase_database: ^10.0.6 cloud_firestore: ^6.1.1 rxdart: ^0.27.7 google_sign_in: ^7.2.0 @@ -19,6 +20,7 @@ dependencies: path: packages/user_repository cupertino_icons: ^1.0.8 fl_chart: ^1.1.1 + firebase_database: ^12.1.3 dev_dependencies: flutter_test: From d5f7e3bc7b712d68a9acd8a551df9b6d6c3a31ca Mon Sep 17 00:00:00 2001 From: e32232340-Nadif <158453666+kleponijo@users.noreply.github.com> Date: Sun, 1 Mar 2026 19:31:54 +0700 Subject: [PATCH 10/28] ds --- lib/screens/monitoring/wind_speed_monitoring_screen.dart | 8 ++++---- pubspec.yaml | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/screens/monitoring/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed_monitoring_screen.dart index eb7ecf5..e705988 100644 --- a/lib/screens/monitoring/wind_speed_monitoring_screen.dart +++ b/lib/screens/monitoring/wind_speed_monitoring_screen.dart @@ -18,8 +18,9 @@ class _WindSpeedMonitoringScreenState extends State { // realtime database state final DatabaseReference _realtimeRef = FirebaseDatabase.instance.ref('anemometer/realtime'); StreamSubscription? _realtimeSub; - double _currentSpeed = 0.0; - List _dailySpeeds = List.filled(24, 0.0); + // current speed kept for future display if needed + // double _currentSpeed = 0.0; + final List _dailySpeeds = List.filled(24, 0.0); @override @@ -33,7 +34,6 @@ class _WindSpeedMonitoringScreenState extends State { if (data is Map) { final speed = (data['kecepatan'] ?? 0).toDouble(); setState(() { - _currentSpeed = speed; // shift hourly data, keep latest at end _dailySpeeds.removeAt(0); _dailySpeeds.add(speed); @@ -49,7 +49,7 @@ class _WindSpeedMonitoringScreenState extends State { @override Widget build(BuildContext context) { - return Scaffold, + return Scaffold( appBar: AppBar( title: const Text("Monitoring Kecepatan Angin"), centerTitle: true, diff --git a/pubspec.yaml b/pubspec.yaml index 6660d29..00cde00 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -9,7 +9,6 @@ dependencies: sdk: flutter firebase_core: ^4.3.0 firebase_auth: ^6.1.3 - firebase_database: ^10.0.6 cloud_firestore: ^6.1.1 rxdart: ^0.27.7 google_sign_in: ^7.2.0 From 692244f59cdde02569ea9aefa6bcdd03b0a5a7bf Mon Sep 17 00:00:00 2001 From: e32232340-Nadif <158453666+kleponijo@users.noreply.github.com> Date: Sun, 1 Mar 2026 19:59:18 +0700 Subject: [PATCH 11/28] jack --- .../wind_speed_monitoring_screen.dart | 82 ++++++++++++++++++- pubspec.lock | 8 ++ pubspec.yaml | 1 + 3 files changed, 87 insertions(+), 4 deletions(-) diff --git a/lib/screens/monitoring/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed_monitoring_screen.dart index e705988..4e32b88 100644 --- a/lib/screens/monitoring/wind_speed_monitoring_screen.dart +++ b/lib/screens/monitoring/wind_speed_monitoring_screen.dart @@ -3,6 +3,7 @@ import 'package:fl_chart/fl_chart.dart'; import 'package:firebase_database/firebase_database.dart'; import 'dart:async'; import 'widgets/monitoring_shared.dart'; +import 'package:intl/intl.dart'; /// WIND SPEED MONITORING SCREEN class WindSpeedMonitoringScreen extends StatefulWidget { @@ -18,10 +19,18 @@ class _WindSpeedMonitoringScreenState extends State { // realtime database state final DatabaseReference _realtimeRef = FirebaseDatabase.instance.ref('anemometer/realtime'); StreamSubscription? _realtimeSub; - // current speed kept for future display if needed - // double _currentSpeed = 0.0; + + // realtime values + DateTime? _lastUpdateTime; + double _currentSpeed = 0.0; final List _dailySpeeds = List.filled(24, 0.0); + bool get _isOnline { + if (_lastUpdateTime == null) return false; + final diff = DateTime.now().difference(_lastUpdateTime!); + return diff.inSeconds <= 5; + } + @override void initState() { @@ -31,10 +40,19 @@ class _WindSpeedMonitoringScreenState extends State { void _onRealtimeData(DatabaseEvent event) { final data = event.snapshot.value; + if (data is Map) { final speed = (data['kecepatan'] ?? 0).toDouble(); + final timestamp = data['timestamp'] ?? 0; + + final waktu = DateTime.fromMillisecondsSinceEpoch( + timestamp * 1000, + ); + setState(() { - // shift hourly data, keep latest at end + _currentSpeed = speed; + _lastUpdateTime = waktu; + _dailySpeeds.removeAt(0); _dailySpeeds.add(speed); }); @@ -68,7 +86,63 @@ class _WindSpeedMonitoringScreenState extends State { ), ), const SizedBox(height: 20), - + if (_lastUpdateTime != null) + Padding( + padding: const EdgeInsets.only(bottom: 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "${_currentSpeed.toStringAsFixed(2)} km/h", + style: const TextStyle( + fontSize: 28, + fontWeight: FontWeight.bold, + color: Colors.green, + ), + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 5, + ), + decoration: BoxDecoration( + color: _isOnline + ? Colors.green.shade100 + : Colors.red.shade100, + borderRadius: BorderRadius.circular(20), + ), + child: Text( + _isOnline ? "ONLINE" : "OFFLINE", + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.w600, + color: _isOnline ? Colors.green : Colors.red, + ), + ), + ), + ], + ), + const SizedBox(height: 4), + Builder( + builder: (_) { + final formattedTime = DateFormat( + "dd MMM yyyy • HH:mm:ss", + ).format(_lastUpdateTime!); + return Text( + "Update: $formattedTime", + style: const TextStyle( + fontSize: 12, + color: Colors.grey, + ), + ); + }, + ), + ], + ), + ), /// GRAFIK MONITORING _buildMonitoringGraphBlock(), const SizedBox(height: 25), diff --git a/pubspec.lock b/pubspec.lock index 7d18d73..f2d3ad9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -280,6 +280,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.1.2" + intl: + dependency: "direct main" + description: + name: intl + sha256: "3df61194eb431efc39c4ceba583b95633a403f46c9fd341e550ce0bfa50e9aa5" + url: "https://pub.dev" + source: hosted + version: "0.20.2" leak_tracker: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 00cde00..699ec7f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,6 +20,7 @@ dependencies: cupertino_icons: ^1.0.8 fl_chart: ^1.1.1 firebase_database: ^12.1.3 + intl: ^0.20.2 dev_dependencies: flutter_test: From 196c5363dcaa21f2d49234ed162a7cf5412e37b4 Mon Sep 17 00:00:00 2001 From: e32232340-Nadif <158453666+kleponijo@users.noreply.github.com> Date: Sun, 1 Mar 2026 21:22:36 +0700 Subject: [PATCH 12/28] Update wind_speed_monitoring_screen.dart --- lib/screens/monitoring/wind_speed_monitoring_screen.dart | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/screens/monitoring/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed_monitoring_screen.dart index 4e32b88..fe747a4 100644 --- a/lib/screens/monitoring/wind_speed_monitoring_screen.dart +++ b/lib/screens/monitoring/wind_speed_monitoring_screen.dart @@ -326,15 +326,15 @@ class _WindSpeedMonitoringScreenState extends State { vertical: 5, ), decoration: BoxDecoration( - color: Colors.amber.shade100, + color: _isOnline ? Colors.green.shade100 : Colors.red.shade100, borderRadius: BorderRadius.circular(20), ), - child: const Text( - "Normal", + child: Text( + _isOnline ? "ONLINE" : "OFFLINE", style: TextStyle( fontSize: 11, fontWeight: FontWeight.w600, - color: Colors.amber, + color: _isOnline ? Colors.green : Colors.red, ), ), ), From da255177ee08efc5b0ddd591a3d591763efb9973 Mon Sep 17 00:00:00 2001 From: e32232340-Nadif <158453666+kleponijo@users.noreply.github.com> Date: Sun, 1 Mar 2026 22:01:03 +0700 Subject: [PATCH 13/28] Update wind_speed_monitoring_screen.dart --- .../wind_speed_monitoring_screen.dart | 60 ++++++++++++++----- 1 file changed, 46 insertions(+), 14 deletions(-) diff --git a/lib/screens/monitoring/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed_monitoring_screen.dart index fe747a4..f619d54 100644 --- a/lib/screens/monitoring/wind_speed_monitoring_screen.dart +++ b/lib/screens/monitoring/wind_speed_monitoring_screen.dart @@ -25,6 +25,11 @@ class _WindSpeedMonitoringScreenState extends State { double _currentSpeed = 0.0; final List _dailySpeeds = List.filled(24, 0.0); + // hourly aggregation helpers (PRO version) + double _hourlyTotalSpeed = 0.0; + int _hourlyCount = 0; + int _currentHour = DateTime.now().hour; + bool get _isOnline { if (_lastUpdateTime == null) return false; final diff = DateTime.now().difference(_lastUpdateTime!); @@ -39,25 +44,52 @@ class _WindSpeedMonitoringScreenState extends State { } void _onRealtimeData(DatabaseEvent event) { - final data = event.snapshot.value; + final data = event.snapshot.value; - if (data is Map) { - final speed = (data['kecepatan'] ?? 0).toDouble(); - final timestamp = data['timestamp'] ?? 0; + if (data is Map) { + final speed = (data['kecepatan'] ?? 0).toDouble(); + final timestamp = data['timestamp'] ?? 0; - final waktu = DateTime.fromMillisecondsSinceEpoch( - timestamp * 1000, - ); + final waktu = DateTime.fromMillisecondsSinceEpoch( + timestamp * 1000, + ); - setState(() { - _currentSpeed = speed; - _lastUpdateTime = waktu; + setState(() { + _currentSpeed = speed; + _lastUpdateTime = waktu; - _dailySpeeds.removeAt(0); - _dailySpeeds.add(speed); - }); - } + final incomingHour = waktu.hour; + + // Jika jam berubah → simpan rata-rata jam sebelumnya + if (incomingHour != _currentHour) { + + if (_hourlyCount > 0) { + final avg = _hourlyTotalSpeed / _hourlyCount; + + // Simpan ke index sesuai jam sebelumnya + _dailySpeeds[_currentHour] = avg; + } + + // Reset agregasi + _hourlyTotalSpeed = 0.0; + _hourlyCount = 0; + + _currentHour = incomingHour; + + // Reset data saat masuk hari baru (00:00) + if (incomingHour == 0) { + for (int i = 0; i < 24; i++) { + _dailySpeeds[i] = 0.0; + } + } + } + + // Tambah akumulasi + _hourlyTotalSpeed += speed; + _hourlyCount++; + }); } +} @override void dispose() { From cd2bc3e0cc0def3f1887f17b7844c80689abfbf6 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Tue, 3 Mar 2026 13:59:19 +0700 Subject: [PATCH 14/28] vgv --- lib/screens/home/views/home_screen.dart | 241 +++++++++++++++++++++--- 1 file changed, 216 insertions(+), 25 deletions(-) diff --git a/lib/screens/home/views/home_screen.dart b/lib/screens/home/views/home_screen.dart index b7a85e1..4deb72a 100644 --- a/lib/screens/home/views/home_screen.dart +++ b/lib/screens/home/views/home_screen.dart @@ -1,14 +1,184 @@ import 'package:flutter/material.dart'; import 'package:fl_chart/fl_chart.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:firebase_database/firebase_database.dart'; +import 'dart:async'; import '../../../blocs/authentication_bloc/authentication_bloc.dart'; import '../../monitoring/evaporasi_monitoring_screen.dart'; import '../../monitoring/wind_speed_monitoring_screen.dart'; import '../../monitoring/air_quality_monitoring_screen.dart'; -class HomeScreen extends StatelessWidget { +class HomeScreen extends StatefulWidget { const HomeScreen({super.key}); + @override + State createState() => _HomeScreenState(); +} + +class _HomeScreenState extends State { + // Firebase realtime database references + final DatabaseReference _evaporasiRef = FirebaseDatabase.instance.ref('evaporasi/realtime'); + final DatabaseReference _windSpeedRef = FirebaseDatabase.instance.ref('anemometer/realtime'); + final DatabaseReference _airQualityRef = FirebaseDatabase.instance.ref('air_quality/realtime'); + + // Stream subscriptions + StreamSubscription? _evaporasiSub; + StreamSubscription? _windSpeedSub; + StreamSubscription? _airQualitySub; + + // Realtime values + double _currentEvaporasi = 0.0; + double _currentWindSpeed = 0.0; + double _currentAirQuality = 0.0; + + DateTime? _evaporasiUpdateTime; + DateTime? _windSpeedUpdateTime; + DateTime? _airQualityUpdateTime; + + // Hourly data for charts (24 hours) + final List _evaporasiData = List.filled(24, 0.0); + final List _windSpeedData = List.filled(24, 0.0); + final List _airQualityData = List.filled(24, 0.0); + + // Hourly aggregation helpers + double _evaporasiHourlyTotal = 0.0; + int _evaporasiHourlyCount = 0; + + double _windSpeedHourlyTotal = 0.0; + int _windSpeedHourlyCount = 0; + + double _airQualityHourlyTotal = 0.0; + int _airQualityHourlyCount = 0; + + int _currentHour = DateTime.now().hour; + + @override + void initState() { + super.initState(); + _evaporasiSub = _evaporasiRef.onValue.listen(_onEvaporasiData); + _windSpeedSub = _windSpeedRef.onValue.listen(_onWindSpeedData); + _airQualitySub = _airQualityRef.onValue.listen(_onAirQualityData); + } + + void _onEvaporasiData(DatabaseEvent event) { + final data = event.snapshot.value; + if (data is Map) { + final value = (data['nilai'] ?? 0).toDouble(); + final timestamp = data['timestamp'] ?? 0; + final waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + + setState(() { + _currentEvaporasi = value; + _evaporasiUpdateTime = waktu; + + final incomingHour = waktu.hour; + + if (incomingHour != _currentHour) { + if (_evaporasiHourlyCount > 0) { + final avg = _evaporasiHourlyTotal / _evaporasiHourlyCount; + _evaporasiData[_currentHour] = avg; + } + + _evaporasiHourlyTotal = 0.0; + _evaporasiHourlyCount = 0; + + _currentHour = incomingHour; + + if (incomingHour == 0) { + for (int i = 0; i < 24; i++) { + _evaporasiData[i] = 0.0; + } + } + } + + _evaporasiHourlyTotal += value; + _evaporasiHourlyCount++; + }); + } + } + + void _onWindSpeedData(DatabaseEvent event) { + final data = event.snapshot.value; + if (data is Map) { + final value = (data['kecepatan'] ?? 0).toDouble(); + final timestamp = data['timestamp'] ?? 0; + final waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + + setState(() { + _currentWindSpeed = value; + _windSpeedUpdateTime = waktu; + + final incomingHour = waktu.hour; + + if (incomingHour != _currentHour) { + if (_windSpeedHourlyCount > 0) { + final avg = _windSpeedHourlyTotal / _windSpeedHourlyCount; + _windSpeedData[_currentHour] = avg; + } + + _windSpeedHourlyTotal = 0.0; + _windSpeedHourlyCount = 0; + + _currentHour = incomingHour; + + if (incomingHour == 0) { + for (int i = 0; i < 24; i++) { + _windSpeedData[i] = 0.0; + } + } + } + + _windSpeedHourlyTotal += value; + _windSpeedHourlyCount++; + }); + } + } + + void _onAirQualityData(DatabaseEvent event) { + final data = event.snapshot.value; + if (data is Map) { + final value = (data['aqi'] ?? 0).toDouble(); + final timestamp = data['timestamp'] ?? 0; + final waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + + setState(() { + _currentAirQuality = value; + _airQualityUpdateTime = waktu; + + final incomingHour = waktu.hour; + + if (incomingHour != _currentHour) { + if (_airQualityHourlyCount > 0) { + final avg = _airQualityHourlyTotal / _airQualityHourlyCount; + _airQualityData[_currentHour] = avg; + } + + _airQualityHourlyTotal = 0.0; + _airQualityHourlyCount = 0; + + _currentHour = incomingHour; + + if (incomingHour == 0) { + for (int i = 0; i < 24; i++) { + _airQualityData[i] = 0.0; + } + } + } + + _airQualityHourlyTotal += value; + _airQualityHourlyCount++; + }); + } + } + + @override + void dispose() { + _evaporasiSub?.cancel(); + _windSpeedSub?.cancel(); + _airQualitySub?.cancel(); + super.dispose(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -142,21 +312,21 @@ class HomeScreen extends StatelessWidget { children: [ _buildDataBlock( "Evaporasi", - "45.2", + _currentEvaporasi.toStringAsFixed(1), "mm", Colors.blue, Icons.opacity, ), _buildDataBlock( "Kec. Angin", - "12.5", + _currentWindSpeed.toStringAsFixed(1), "km/h", Colors.green, Icons.air, ), _buildDataBlock( "Kualitas Udara", - "78", + _currentAirQuality.toStringAsFixed(0), "AQI", Colors.orange, Icons.cloud, @@ -461,22 +631,22 @@ class HomeScreen extends StatelessWidget { /// GET MONITORING DATA FOR 24 HOURS List _getMonitoringData(String title) { - final dataMap = { - "Evaporasi": [ - 2.1, 2.3, 2.0, 1.9, 2.2, 2.5, 3.0, 3.5, 4.0, 4.2, - 4.5, 4.8, 5.0, 5.2, 5.1, 4.9, 4.5, 4.0, 3.5, 3.0, 2.8, 2.5, 2.3, 2.2 - ], - "Kecepatan Angin": [ - 5.0, 5.2, 4.8, 4.5, 4.3, 4.6, 5.1, 6.0, 7.2, 8.5, - 9.0, 10.2, 11.0, 10.5, 10.0, 9.2, 8.0, 6.5, 5.5, 5.0, 4.8, 4.5, 5.0, 5.2 - ], - "Kualitas Udara": [ - 68.0, 70.0, 72.0, 75.0, 78.0, 80.0, 78.0, 75.0, 72.0, 70.0, - 68.0, 65.0, 60.0, 58.0, 60.0, 62.0, 65.0, 68.0, 70.0, 72.0, 75.0, 78.0, 76.0, 74.0 - ], - }; + late final List data; + + switch (title) { + case "Evaporasi": + data = _evaporasiData; + break; + case "Kecepatan Angin": + data = _windSpeedData; + break; + case "Kualitas Udara": + data = _airQualityData; + break; + default: + data = []; + } - final data = dataMap[title] ?? []; return List.generate( data.length, (index) => FlSpot(index.toDouble(), data[index]), @@ -485,12 +655,33 @@ class HomeScreen extends StatelessWidget { /// GET AVERAGE VALUE String _getAverageData(String title) { - final dataMap = { - "Evaporasi": "3.5 mm", - "Kecepatan Angin": "6.8 km/h", - "Kualitas Udara": "70 AQI", - }; - return dataMap[title] ?? "N/A"; + late final double average; + late final String unit; + + switch (title) { + case "Evaporasi": + average = _evaporasiData.isNotEmpty + ? _evaporasiData.reduce((a, b) => a + b) / _evaporasiData.length + : 0.0; + unit = "mm"; + break; + case "Kecepatan Angin": + average = _windSpeedData.isNotEmpty + ? _windSpeedData.reduce((a, b) => a + b) / _windSpeedData.length + : 0.0; + unit = "km/h"; + break; + case "Kualitas Udara": + average = _airQualityData.isNotEmpty + ? _airQualityData.reduce((a, b) => a + b) / _airQualityData.length + : 0.0; + unit = "AQI"; + break; + default: + return "N/A"; + } + + return "${average.toStringAsFixed(1)} $unit"; } /// GET COLOR BY TITLE From 75d9e3220ea374009c06553c75788983d734f0b3 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Tue, 3 Mar 2026 15:21:49 +0700 Subject: [PATCH 15/28] update home_page halaman dashboard --- lib/screens/home/views/home_screen.dart | 190 ++++++++++++++++-------- 1 file changed, 125 insertions(+), 65 deletions(-) diff --git a/lib/screens/home/views/home_screen.dart b/lib/screens/home/views/home_screen.dart index 4deb72a..04899a6 100644 --- a/lib/screens/home/views/home_screen.dart +++ b/lib/screens/home/views/home_screen.dart @@ -15,6 +15,20 @@ class HomeScreen extends StatefulWidget { State createState() => _HomeScreenState(); } + +// simple model to represent one activity log item +class ActivityItem { + final String type; // evaporasi, angin, udara, etc + final String message; + final DateTime time; + + ActivityItem({ + required this.type, + required this.message, + required this.time, + }); +} + class _HomeScreenState extends State { // Firebase realtime database references final DatabaseReference _evaporasiRef = FirebaseDatabase.instance.ref('evaporasi/realtime'); @@ -40,6 +54,9 @@ class _HomeScreenState extends State { final List _windSpeedData = List.filled(24, 0.0); final List _airQualityData = List.filled(24, 0.0); + // activity log + final List _activities = []; + // Hourly aggregation helpers double _evaporasiHourlyTotal = 0.0; int _evaporasiHourlyCount = 0; @@ -71,6 +88,17 @@ class _HomeScreenState extends State { _currentEvaporasi = value; _evaporasiUpdateTime = waktu; + // add to activity log + _activities.insert( + 0, + ActivityItem( + type: "evaporasi", + message: "Evaporasi tercatat ${value.toStringAsFixed(1)} mm", + time: waktu, + ), + ); + if (_activities.length > 50) _activities.removeLast(); + final incomingHour = waktu.hour; if (incomingHour != _currentHour) { @@ -108,6 +136,17 @@ class _HomeScreenState extends State { _currentWindSpeed = value; _windSpeedUpdateTime = waktu; + // add to activity log + _activities.insert( + 0, + ActivityItem( + type: "angin", + message: "Kecepatan angin update menjadi ${value.toStringAsFixed(1)} km/h", + time: waktu, + ), + ); + if (_activities.length > 50) _activities.removeLast(); + final incomingHour = waktu.hour; if (incomingHour != _currentHour) { @@ -145,6 +184,17 @@ class _HomeScreenState extends State { _currentAirQuality = value; _airQualityUpdateTime = waktu; + // add to activity log + _activities.insert( + 0, + ActivityItem( + type: "udara", + message: "AQI berubah menjadi ${value.toStringAsFixed(0)}", + time: waktu, + ), + ); + if (_activities.length > 50) _activities.removeLast(); + final incomingHour = waktu.hour; if (incomingHour != _currentHour) { @@ -286,72 +336,44 @@ class _HomeScreenState extends State { /// 🔹 DASHBOARD UTAMA - 3 MONITORING body: Padding( padding: const EdgeInsets.all(16), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - BlocBuilder( - builder: (context, state) { - final name = state.user?.name.isNotEmpty == true - ? state.user!.name - : 'Pengguna'; - return Text( - 'Selamat Datang $name', - style: const TextStyle( - fontSize: 22, - fontWeight: FontWeight.bold, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + BlocBuilder( + builder: (context, state) { + final name = state.user?.name.isNotEmpty == true + ? state.user!.name + : 'Pengguna'; + return Text( + 'Selamat Datang $name', + style: const TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + ), + ); + }, + ), + const SizedBox(height: 10), + const Text( + "Recent Activity", + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 16), + Expanded( + child: _activities.isEmpty + ? const Center(child: Text("Belum ada aktivitas")) + : ListView.builder( + itemCount: _activities.length, + itemBuilder: (context, index) { + final item = _activities[index]; + return _buildActivityTile(item); + }, ), - ); - }, - ), - const SizedBox(height: 20), - - // 🔹 3 BLOCK DATA HARI INI - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - _buildDataBlock( - "Evaporasi", - _currentEvaporasi.toStringAsFixed(1), - "mm", - Colors.blue, - Icons.opacity, - ), - _buildDataBlock( - "Kec. Angin", - _currentWindSpeed.toStringAsFixed(1), - "km/h", - Colors.green, - Icons.air, - ), - _buildDataBlock( - "Kualitas Udara", - _currentAirQuality.toStringAsFixed(0), - "AQI", - Colors.orange, - Icons.cloud, - ), - ], - ), - - const SizedBox(height: 30), - - const Text( - "Grafik Monitoring", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 15), - - _buildDashboardCard(context, "Evaporasi"), - const SizedBox(height: 20), - _buildDashboardCard(context, "Kecepatan Angin"), - const SizedBox(height: 20), - _buildDashboardCard(context, "Kualitas Udara"), - ], - ), + ), + ], ), ), ); @@ -697,4 +719,42 @@ class _HomeScreenState extends State { return Colors.grey; } } + + /// ACTIVITY TILE + Widget _buildActivityTile(ActivityItem item) { + IconData icon; + Color color; + + switch (item.type) { + case "evaporasi": + icon = Icons.opacity; + color = Colors.blue; + break; + case "angin": + icon = Icons.air; + color = Colors.green; + break; + case "udara": + icon = Icons.cloud; + color = Colors.orange; + break; + default: + icon = Icons.info; + color = Colors.grey; + } + + return Card( + margin: const EdgeInsets.only(bottom: 12), + child: ListTile( + leading: CircleAvatar( + backgroundColor: color.withOpacity(0.2), + child: Icon(icon, color: color), + ), + title: Text(item.message), + subtitle: Text( + "${item.time.hour}:${item.time.minute.toString().padLeft(2, '0')}", + ), + ), + ); + } } From 499bf7d5688da57909dc859575f552901af00fa6 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Sun, 5 Apr 2026 20:33:12 +0700 Subject: [PATCH 16/28] oke pembaruan auth ke google --- .../auth/blocs/sign_in_bloc/sign_in_bloc.dart | 15 +- .../blocs/sign_in_bloc/sign_in_event.dart | 6 +- .../auth/blocs/sign_up_bloc/sign_up_bloc.dart | 13 +- .../blocs/sign_up_bloc/sign_up_event.dart | 4 +- lib/screens/auth/views/sign_in_screen.dart | 246 +++++----- lib/screens/auth/views/sign_up_screen.dart | 431 ++++++++++-------- .../lib/src/firebase_user_repo.dart | 46 +- .../user_repository/lib/src/user_repo.dart | 12 +- 8 files changed, 434 insertions(+), 339 deletions(-) diff --git a/lib/screens/auth/blocs/sign_in_bloc/sign_in_bloc.dart b/lib/screens/auth/blocs/sign_in_bloc/sign_in_bloc.dart index 1674865..d9502d1 100644 --- a/lib/screens/auth/blocs/sign_in_bloc/sign_in_bloc.dart +++ b/lib/screens/auth/blocs/sign_in_bloc/sign_in_bloc.dart @@ -8,9 +8,7 @@ part 'sign_in_state.dart'; class SignInBloc extends Bloc { final UserRepository _userRepository; - SignInBloc( - this._userRepository - ) : super(SignInInitial()) { + SignInBloc(this._userRepository) : super(SignInInitial()) { on((event, emit) async { emit(SignInProcess()); try { @@ -19,7 +17,16 @@ class SignInBloc extends Bloc { emit(SignInFailure()); } }); - + + on((event, emit) async { + emit(SignInProcess()); + try { + await _userRepository.signInWithGoogle(); + } catch (e) { + emit(SignInFailure()); + } + }); + on((event, emit) async => await _userRepository.logOut()); } } diff --git a/lib/screens/auth/blocs/sign_in_bloc/sign_in_event.dart b/lib/screens/auth/blocs/sign_in_bloc/sign_in_event.dart index 05203c4..037d319 100644 --- a/lib/screens/auth/blocs/sign_in_bloc/sign_in_event.dart +++ b/lib/screens/auth/blocs/sign_in_bloc/sign_in_event.dart @@ -17,6 +17,6 @@ class SignInRequired extends SignInEvent { List get props => [email, password]; } -class SignOutRequired extends SignInEvent { - -} \ No newline at end of file +class GoogleSignInRequired extends SignInEvent {} + +class SignOutRequired extends SignInEvent {} diff --git a/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart b/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart index d113b93..7da96f5 100644 --- a/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart +++ b/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart @@ -12,12 +12,23 @@ class SignUpBloc extends Bloc { on((event, emit) async { emit(SignUpProcess()); try { - MyUser myUser = await _userRepository.signUp(event.user, event.password); + MyUser myUser = + await _userRepository.signUp(event.user, event.password); await _userRepository.setUserData(myUser); emit(SignUpSuccess()); } catch (e) { emit(SignUpFailure(e.toString())); } }); + + on((event, emit) async { + emit(SignUpProcess()); + try { + await _userRepository.signInWithGoogle(); + emit(SignUpSuccess()); + } catch (e) { + emit(SignUpFailure(e.toString())); + } + }); } } diff --git a/lib/screens/auth/blocs/sign_up_bloc/sign_up_event.dart b/lib/screens/auth/blocs/sign_up_bloc/sign_up_event.dart index e87ef90..ea88827 100644 --- a/lib/screens/auth/blocs/sign_up_bloc/sign_up_event.dart +++ b/lib/screens/auth/blocs/sign_up_bloc/sign_up_event.dart @@ -15,4 +15,6 @@ class SignUpRequired extends SignUpEvent { @override List get props => [user, password]; -} \ No newline at end of file +} + +class GoogleSignInRequired extends SignUpEvent {} diff --git a/lib/screens/auth/views/sign_in_screen.dart b/lib/screens/auth/views/sign_in_screen.dart index e800018..f687089 100644 --- a/lib/screens/auth/views/sign_in_screen.dart +++ b/lib/screens/auth/views/sign_in_screen.dart @@ -13,125 +13,149 @@ class SignInScreen extends StatefulWidget { } class _SignInScreenState extends State { - final passwordController = TextEditingController(); + final passwordController = TextEditingController(); final emailController = TextEditingController(); final _formKey = GlobalKey(); - bool signInRequired = false; - IconData iconPassword = CupertinoIcons.eye_fill; - bool obscurePassword = true; - String? _errorMsg; - + bool signInRequired = false; + IconData iconPassword = CupertinoIcons.eye_fill; + bool obscurePassword = true; + String? _errorMsg; + @override Widget build(BuildContext context) { return BlocListener( - listener: (context, state) { - if(state is SignInSuccess) { - setState(() { - signInRequired = false; - }); - } else if(state is SignInProcess) { - setState(() { - signInRequired = true; - }); - } else if(state is SignInFailure) { - setState(() { - signInRequired = false; - _errorMsg = 'Invalid email or password'; - }); - } - }, - child: Form( - key: _formKey, - child: Column( - children: [ - const SizedBox(height: 20), - SizedBox( - width: MediaQuery.of(context).size.width * 0.9, - child: MyTextField( - controller: emailController, - hintText: 'Email', - obscureText: false, - keyboardType: TextInputType.emailAddress, - prefixIcon: const Icon(CupertinoIcons.mail_solid), - errorMsg: _errorMsg, - validator: (val) { - if (val!.isEmpty) { - return 'Please fill in this field'; - } - return null; - } - ) - ), - const SizedBox(height: 10), - SizedBox( - width: MediaQuery.of(context).size.width * 0.9, - child: MyTextField( - controller: passwordController, - hintText: 'Password', - obscureText: obscurePassword, - keyboardType: TextInputType.visiblePassword, - prefixIcon: const Icon(CupertinoIcons.lock_fill), - errorMsg: _errorMsg, - validator: (val) { - if (val!.isEmpty) { - return 'Please fill in this field'; - } - return null; - }, - suffixIcon: IconButton( - onPressed: () { - setState(() { - obscurePassword = !obscurePassword; - if(obscurePassword) { - iconPassword = CupertinoIcons.eye_fill; - } else { - iconPassword = CupertinoIcons.eye_slash_fill; - } - }); + listener: (context, state) { + if (state is SignInSuccess) { + setState(() { + signInRequired = false; + }); + } else if (state is SignInProcess) { + setState(() { + signInRequired = true; + }); + } else if (state is SignInFailure) { + setState(() { + signInRequired = false; + _errorMsg = 'Invalid email or password'; + }); + } + }, + child: Form( + key: _formKey, + child: Column( + children: [ + const SizedBox(height: 20), + SizedBox( + width: MediaQuery.of(context).size.width * 0.9, + child: MyTextField( + controller: emailController, + hintText: 'Email', + obscureText: false, + keyboardType: TextInputType.emailAddress, + prefixIcon: const Icon(CupertinoIcons.mail_solid), + errorMsg: _errorMsg, + validator: (val) { + if (val!.isEmpty) { + return 'Please fill in this field'; + } + return null; + })), + const SizedBox(height: 10), + SizedBox( + width: MediaQuery.of(context).size.width * 0.9, + child: MyTextField( + controller: passwordController, + hintText: 'Password', + obscureText: obscurePassword, + keyboardType: TextInputType.visiblePassword, + prefixIcon: const Icon(CupertinoIcons.lock_fill), + errorMsg: _errorMsg, + validator: (val) { + if (val!.isEmpty) { + return 'Please fill in this field'; + } + return null; }, - icon: Icon(iconPassword), + suffixIcon: IconButton( + onPressed: () { + setState(() { + obscurePassword = !obscurePassword; + if (obscurePassword) { + iconPassword = CupertinoIcons.eye_fill; + } else { + iconPassword = CupertinoIcons.eye_slash_fill; + } + }); + }, + icon: Icon(iconPassword), + ), ), ), - ), - const SizedBox(height: 20), - !signInRequired - ? SizedBox( - width: MediaQuery.of(context).size.width * 0.5, - child: TextButton( - onPressed: () { - if (_formKey.currentState!.validate()) { - context.read().add(SignInRequired( - emailController.text, - passwordController.text) - ); - } - }, - style: TextButton.styleFrom( - elevation: 3.0, - backgroundColor: Theme.of(context).colorScheme.primary, - foregroundColor: Colors.white, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(60) - ) - ), - child: const Padding( - padding: EdgeInsets.symmetric(horizontal: 25, vertical: 5), - child: Text( - 'Sign In', - textAlign: TextAlign.center, - style: TextStyle( - color: Colors.white, - fontSize: 16, - fontWeight: FontWeight.w600 - ), - ), + const SizedBox(height: 20), + !signInRequired + ? SizedBox( + width: MediaQuery.of(context).size.width * 0.5, + child: TextButton( + onPressed: () { + if (_formKey.currentState!.validate()) { + context.read().add(SignInRequired( + emailController.text, + passwordController.text)); + } + }, + style: TextButton.styleFrom( + elevation: 3.0, + backgroundColor: + Theme.of(context).colorScheme.primary, + foregroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(60))), + child: const Padding( + padding: EdgeInsets.symmetric( + horizontal: 25, vertical: 5), + child: Text( + 'Sign In', + textAlign: TextAlign.center, + style: TextStyle( + color: Colors.white, + fontSize: 16, + fontWeight: FontWeight.w600), + ), + )), ) + : const CircularProgressIndicator(), + const SizedBox(height: 20), + SizedBox( + width: MediaQuery.of(context).size.width * 0.5, + child: TextButton.icon( + onPressed: () { + context.read().add(GoogleSignInRequired()); + }, + icon: const Text( + 'G', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + color: Colors.blue, + ), ), - ) - : const CircularProgressIndicator(), - ], - ) - ), - ); + label: const Text( + 'Sign In with Google', + style: TextStyle( + color: Colors.black, + fontSize: 16, + fontWeight: FontWeight.w600), + ), + style: TextButton.styleFrom( + elevation: 3.0, + backgroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(60), + side: const BorderSide(color: Colors.grey))), + ), + ), + ], + )), + ); } -} \ No newline at end of file +} diff --git a/lib/screens/auth/views/sign_up_screen.dart b/lib/screens/auth/views/sign_up_screen.dart index 70c9b31..32b70e5 100644 --- a/lib/screens/auth/views/sign_up_screen.dart +++ b/lib/screens/auth/views/sign_up_screen.dart @@ -23,223 +23,266 @@ class _SignUpScreenState extends State { bool signUpRequired = false; bool containsUpperCase = false; - bool containsLowerCase = false; - bool containsNumber = false; - bool containsSpecialChar = false; - bool contains8Length = false; + bool containsLowerCase = false; + bool containsNumber = false; + bool containsSpecialChar = false; + bool contains8Length = false; @override Widget build(BuildContext context) { return BlocListener( - listener: (context, state) { - if (state is SignUpSuccess) { - setState(() { - signUpRequired = false; - }); - } else if (state is SignUpProcess) { - setState(() { - signUpRequired = true; - }); - } else if (state is SignUpFailure) { - return; - } - }, - child: Form( - key: _formKey, - child: Scaffold( - backgroundColor: Colors.white, - body: Center( - child: SingleChildScrollView( - child: Column( - children: [ - const SizedBox(height: 30), - Container( - width: MediaQuery.of(context).size.width * 0.92, - padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 22), - decoration: BoxDecoration( - color: Colors.white, - borderRadius: BorderRadius.circular(12), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.04), - blurRadius: 10, - offset: const Offset(0, 4), - ) - ], - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox(height: 6), - const Center( - child: Text( - 'Buat Akun', - style: TextStyle(fontSize: 22, fontWeight: FontWeight.w700), - ), + listener: (context, state) { + if (state is SignUpSuccess) { + setState(() { + signUpRequired = false; + }); + } else if (state is SignUpProcess) { + setState(() { + signUpRequired = true; + }); + } else if (state is SignUpFailure) { + return; + } + }, + child: Form( + key: _formKey, + child: Scaffold( + backgroundColor: Colors.white, + body: Center( + child: SingleChildScrollView( + child: Column( + children: [ + const SizedBox(height: 30), + Container( + width: MediaQuery.of(context).size.width * 0.92, + padding: const EdgeInsets.symmetric( + horizontal: 20, vertical: 22), + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(12), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.04), + blurRadius: 10, + offset: const Offset(0, 4), + ) + ], + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 6), + const Center( + child: Text( + 'Buat Akun', + style: TextStyle( + fontSize: 22, fontWeight: FontWeight.w700), ), - const SizedBox(height: 6), - const Center( - child: Text( - 'Daftar untuk mulai monitoring', - style: TextStyle(fontSize: 13, color: Colors.black54), - ), + ), + const SizedBox(height: 6), + const Center( + child: Text( + 'Daftar untuk mulai monitoring', + style: + TextStyle(fontSize: 13, color: Colors.black54), ), - const SizedBox(height: 14), + ), + const SizedBox(height: 14), - // Name - SizedBox( - width: MediaQuery.of(context).size.width * 0.9, - child: MyTextField( - controller: nameController, - hintText: 'Masukkan nama lengkap', - obscureText: false, - keyboardType: TextInputType.name, - prefixIcon: const Icon(CupertinoIcons.person_fill), - validator: (val) { - if (val == null || val.isEmpty) { - return 'Please fill in this field'; - } else if (val.length > 50) { - return 'Name too long'; - } - return null; + // Name + SizedBox( + width: MediaQuery.of(context).size.width * 0.9, + child: MyTextField( + controller: nameController, + hintText: 'Masukkan nama lengkap', + obscureText: false, + keyboardType: TextInputType.name, + prefixIcon: const Icon(CupertinoIcons.person_fill), + validator: (val) { + if (val == null || val.isEmpty) { + return 'Please fill in this field'; + } else if (val.length > 50) { + return 'Name too long'; + } + return null; + }, + ), + ), + const SizedBox(height: 10), + + // Email + SizedBox( + width: MediaQuery.of(context).size.width * 0.9, + child: MyTextField( + controller: emailController, + hintText: 'nama@email.com', + obscureText: false, + keyboardType: TextInputType.emailAddress, + prefixIcon: const Icon(CupertinoIcons.mail_solid), + validator: (val) { + if (val == null || val.isEmpty) { + return 'Please fill in this field'; + } + return null; + }, + ), + ), + const SizedBox(height: 10), + + // Password + SizedBox( + width: MediaQuery.of(context).size.width * 0.9, + child: MyTextField( + controller: passwordController, + hintText: 'Minimal 6 karakter', + obscureText: obscurePassword, + keyboardType: TextInputType.visiblePassword, + prefixIcon: const Icon(CupertinoIcons.lock_fill), + suffixIcon: IconButton( + onPressed: () { + setState(() { + obscurePassword = !obscurePassword; + iconPassword = obscurePassword + ? CupertinoIcons.eye_fill + : CupertinoIcons.eye_slash_fill; + }); }, + icon: Icon(iconPassword), ), + validator: (val) { + if (val == null || val.isEmpty) { + return 'Please fill in this field'; + } + return null; + }, ), - const SizedBox(height: 10), + ), + const SizedBox(height: 10), - // Email - SizedBox( - width: MediaQuery.of(context).size.width * 0.9, - child: MyTextField( - controller: emailController, - hintText: 'nama@email.com', - obscureText: false, - keyboardType: TextInputType.emailAddress, - prefixIcon: const Icon(CupertinoIcons.mail_solid), - validator: (val) { - if (val == null || val.isEmpty) { - return 'Please fill in this field'; - } - return null; - }, - ), + // Confirm Password + SizedBox( + width: MediaQuery.of(context).size.width * 0.9, + child: MyTextField( + controller: confirmPasswordController, + hintText: 'Ulangi password', + obscureText: obscurePassword, + keyboardType: TextInputType.visiblePassword, + prefixIcon: const Icon(CupertinoIcons.lock_fill), + validator: (val) { + if (val == null || val.isEmpty) { + return 'Please fill in this field'; + } else if (val != passwordController.text) { + return 'Password tidak cocok'; + } + return null; + }, ), - const SizedBox(height: 10), + ), - // Password - SizedBox( - width: MediaQuery.of(context).size.width * 0.9, - child: MyTextField( - controller: passwordController, - hintText: 'Minimal 6 karakter', - obscureText: obscurePassword, - keyboardType: TextInputType.visiblePassword, - prefixIcon: const Icon(CupertinoIcons.lock_fill), - suffixIcon: IconButton( - onPressed: () { - setState(() { - obscurePassword = !obscurePassword; - iconPassword = obscurePassword - ? CupertinoIcons.eye_fill - : CupertinoIcons.eye_slash_fill; - }); - }, - icon: Icon(iconPassword), - ), - validator: (val) { - if (val == null || val.isEmpty) { - return 'Please fill in this field'; - } - return null; - }, - ), - ), - const SizedBox(height: 10), + const SizedBox(height: 18), - // Confirm Password - SizedBox( - width: MediaQuery.of(context).size.width * 0.9, - child: MyTextField( - controller: confirmPasswordController, - hintText: 'Ulangi password', - obscureText: obscurePassword, - keyboardType: TextInputType.visiblePassword, - prefixIcon: const Icon(CupertinoIcons.lock_fill), - validator: (val) { - if (val == null || val.isEmpty) { - return 'Please fill in this field'; - } else if (val != passwordController.text) { - return 'Password tidak cocok'; - } - return null; - }, - ), - ), + // Button + !signUpRequired + ? SizedBox( + width: MediaQuery.of(context).size.width * 0.92, + child: ElevatedButton( + onPressed: () { + if (_formKey.currentState!.validate()) { + MyUser myUser = MyUser.empty; + myUser.email = emailController.text; + myUser.name = nameController.text; - const SizedBox(height: 18), - - // Button - !signUpRequired - ? SizedBox( - width: MediaQuery.of(context).size.width * 0.92, - child: ElevatedButton( - onPressed: () { - if (_formKey.currentState!.validate()) { - MyUser myUser = MyUser.empty; - myUser.email = emailController.text; - myUser.name = nameController.text; - - setState(() { - context.read().add( - SignUpRequired( - myUser, - passwordController.text, - ), - ); - }); - } - }, - style: ElevatedButton.styleFrom( - backgroundColor: Colors.black87, - foregroundColor: Colors.white, - padding: const EdgeInsets.symmetric(vertical: 16), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - ), - ), - child: const Text( - 'Daftar', - style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600), + setState(() { + context.read().add( + SignUpRequired( + myUser, + passwordController.text, + ), + ); + }); + } + }, + style: ElevatedButton.styleFrom( + backgroundColor: Colors.black87, + foregroundColor: Colors.white, + padding: const EdgeInsets.symmetric( + vertical: 16), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), ), ), - ) - : const CircularProgressIndicator(), + child: const Text( + 'Daftar', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600), + ), + ), + ) + : const CircularProgressIndicator(), - const SizedBox(height: 12), - Center( - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text('Sudah punya akun? '), - TextButton( - onPressed: () { - Navigator.of(context).pop(); - }, - child: const Text('Login di sini'), - ) - ], + const SizedBox(height: 12), + Center( + child: Text('Atau'), + ), + const SizedBox(height: 12), + SizedBox( + width: MediaQuery.of(context).size.width * 0.92, + child: TextButton.icon( + onPressed: () { + context + .read() + .add(GoogleSignInRequired()); + }, + icon: const Text( + 'G', + style: TextStyle( + fontSize: 20, + fontWeight: FontWeight.bold, + color: Colors.blue, + ), + ), + label: const Text( + 'Daftar dengan Google', + style: TextStyle( + color: Colors.black, + fontSize: 16, + fontWeight: FontWeight.w600), + ), + style: TextButton.styleFrom( + backgroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8), + side: const BorderSide(color: Colors.grey)), + padding: const EdgeInsets.symmetric(vertical: 16), ), ), - ], - ), + ), + const SizedBox(height: 12), + Center( + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('Sudah punya akun? '), + TextButton( + onPressed: () { + Navigator.of(context).pop(); + }, + child: const Text('Login di sini'), + ) + ], + ), + ), + ], ), - const SizedBox(height: 30), - ], - ), + ), + const SizedBox(height: 30), + ], ), ), ), ), - ); + ), + ); } -} \ No newline at end of file +} diff --git a/packages/user_repository/lib/src/firebase_user_repo.dart b/packages/user_repository/lib/src/firebase_user_repo.dart index e27ae9b..534a3e9 100644 --- a/packages/user_repository/lib/src/firebase_user_repo.dart +++ b/packages/user_repository/lib/src/firebase_user_repo.dart @@ -21,13 +21,15 @@ class FirebaseUserRepo implements UserRepository { try { final userData = await userCollection.doc(firebaseUser.uid).get(); if (userData.exists && userData.data() != null) { - yield MyUser.fromEntity(MyUserEntity.fromDocument(userData.data()!)); + yield MyUser.fromEntity( + MyUserEntity.fromDocument(userData.data()!)); } else { // User baru yang belum ada data di Firestore, tunggu sebentar await Future.delayed(const Duration(milliseconds: 500)); final retryData = await userCollection.doc(firebaseUser.uid).get(); if (retryData.exists && retryData.data() != null) { - yield MyUser.fromEntity(MyUserEntity.fromDocument(retryData.data()!)); + yield MyUser.fromEntity( + MyUserEntity.fromDocument(retryData.data()!)); } else { yield MyUser.empty; } @@ -40,32 +42,28 @@ class FirebaseUserRepo implements UserRepository { }); } - @override + @override Future signIn(String email, String password) async { try { - await _firebaseAuth.signInWithEmailAndPassword( - email: email, - password: password - ); + await _firebaseAuth.signInWithEmailAndPassword( + email: email, password: password); } catch (e) { - log(e.toString()); + log(e.toString()); rethrow; } } @override Future signUp(MyUser myUser, String password) async { - try { + try { UserCredential user = await _firebaseAuth.createUserWithEmailAndPassword( - email: myUser.email, - password: password - ); - myUser.userId = user.user!.uid; - return myUser; + email: myUser.email, password: password); + myUser.userId = user.user!.uid; + return myUser; } catch (e) { log(e.toString()); rethrow; - } + } } @override @@ -77,8 +75,8 @@ class FirebaseUserRepo implements UserRepository { Future setUserData(MyUser myUser) async { try { await userCollection - .doc(myUser.userId) - .set(myUser.toEntity().toDocument()); + .doc(myUser.userId) + .set(myUser.toEntity().toDocument()); // Tunggu sebentar agar data tersimpan dengan baik sebelum stream update await Future.delayed(const Duration(milliseconds: 500)); } catch (e) { @@ -87,6 +85,14 @@ class FirebaseUserRepo implements UserRepository { } } - - -} \ No newline at end of file + @override + Future signInWithGoogle() async { + try { + final GoogleAuthProvider googleProvider = GoogleAuthProvider(); + await _firebaseAuth.signInWithPopup(googleProvider); + } catch (e) { + log('Google sign-in error: $e'); + rethrow; + } + } +} diff --git a/packages/user_repository/lib/src/user_repo.dart b/packages/user_repository/lib/src/user_repo.dart index 6ffe0bf..f90adfa 100644 --- a/packages/user_repository/lib/src/user_repo.dart +++ b/packages/user_repository/lib/src/user_repo.dart @@ -3,11 +3,13 @@ import 'models/models.dart'; abstract class UserRepository { Stream get user; - Future signUp(MyUser myUser, String password); + Future signUp(MyUser myUser, String password); - Future setUserData(MyUser user); + Future setUserData(MyUser user); - Future signIn(String email, String password); + Future signIn(String email, String password); - Future logOut(); -} \ No newline at end of file + Future signInWithGoogle(); + + Future logOut(); +} From 16db1703f3b446aeb447b0b81a256a045f67db6e Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Sun, 5 Apr 2026 20:40:09 +0700 Subject: [PATCH 17/28] Update firebase_user_repo.dart --- .../lib/src/firebase_user_repo.dart | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/user_repository/lib/src/firebase_user_repo.dart b/packages/user_repository/lib/src/firebase_user_repo.dart index 534a3e9..b1b428f 100644 --- a/packages/user_repository/lib/src/firebase_user_repo.dart +++ b/packages/user_repository/lib/src/firebase_user_repo.dart @@ -89,7 +89,26 @@ class FirebaseUserRepo implements UserRepository { Future signInWithGoogle() async { try { final GoogleAuthProvider googleProvider = GoogleAuthProvider(); - await _firebaseAuth.signInWithPopup(googleProvider); + final UserCredential userCredential = + await _firebaseAuth.signInWithPopup(googleProvider); + + final User? firebaseUser = userCredential.user; + if (firebaseUser != null) { + // Check if user data already exists in Firestore + final existingUser = await userCollection.doc(firebaseUser.uid).get(); + + if (!existingUser.exists) { + // Create new user data from Google account info + final newUser = MyUser( + userId: firebaseUser.uid, + email: firebaseUser.email ?? '', + name: firebaseUser.displayName ?? 'User', + hasActiveCart: false, + ); + + await setUserData(newUser); + } + } } catch (e) { log('Google sign-in error: $e'); rethrow; From 726d561670326b485ce287d8c2fba82bb4af539c Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Thu, 9 Apr 2026 10:26:50 +0700 Subject: [PATCH 18/28] oke --- lib/screens/home/views/home_screen.dart | 64 ++- .../evaporasi_monitoring_screen.dart | 416 +++++++++++++++--- 2 files changed, 403 insertions(+), 77 deletions(-) diff --git a/lib/screens/home/views/home_screen.dart b/lib/screens/home/views/home_screen.dart index 04899a6..27c4ebe 100644 --- a/lib/screens/home/views/home_screen.dart +++ b/lib/screens/home/views/home_screen.dart @@ -15,7 +15,6 @@ class HomeScreen extends StatefulWidget { State createState() => _HomeScreenState(); } - // simple model to represent one activity log item class ActivityItem { final String type; // evaporasi, angin, udara, etc @@ -31,9 +30,12 @@ class ActivityItem { class _HomeScreenState extends State { // Firebase realtime database references - final DatabaseReference _evaporasiRef = FirebaseDatabase.instance.ref('evaporasi/realtime'); - final DatabaseReference _windSpeedRef = FirebaseDatabase.instance.ref('anemometer/realtime'); - final DatabaseReference _airQualityRef = FirebaseDatabase.instance.ref('air_quality/realtime'); + final DatabaseReference _evaporasiRef = + FirebaseDatabase.instance.ref('kelompok1/evaporasi'); + final DatabaseReference _windSpeedRef = + FirebaseDatabase.instance.ref('anemometer/realtime'); + final DatabaseReference _airQualityRef = + FirebaseDatabase.instance.ref('air_quality/realtime'); // Stream subscriptions StreamSubscription? _evaporasiSub; @@ -44,7 +46,7 @@ class _HomeScreenState extends State { double _currentEvaporasi = 0.0; double _currentWindSpeed = 0.0; double _currentAirQuality = 0.0; - + DateTime? _evaporasiUpdateTime; DateTime? _windSpeedUpdateTime; DateTime? _airQualityUpdateTime; @@ -60,13 +62,13 @@ class _HomeScreenState extends State { // Hourly aggregation helpers double _evaporasiHourlyTotal = 0.0; int _evaporasiHourlyCount = 0; - + double _windSpeedHourlyTotal = 0.0; int _windSpeedHourlyCount = 0; - + double _airQualityHourlyTotal = 0.0; int _airQualityHourlyCount = 0; - + int _currentHour = DateTime.now().hour; @override @@ -80,9 +82,21 @@ class _HomeScreenState extends State { void _onEvaporasiData(DatabaseEvent event) { final data = event.snapshot.value; if (data is Map) { - final value = (data['nilai'] ?? 0).toDouble(); - final timestamp = data['timestamp'] ?? 0; - final waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + final value = double.tryParse( + (data['evaporasi'] ?? data['nilai'] ?? 0).toString()) ?? + 0.0; + DateTime waktu; + + if (data.containsKey('timestamp')) { + final timestamp = + int.tryParse(data['timestamp']?.toString() ?? '0') ?? 0; + waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + } else { + final hour = int.tryParse(data['jam']?.toString() ?? '0') ?? 0; + final minute = int.tryParse(data['menit']?.toString() ?? '0') ?? 0; + final now = DateTime.now(); + waktu = DateTime(now.year, now.month, now.day, hour, minute); + } setState(() { _currentEvaporasi = value; @@ -141,7 +155,8 @@ class _HomeScreenState extends State { 0, ActivityItem( type: "angin", - message: "Kecepatan angin update menjadi ${value.toStringAsFixed(1)} km/h", + message: + "Kecepatan angin update menjadi ${value.toStringAsFixed(1)} km/h", time: waktu, ), ); @@ -254,7 +269,12 @@ class _HomeScreenState extends State { ? user.email : 'Tidak ada email'; final initials = (displayName.isNotEmpty) - ? displayName.trim().split(' ').map((e) => e.isNotEmpty ? e[0] : '').take(2).join() + ? displayName + .trim() + .split(' ') + .map((e) => e.isNotEmpty ? e[0] : '') + .take(2) + .join() : 'U'; return UserAccountsDrawerHeader( @@ -654,7 +674,7 @@ class _HomeScreenState extends State { /// GET MONITORING DATA FOR 24 HOURS List _getMonitoringData(String title) { late final List data; - + switch (title) { case "Evaporasi": data = _evaporasiData; @@ -679,30 +699,30 @@ class _HomeScreenState extends State { String _getAverageData(String title) { late final double average; late final String unit; - + switch (title) { case "Evaporasi": - average = _evaporasiData.isNotEmpty - ? _evaporasiData.reduce((a, b) => a + b) / _evaporasiData.length + average = _evaporasiData.isNotEmpty + ? _evaporasiData.reduce((a, b) => a + b) / _evaporasiData.length : 0.0; unit = "mm"; break; case "Kecepatan Angin": - average = _windSpeedData.isNotEmpty - ? _windSpeedData.reduce((a, b) => a + b) / _windSpeedData.length + average = _windSpeedData.isNotEmpty + ? _windSpeedData.reduce((a, b) => a + b) / _windSpeedData.length : 0.0; unit = "km/h"; break; case "Kualitas Udara": - average = _airQualityData.isNotEmpty - ? _airQualityData.reduce((a, b) => a + b) / _airQualityData.length + average = _airQualityData.isNotEmpty + ? _airQualityData.reduce((a, b) => a + b) / _airQualityData.length : 0.0; unit = "AQI"; break; default: return "N/A"; } - + return "${average.toStringAsFixed(1)} $unit"; } diff --git a/lib/screens/monitoring/evaporasi_monitoring_screen.dart b/lib/screens/monitoring/evaporasi_monitoring_screen.dart index 9618d26..488aae8 100644 --- a/lib/screens/monitoring/evaporasi_monitoring_screen.dart +++ b/lib/screens/monitoring/evaporasi_monitoring_screen.dart @@ -1,5 +1,8 @@ import 'package:flutter/material.dart'; import 'package:fl_chart/fl_chart.dart'; +import 'package:firebase_database/firebase_database.dart'; +import 'dart:async'; +import 'package:intl/intl.dart'; import 'widgets/monitoring_shared.dart'; /// EVAPORASI MONITORING SCREEN @@ -7,12 +10,148 @@ class EvaporasiMonitoringScreen extends StatefulWidget { const EvaporasiMonitoringScreen({super.key}); @override - State createState() => _EvaporasiMonitoringScreenState(); + State createState() => + _EvaporasiMonitoringScreenState(); } class _EvaporasiMonitoringScreenState extends State { String _selectedPeriod = "Hari Ini"; + final DatabaseReference _evaporationRef = + FirebaseDatabase.instance.ref('kelompok1/evaporasi'); + StreamSubscription? _evaporationSub; + + DateTime? _lastUpdateTime; + double _currentEvaporation = 0.0; + double _currentTemperature = 0.0; + double _currentWaterHeight = 0.0; + final List _dailyEvaporation = List.filled(24, 0.0); + double _hourlyTotal = 0.0; + int _hourlyCount = 0; + int _currentHour = DateTime.now().hour; + + bool get _isOnline { + if (_lastUpdateTime == null) return false; + final diff = DateTime.now().difference(_lastUpdateTime!); + return diff.inMinutes <= 5; + } + + @override + void initState() { + super.initState(); + _evaporationSub = _evaporationRef.onValue.listen(_onRealtimeData); + } + + @override + void dispose() { + _evaporationSub?.cancel(); + super.dispose(); + } + + void _onRealtimeData(DatabaseEvent event) { + final data = event.snapshot.value; + if (data is Map) { + final value = double.tryParse( + (data['evaporasi'] ?? data['nilai'] ?? 0).toString()) ?? + 0.0; + final temp = double.tryParse(data['suhu']?.toString() ?? '0') ?? 0.0; + final waterHeight = + double.tryParse(data['tinggi_air']?.toString() ?? '0') ?? 0.0; + final DateTime waktu; + + if (data.containsKey('timestamp')) { + final timestamp = + int.tryParse(data['timestamp']?.toString() ?? '0') ?? 0; + waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + } else { + final hour = int.tryParse(data['jam']?.toString() ?? '0') ?? 0; + final minute = int.tryParse(data['menit']?.toString() ?? '0') ?? 0; + final now = DateTime.now(); + waktu = DateTime(now.year, now.month, now.day, hour, minute); + } + + setState(() { + _currentEvaporation = value; + _currentTemperature = temp; + _currentWaterHeight = waterHeight; + _lastUpdateTime = waktu; + + final incomingHour = waktu.hour; + if (incomingHour != _currentHour) { + if (_hourlyCount > 0) { + _dailyEvaporation[_currentHour] = _hourlyTotal / _hourlyCount; + } + _hourlyTotal = 0.0; + _hourlyCount = 0; + _currentHour = incomingHour; + if (incomingHour == 0) { + for (int i = 0; i < 24; i++) { + _dailyEvaporation[i] = 0.0; + } + } + } + + _hourlyTotal += value; + _hourlyCount++; + _dailyEvaporation[incomingHour] = + _hourlyCount > 0 ? _hourlyTotal / _hourlyCount : value; + }); + } + } + + String _formatUpdateTime() { + if (_lastUpdateTime == null) return '-'; + return DateFormat('dd MMM yyyy • HH:mm').format(_lastUpdateTime!); + } + + bool get _hasRealtimeEvaporation => + _dailyEvaporation.any((value) => value > 0.0); + + Widget _buildDetailTile({ + required String label, + required String value, + required IconData icon, + required Color color, + }) { + return Expanded( + child: Container( + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + color: color.withOpacity(0.08), + borderRadius: BorderRadius.circular(12), + border: Border.all(color: color.withOpacity(0.2)), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + Icon(icon, color: color, size: 16), + const SizedBox(width: 6), + Text( + label, + style: TextStyle( + fontSize: 11, + color: Colors.grey.shade700, + ), + ), + ], + ), + const SizedBox(height: 8), + Text( + value, + style: TextStyle( + fontSize: 15, + fontWeight: FontWeight.bold, + color: color, + ), + ), + ], + ), + ), + ); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -33,6 +172,139 @@ class _EvaporasiMonitoringScreenState extends State { fontWeight: FontWeight.bold, ), ), + const SizedBox(height: 16), + if (_lastUpdateTime != null) + Card( + elevation: 2, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "${_currentEvaporation.toStringAsFixed(1)} mm", + style: const TextStyle( + fontSize: 28, + fontWeight: FontWeight.bold, + color: Colors.blue, + ), + ), + const SizedBox(height: 8), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Terakhir diperbarui", + style: TextStyle( + fontSize: 12, + color: Colors.grey, + ), + ), + const SizedBox(height: 4), + Text( + _formatUpdateTime(), + style: const TextStyle( + fontSize: 12, + color: Colors.black54, + ), + ), + ], + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 5, + ), + decoration: BoxDecoration( + color: _isOnline + ? Colors.green.shade100 + : Colors.red.shade100, + borderRadius: BorderRadius.circular(20), + ), + child: Text( + _isOnline ? 'ONLINE' : 'OFFLINE', + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.w600, + color: _isOnline ? Colors.green : Colors.red, + ), + ), + ), + ], + ), + ], + ), + ), + ), + const SizedBox(height: 12), + Card( + elevation: 2, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 16, + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + 'Detail Sensor Evaporasi', + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 14), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + _buildDetailTile( + label: 'Jam', + value: DateFormat('HH:mm').format(_lastUpdateTime!), + icon: Icons.access_time, + color: Colors.blue, + ), + _buildDetailTile( + label: 'Suhu', + value: + '${_currentTemperature.toStringAsFixed(2)} °C', + icon: Icons.thermostat, + color: Colors.red, + ), + ], + ), + const SizedBox(height: 12), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + _buildDetailTile( + label: 'Tinggi Air', + value: '${_currentWaterHeight.toStringAsFixed(2)}', + icon: Icons.water_drop, + color: Colors.blueAccent, + ), + _buildDetailTile( + label: 'Evaporasi', + value: + '${_currentEvaporation.toStringAsFixed(1)} mm', + icon: Icons.opacity, + color: Colors.blue, + ), + ], + ), + ], + ), + ), + ), const SizedBox(height: 20), /// SISTEM KONTROL AIR OTOMATIS @@ -65,8 +337,30 @@ class _EvaporasiMonitoringScreenState extends State { csvContent.writeln("Jam,Nilai (mm)"); final dailyData = [ - 2.1, 2.3, 2.0, 1.9, 2.2, 2.5, 3.0, 3.5, 4.0, 4.2, - 4.5, 4.8, 5.0, 5.2, 5.1, 4.9, 4.5, 4.0, 3.5, 3.0, 2.8, 2.5, 2.3, 2.2 + 2.1, + 2.3, + 2.0, + 1.9, + 2.2, + 2.5, + 3.0, + 3.5, + 4.0, + 4.2, + 4.5, + 4.8, + 5.0, + 5.2, + 5.1, + 4.9, + 4.5, + 4.0, + 3.5, + 3.0, + 2.8, + 2.5, + 2.3, + 2.2 ]; for (int i = 0; i < dailyData.length; i++) { csvContent.writeln("$i:00,${dailyData[i]}"); @@ -89,7 +383,15 @@ class _EvaporasiMonitoringScreenState extends State { csvContent.writeln(""); csvContent.writeln("Hari,Nilai (mm)"); - final days = ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu']; + final days = [ + 'Senin', + 'Selasa', + 'Rabu', + 'Kamis', + 'Jumat', + 'Sabtu', + 'Minggu' + ]; final weeklyData = [3.5, 3.8, 4.2, 4.5, 4.0, 3.8, 3.2]; for (int i = 0; i < days.length; i++) { @@ -109,7 +411,8 @@ class _EvaporasiMonitoringScreenState extends State { void _exportMonthlyData() { final StringBuffer csvContent = StringBuffer(); csvContent.writeln("DATA MONITORING EVAPORASI - BULANAN"); - csvContent.writeln("Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); + csvContent.writeln( + "Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); csvContent.writeln(""); csvContent.writeln("Tanggal,Nilai (mm)"); @@ -136,11 +439,34 @@ class _EvaporasiMonitoringScreenState extends State { csvContent.writeln("Bulan,Pengisian (x),Rata-rata (mm)"); final months = [ - 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', - 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' + 'Januari', + 'Februari', + 'Maret', + 'April', + 'Mei', + 'Juni', + 'Juli', + 'Agustus', + 'September', + 'Oktober', + 'November', + 'Desember' ]; final fillings = [12, 13, 15, 14, 13, 12, 14, 16, 13, 14, 15, 13]; - final averages = [3.5, 3.8, 4.2, 4.5, 5.0, 5.2, 5.5, 5.8, 5.0, 4.5, 4.0, 3.7]; + final averages = [ + 3.5, + 3.8, + 4.2, + 4.5, + 5.0, + 5.2, + 5.5, + 5.8, + 5.0, + 4.5, + 4.0, + 3.7 + ]; for (int i = 0; i < months.length; i++) { csvContent.writeln("${months[i]},${fillings[i]},${averages[i]}"); @@ -159,38 +485,17 @@ class _EvaporasiMonitoringScreenState extends State { List _getEvaporationPeriodData() { switch (_selectedPeriod) { case "Hari Ini": - return List.generate(24, (i) { - final values = [ - 2.1, 2.3, 2.0, 1.9, 2.2, 2.5, 3.0, 3.5, 4.0, 4.2, - 4.5, 4.8, 5.0, 5.2, 5.1, 4.9, 4.5, 4.0, 3.5, 3.0, 2.8, 2.5, 2.3, 2.2 - ]; - return FlSpot(i.toDouble(), values[i]); - }); + if (_hasRealtimeEvaporation) { + return List.generate( + _dailyEvaporation.length, + (index) => FlSpot(index.toDouble(), _dailyEvaporation[index]), + ); + } + return List.generate(24, (index) => FlSpot(index.toDouble(), 0.0)); case "Minggu Ini": - return [ - const FlSpot(0, 3.5), - const FlSpot(1, 3.8), - const FlSpot(2, 4.2), - const FlSpot(3, 4.5), - const FlSpot(4, 4.0), - const FlSpot(5, 3.8), - const FlSpot(6, 3.2), - ]; + return List.generate(7, (index) => FlSpot(index.toDouble(), 0.0)); case "Bulan Ini": - return [ - const FlSpot(0, 3.5), - const FlSpot(1, 3.8), - const FlSpot(2, 4.2), - const FlSpot(3, 4.5), - const FlSpot(4, 5.0), - const FlSpot(5, 5.2), - const FlSpot(6, 5.5), - const FlSpot(7, 5.8), - const FlSpot(8, 5.0), - const FlSpot(9, 4.5), - const FlSpot(10, 4.0), - const FlSpot(11, 3.7), - ]; + return List.generate(12, (index) => FlSpot(index.toDouble(), 0.0)); default: return []; } @@ -333,7 +638,8 @@ class _EvaporasiMonitoringScreenState extends State { child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( - children: ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { + children: + ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { return Padding( padding: const EdgeInsets.only(right: 8), child: ChoiceChip( @@ -595,8 +901,18 @@ class _EvaporasiMonitoringScreenState extends State { showTitles: true, getTitlesWidget: (value, meta) { final months = [ - 'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', - 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des' + 'Jan', + 'Feb', + 'Mar', + 'Apr', + 'Mei', + 'Jun', + 'Jul', + 'Agu', + 'Sep', + 'Okt', + 'Nov', + 'Des' ]; return Text( months[value.toInt()], @@ -660,20 +976,10 @@ class _EvaporasiMonitoringScreenState extends State { ), ), ), - barGroups: [ - buildBarGroup(0, 12), - buildBarGroup(1, 13), - buildBarGroup(2, 15), - buildBarGroup(3, 14), - buildBarGroup(4, 13), - buildBarGroup(5, 12), - buildBarGroup(6, 14), - buildBarGroup(7, 16), - buildBarGroup(8, 13), - buildBarGroup(9, 14), - buildBarGroup(10, 15), - buildBarGroup(11, 13), - ], + barGroups: List.generate( + 12, + (index) => buildBarGroup(index, 0), + ), rangeAnnotations: RangeAnnotations( horizontalRangeAnnotations: [ HorizontalRangeAnnotation( From f9e5ab02c7ce4aaea94948417a0020963e7d3ef9 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Fri, 10 Apr 2026 20:28:17 +0700 Subject: [PATCH 19/28] ok --- lib/screens/home/views/home_screen.dart | 2 +- .../widgets/wind_speed_annual_section.dart | 225 +++++ .../widgets/wind_speed_explanation.dart | 39 + .../widgets/wind_speed_graph_block.dart | 249 ++++++ .../widgets/wind_speed_status_block.dart | 68 ++ .../wind_speed_monitoring_screen.dart | 328 +++++++ .../wind_speed_monitoring_screen.dart | 815 ------------------ 7 files changed, 910 insertions(+), 816 deletions(-) create mode 100644 lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart create mode 100644 lib/screens/monitoring/wind_speed/widgets/wind_speed_explanation.dart create mode 100644 lib/screens/monitoring/wind_speed/widgets/wind_speed_graph_block.dart create mode 100644 lib/screens/monitoring/wind_speed/widgets/wind_speed_status_block.dart create mode 100644 lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart delete mode 100644 lib/screens/monitoring/wind_speed_monitoring_screen.dart diff --git a/lib/screens/home/views/home_screen.dart b/lib/screens/home/views/home_screen.dart index 27c4ebe..b933854 100644 --- a/lib/screens/home/views/home_screen.dart +++ b/lib/screens/home/views/home_screen.dart @@ -5,7 +5,7 @@ import 'package:firebase_database/firebase_database.dart'; import 'dart:async'; import '../../../blocs/authentication_bloc/authentication_bloc.dart'; import '../../monitoring/evaporasi_monitoring_screen.dart'; -import '../../monitoring/wind_speed_monitoring_screen.dart'; +import '../../monitoring/wind_speed/wind_speed_monitoring_screen.dart'; import '../../monitoring/air_quality_monitoring_screen.dart'; class HomeScreen extends StatefulWidget { diff --git a/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart b/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart new file mode 100644 index 0000000..7925fd1 --- /dev/null +++ b/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart @@ -0,0 +1,225 @@ +import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; + +import '../../widgets/monitoring_shared.dart'; + +class WindSpeedAnnualSection extends StatelessWidget { + final VoidCallback onExportAnnual; + + const WindSpeedAnnualSection({ + super.key, + required this.onExportAnnual, + }); + + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Statistik Tahunan Kecepatan Angin", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 15), + Row( + children: const [ + Expanded( + child: StatCard( + title: "Rata-rata Tahunan", + value: "7.1 km/h", + color: Colors.green, + icon: Icons.air, + ), + ), + SizedBox(width: 10), + Expanded( + child: StatCard( + title: "Kecepatan Max", + value: "16.5 km/h", + color: Colors.red, + icon: Icons.trending_up, + ), + ), + ], + ), + const SizedBox(height: 20), + const Text( + "Grafik Tahunan - Rata-rata & Kecepatan Maksimal", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + ), + ), + const SizedBox(height: 12), + Card( + elevation: 3, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: SizedBox( + height: 320, + child: LineChart( + LineChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 2, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.shade300, + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + lineBarsData: [ + LineChartBarData( + spots: const [ + FlSpot(0, 5.5), + FlSpot(1, 6.2), + FlSpot(2, 6.8), + FlSpot(3, 7.5), + FlSpot(4, 7.8), + FlSpot(5, 8.0), + FlSpot(6, 8.2), + FlSpot(7, 8.0), + FlSpot(8, 7.2), + FlSpot(9, 6.5), + FlSpot(10, 5.8), + FlSpot(11, 5.2), + ], + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.green, + strokeWidth: 0, + ); + }, + ), + color: Colors.green, + belowBarData: BarAreaData( + show: true, + color: Colors.green.withOpacity(0.1), + ), + ), + LineChartBarData( + spots: const [ + FlSpot(0, 12.0), + FlSpot(1, 13.5), + FlSpot(2, 14.0), + FlSpot(3, 15.5), + FlSpot(4, 16.0), + FlSpot(5, 16.2), + FlSpot(6, 16.5), + FlSpot(7, 16.0), + FlSpot(8, 15.0), + FlSpot(9, 14.0), + FlSpot(10, 12.5), + FlSpot(11, 11.0), + ], + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.red, + strokeWidth: 0, + ); + }, + ), + color: Colors.red, + ), + ], + ), + ), + ), + ), + ), + const SizedBox(height: 15), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.green, + borderRadius: BorderRadius.circular(3), + ), + ), + const SizedBox(width: 8), + const Text( + "Rata-rata (km/h)", + style: TextStyle(fontSize: 12), + ), + const SizedBox(width: 20), + Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(3), + ), + ), + const SizedBox(width: 8), + const Text( + "Kecepatan Max (km/h)", + style: TextStyle(fontSize: 12), + ), + ], + ), + const SizedBox(height: 15), + Center( + child: ElevatedButton.icon( + onPressed: onExportAnnual, + icon: const Icon(Icons.file_download), + label: const Text("Download Excel Tahunan"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.green, + foregroundColor: Colors.white, + ), + ), + ), + ], + ); + } +} diff --git a/lib/screens/monitoring/wind_speed/widgets/wind_speed_explanation.dart b/lib/screens/monitoring/wind_speed/widgets/wind_speed_explanation.dart new file mode 100644 index 0000000..6e6bb90 --- /dev/null +++ b/lib/screens/monitoring/wind_speed/widgets/wind_speed_explanation.dart @@ -0,0 +1,39 @@ +import 'package:flutter/material.dart'; + +class WindSpeedExplanation extends StatelessWidget { + const WindSpeedExplanation({super.key}); + + @override + Widget build(BuildContext context) { + return Container( + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.green.shade50, + borderRadius: BorderRadius.circular(12), + border: Border.all(color: Colors.green.shade200), + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: const [ + Text( + "Penjelasan Kecepatan Angin", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, + color: Colors.green, + ), + ), + SizedBox(height: 10), + Text( + "Kecepatan angin adalah laju gerakan massa udara yang mengalir secara horizontal. Data kecepatan angin penting untuk prediksi cuaca, manajemen rawan angin, perencanaan energi terbarukan (angin), serta membantu dalam pengeringan hasil pertanian. Pengukuran dilakukan dalam satuan km/h.", + style: TextStyle( + fontSize: 12, + height: 1.6, + color: Colors.green, + ), + ), + ], + ), + ); + } +} diff --git a/lib/screens/monitoring/wind_speed/widgets/wind_speed_graph_block.dart b/lib/screens/monitoring/wind_speed/widgets/wind_speed_graph_block.dart new file mode 100644 index 0000000..5a52f97 --- /dev/null +++ b/lib/screens/monitoring/wind_speed/widgets/wind_speed_graph_block.dart @@ -0,0 +1,249 @@ +import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; + +import '../../widgets/monitoring_shared.dart'; + +class WindSpeedGraphBlock extends StatelessWidget { + final String selectedPeriod; + final List dailySpeeds; + final bool isOnline; + final ValueChanged onPeriodChanged; + final ValueChanged onExportPressed; + + const WindSpeedGraphBlock({ + super.key, + required this.selectedPeriod, + required this.dailySpeeds, + required this.isOnline, + required this.onPeriodChanged, + required this.onExportPressed, + }); + + List _getPeriodSpots() { + switch (selectedPeriod) { + case "Hari Ini": + return List.generate(24, (i) { + final value = dailySpeeds[i]; + return FlSpot(i.toDouble(), value); + }); + case "Minggu Ini": + return const [ + FlSpot(0, 6.5), + FlSpot(1, 7.2), + FlSpot(2, 7.8), + FlSpot(3, 8.0), + FlSpot(4, 7.5), + FlSpot(5, 6.8), + FlSpot(6, 5.5), + ]; + case "Bulan Ini": + return const [ + FlSpot(0, 6.0), + FlSpot(1, 6.5), + FlSpot(2, 7.0), + FlSpot(3, 7.5), + FlSpot(4, 7.8), + FlSpot(5, 8.0), + FlSpot(6, 8.2), + FlSpot(7, 8.0), + FlSpot(8, 7.5), + FlSpot(9, 7.0), + FlSpot(10, 6.5), + FlSpot(11, 6.0), + ]; + default: + return []; + } + } + + @override + Widget build(BuildContext context) { + return Card( + elevation: 4, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + "Status Kecepatan Angin", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 5, + ), + decoration: BoxDecoration( + color: + isOnline ? Colors.green.shade100 : Colors.red.shade100, + borderRadius: BorderRadius.circular(20), + ), + child: Text( + isOnline ? "ONLINE" : "OFFLINE", + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.w600, + color: isOnline ? Colors.green : Colors.red, + ), + ), + ), + ], + ), + const SizedBox(height: 16), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: + ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { + return Padding( + padding: const EdgeInsets.only(right: 8), + child: ChoiceChip( + label: Text(period), + selected: selectedPeriod == period, + onSelected: (selected) { + if (selected) { + onPeriodChanged(period); + } + }, + selectedColor: Colors.green, + labelStyle: TextStyle( + color: selectedPeriod == period + ? Colors.white + : Colors.black, + ), + ), + ); + }).toList(), + ), + ), + ), + const SizedBox(width: 8), + ElevatedButton.icon( + onPressed: () => onExportPressed(selectedPeriod), + icon: const Icon(Icons.download, size: 16), + label: const Text("Export"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.orange, + foregroundColor: Colors.white, + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 6, + ), + textStyle: const TextStyle(fontSize: 11), + ), + ), + ], + ), + const SizedBox(height: 16), + SizedBox( + height: 300, + child: LineChart( + LineChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 1, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.shade300, + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: getPeriodInterval(selectedPeriod), + getTitlesWidget: (value, meta) { + return Text( + getPeriodLabel(selectedPeriod, value), + style: const TextStyle( + fontSize: 10, + color: Colors.grey, + ), + ); + }, + ), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: 1, + getTitlesWidget: (value, meta) { + return Text( + value.toInt().toString(), + style: const TextStyle( + fontSize: 9, + color: Colors.grey, + ), + ); + }, + reservedSize: 28, + ), + ), + topTitles: + AxisTitles(sideTitles: SideTitles(showTitles: false)), + rightTitles: + AxisTitles(sideTitles: SideTitles(showTitles: false)), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + lineBarsData: [ + LineChartBarData( + spots: _getPeriodSpots(), + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.green, + strokeWidth: 0, + ); + }, + ), + color: Colors.green, + belowBarData: BarAreaData( + show: true, + color: Colors.green.withOpacity(0.1), + ), + ), + ], + ), + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/screens/monitoring/wind_speed/widgets/wind_speed_status_block.dart b/lib/screens/monitoring/wind_speed/widgets/wind_speed_status_block.dart new file mode 100644 index 0000000..d3e5177 --- /dev/null +++ b/lib/screens/monitoring/wind_speed/widgets/wind_speed_status_block.dart @@ -0,0 +1,68 @@ +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +class WindSpeedStatusBlock extends StatelessWidget { + final double currentSpeed; + final bool isOnline; + final DateTime lastUpdateTime; + + const WindSpeedStatusBlock({ + super.key, + required this.currentSpeed, + required this.isOnline, + required this.lastUpdateTime, + }); + + @override + Widget build(BuildContext context) { + final formattedTime = + DateFormat("dd MMM yyyy • HH:mm:ss").format(lastUpdateTime); + return Padding( + padding: const EdgeInsets.only(bottom: 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "${currentSpeed.toStringAsFixed(2)} km/h", + style: const TextStyle( + fontSize: 28, + fontWeight: FontWeight.bold, + color: Colors.green, + ), + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 5, + ), + decoration: BoxDecoration( + color: isOnline ? Colors.green.shade100 : Colors.red.shade100, + borderRadius: BorderRadius.circular(20), + ), + child: Text( + isOnline ? "ONLINE" : "OFFLINE", + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.w600, + color: isOnline ? Colors.green : Colors.red, + ), + ), + ), + ], + ), + const SizedBox(height: 4), + Text( + "Update: $formattedTime", + style: const TextStyle( + fontSize: 12, + color: Colors.grey, + ), + ), + ], + ), + ); + } +} diff --git a/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart new file mode 100644 index 0000000..f315bf5 --- /dev/null +++ b/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart @@ -0,0 +1,328 @@ +import 'dart:async'; + +import 'package:firebase_database/firebase_database.dart'; +import 'package:flutter/material.dart'; + +import '../widgets/monitoring_shared.dart'; +import 'widgets/wind_speed_annual_section.dart'; +import 'widgets/wind_speed_explanation.dart'; +import 'widgets/wind_speed_graph_block.dart'; +import 'widgets/wind_speed_status_block.dart'; + +class WindSpeedMonitoringScreen extends StatefulWidget { + const WindSpeedMonitoringScreen({super.key}); + + @override + State createState() => + _WindSpeedMonitoringScreenState(); +} + +class _WindSpeedMonitoringScreenState extends State { + String _selectedPeriod = "Hari Ini"; + + // realtime database state + final DatabaseReference _realtimeRef = + FirebaseDatabase.instance.ref('anemometer/realtime'); + StreamSubscription? _realtimeSub; + + // realtime values + DateTime? _lastUpdateTime; + double _currentSpeed = 0.0; + final List _dailySpeeds = List.filled(24, 0.0); + + // hourly aggregation helpers (PRO version) + double _hourlyTotalSpeed = 0.0; + int _hourlyCount = 0; + int _currentHour = DateTime.now().hour; + + bool get _isOnline { + if (_lastUpdateTime == null) return false; + final diff = DateTime.now().difference(_lastUpdateTime!); + return diff.inSeconds <= 5; + } + + @override + void initState() { + super.initState(); + _realtimeSub = _realtimeRef.onValue.listen(_onRealtimeData); + } + + void _onRealtimeData(DatabaseEvent event) { + final data = event.snapshot.value; + + if (data is Map) { + final speed = (data['kecepatan'] ?? 0).toDouble(); + final timestamp = data['timestamp'] ?? 0; + + final waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + + setState(() { + _currentSpeed = speed; + _lastUpdateTime = waktu; + + final incomingHour = waktu.hour; + + if (incomingHour != _currentHour) { + if (_hourlyCount > 0) { + final avg = _hourlyTotalSpeed / _hourlyCount; + _dailySpeeds[_currentHour] = avg; + } + + _hourlyTotalSpeed = 0.0; + _hourlyCount = 0; + _currentHour = incomingHour; + + if (incomingHour == 0) { + for (int i = 0; i < 24; i++) { + _dailySpeeds[i] = 0.0; + } + } + } + + _hourlyTotalSpeed += speed; + _hourlyCount++; + }); + } + } + + @override + void dispose() { + _realtimeSub?.cancel(); + super.dispose(); + } + + void _handleExportSelectedPeriod(String period) { + switch (period) { + case "Hari Ini": + _exportDailyWindData(); + break; + case "Minggu Ini": + _exportWeeklyWindData(); + break; + case "Bulan Ini": + _exportMonthlyWindData(); + break; + } + } + + void _exportDailyWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - HARIAN (24 JAM)"); + csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); + csvContent.writeln(""); + csvContent.writeln("Jam,Kecepatan (km/h)"); + + final dailyData = [ + 5.0, + 5.2, + 4.8, + 4.5, + 4.3, + 4.6, + 5.1, + 6.0, + 7.2, + 8.5, + 9.0, + 10.2, + 11.0, + 10.5, + 10.0, + 9.2, + 8.0, + 6.5, + 5.5, + 5.0, + 4.8, + 4.5, + 5.0, + 5.2 + ]; + + for (int i = 0; i < dailyData.length; i++) { + csvContent.writeln("$i:00,${dailyData[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Harian"); + csvContent.writeln("Total: 165.8 km/h"); + csvContent.writeln("Rata-rata: 6.9 km/h"); + csvContent.writeln("Maksimal: 11.0 km/h"); + csvContent.writeln("Minimal: 4.3 km/h"); + + showExportPreview( + context, csvContent.toString(), "Data Harian Kecepatan Angin"); + } + + void _exportWeeklyWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - MINGGUAN"); + csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); + csvContent.writeln(""); + csvContent.writeln("Hari,Rata-rata (km/h)"); + + final days = [ + 'Senin', + 'Selasa', + 'Rabu', + 'Kamis', + 'Jumat', + 'Sabtu', + 'Minggu' + ]; + final weeklyData = [6.5, 7.2, 7.8, 8.0, 7.5, 6.8, 5.5]; + + for (int i = 0; i < days.length; i++) { + csvContent.writeln("${days[i]},${weeklyData[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Mingguan"); + csvContent.writeln("Total: 49.3 km/h"); + csvContent.writeln("Rata-rata: 7.0 km/h"); + csvContent.writeln("Maksimal: 8.0 km/h"); + csvContent.writeln("Minimal: 5.5 km/h"); + + showExportPreview( + context, csvContent.toString(), "Data Mingguan Kecepatan Angin"); + } + + void _exportMonthlyWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - BULANAN"); + csvContent.writeln( + "Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); + csvContent.writeln(""); + csvContent.writeln("Tanggal,Rata-rata (km/h)"); + + for (int i = 1; i <= 28; i++) { + final value = (6.0 + (i % 6) * 0.8).toStringAsFixed(1); + csvContent.writeln("$i,$value"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Bulanan"); + csvContent.writeln("Total: 180.5 km/h"); + csvContent.writeln("Rata-rata: 6.4 km/h"); + csvContent.writeln("Maksimal: 9.0 km/h"); + csvContent.writeln("Minimal: 4.0 km/h"); + + showExportPreview( + context, csvContent.toString(), "Data Bulanan Kecepatan Angin"); + } + + void _exportAnnualWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - TAHUNAN"); + csvContent.writeln("Tahun: 2025"); + csvContent.writeln(""); + csvContent.writeln("Bulan,Rata-rata (km/h),Kecepatan Max (km/h)"); + + final months = [ + 'Januari', + 'Februari', + 'Maret', + 'April', + 'Mei', + 'Juni', + 'Juli', + 'Agustus', + 'September', + 'Oktober', + 'November', + 'Desember' + ]; + final averages = [ + 5.5, + 6.2, + 6.8, + 7.5, + 7.8, + 8.0, + 8.2, + 8.0, + 7.2, + 6.5, + 5.8, + 5.2 + ]; + final maxSpeed = [ + 12.0, + 13.5, + 14.0, + 15.5, + 16.0, + 16.2, + 16.5, + 16.0, + 15.0, + 14.0, + 12.5, + 11.0 + ]; + + for (int i = 0; i < months.length; i++) { + csvContent.writeln("${months[i]},${averages[i]},${maxSpeed[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("STATISTIK TAHUNAN"); + csvContent.writeln("Rata-rata Tahunan: 7.1 km/h"); + csvContent.writeln("Kecepatan Max Tertinggi: 16.5 km/h"); + csvContent.writeln("Kecepatan Min Terendah: 5.2 km/h"); + + showExportPreview( + context, csvContent.toString(), "Data Tahunan Kecepatan Angin"); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text("Monitoring Kecepatan Angin"), + centerTitle: true, + ), + body: Padding( + padding: const EdgeInsets.all(16), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Kecepatan Angin", + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 20), + if (_lastUpdateTime != null) + WindSpeedStatusBlock( + currentSpeed: _currentSpeed, + isOnline: _isOnline, + lastUpdateTime: _lastUpdateTime!, + ), + WindSpeedGraphBlock( + selectedPeriod: _selectedPeriod, + dailySpeeds: _dailySpeeds, + isOnline: _isOnline, + onPeriodChanged: (period) { + setState(() { + _selectedPeriod = period; + }); + }, + onExportPressed: _handleExportSelectedPeriod, + ), + const SizedBox(height: 25), + const WindSpeedExplanation(), + const SizedBox(height: 25), + WindSpeedAnnualSection( + onExportAnnual: _exportAnnualWindData, + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/screens/monitoring/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed_monitoring_screen.dart deleted file mode 100644 index f619d54..0000000 --- a/lib/screens/monitoring/wind_speed_monitoring_screen.dart +++ /dev/null @@ -1,815 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:fl_chart/fl_chart.dart'; -import 'package:firebase_database/firebase_database.dart'; -import 'dart:async'; -import 'widgets/monitoring_shared.dart'; -import 'package:intl/intl.dart'; - -/// WIND SPEED MONITORING SCREEN -class WindSpeedMonitoringScreen extends StatefulWidget { - const WindSpeedMonitoringScreen({super.key}); - - @override - State createState() => _WindSpeedMonitoringScreenState(); -} - -class _WindSpeedMonitoringScreenState extends State { - String _selectedPeriod = "Hari Ini"; - - // realtime database state - final DatabaseReference _realtimeRef = FirebaseDatabase.instance.ref('anemometer/realtime'); - StreamSubscription? _realtimeSub; - - // realtime values - DateTime? _lastUpdateTime; - double _currentSpeed = 0.0; - final List _dailySpeeds = List.filled(24, 0.0); - - // hourly aggregation helpers (PRO version) - double _hourlyTotalSpeed = 0.0; - int _hourlyCount = 0; - int _currentHour = DateTime.now().hour; - - bool get _isOnline { - if (_lastUpdateTime == null) return false; - final diff = DateTime.now().difference(_lastUpdateTime!); - return diff.inSeconds <= 5; - } - - - @override - void initState() { - super.initState(); - _realtimeSub = _realtimeRef.onValue.listen(_onRealtimeData); - } - - void _onRealtimeData(DatabaseEvent event) { - final data = event.snapshot.value; - - if (data is Map) { - final speed = (data['kecepatan'] ?? 0).toDouble(); - final timestamp = data['timestamp'] ?? 0; - - final waktu = DateTime.fromMillisecondsSinceEpoch( - timestamp * 1000, - ); - - setState(() { - _currentSpeed = speed; - _lastUpdateTime = waktu; - - final incomingHour = waktu.hour; - - // Jika jam berubah → simpan rata-rata jam sebelumnya - if (incomingHour != _currentHour) { - - if (_hourlyCount > 0) { - final avg = _hourlyTotalSpeed / _hourlyCount; - - // Simpan ke index sesuai jam sebelumnya - _dailySpeeds[_currentHour] = avg; - } - - // Reset agregasi - _hourlyTotalSpeed = 0.0; - _hourlyCount = 0; - - _currentHour = incomingHour; - - // Reset data saat masuk hari baru (00:00) - if (incomingHour == 0) { - for (int i = 0; i < 24; i++) { - _dailySpeeds[i] = 0.0; - } - } - } - - // Tambah akumulasi - _hourlyTotalSpeed += speed; - _hourlyCount++; - }); - } -} - - @override - void dispose() { - _realtimeSub?.cancel(); - super.dispose(); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text("Monitoring Kecepatan Angin"), - centerTitle: true, - ), - body: Padding( - padding: const EdgeInsets.all(16), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - "Kecepatan Angin", - style: TextStyle( - fontSize: 22, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 20), - if (_lastUpdateTime != null) - Padding( - padding: const EdgeInsets.only(bottom: 12), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "${_currentSpeed.toStringAsFixed(2)} km/h", - style: const TextStyle( - fontSize: 28, - fontWeight: FontWeight.bold, - color: Colors.green, - ), - ), - Container( - padding: const EdgeInsets.symmetric( - horizontal: 10, - vertical: 5, - ), - decoration: BoxDecoration( - color: _isOnline - ? Colors.green.shade100 - : Colors.red.shade100, - borderRadius: BorderRadius.circular(20), - ), - child: Text( - _isOnline ? "ONLINE" : "OFFLINE", - style: TextStyle( - fontSize: 11, - fontWeight: FontWeight.w600, - color: _isOnline ? Colors.green : Colors.red, - ), - ), - ), - ], - ), - const SizedBox(height: 4), - Builder( - builder: (_) { - final formattedTime = DateFormat( - "dd MMM yyyy • HH:mm:ss", - ).format(_lastUpdateTime!); - return Text( - "Update: $formattedTime", - style: const TextStyle( - fontSize: 12, - color: Colors.grey, - ), - ); - }, - ), - ], - ), - ), - /// GRAFIK MONITORING - _buildMonitoringGraphBlock(), - const SizedBox(height: 25), - - /// PENJELASAN - _buildWindSpeedExplanation(), - const SizedBox(height: 25), - - /// STATISTIK TAHUNAN - _buildAnnualWindGraphSection(), - ], - ), - ), - ), - ); - } - - /// EXPORT FUNCTIONS - void _exportDailyWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - HARIAN (24 JAM)"); - csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); - csvContent.writeln(""); - csvContent.writeln("Jam,Kecepatan (km/h)"); - - final dailyData = [ - 5.0, 5.2, 4.8, 4.5, 4.3, 4.6, 5.1, 6.0, 7.2, 8.5, - 9.0, 10.2, 11.0, 10.5, 10.0, 9.2, 8.0, 6.5, 5.5, 5.0, 4.8, 4.5, 5.0, 5.2 - ]; - for (int i = 0; i < dailyData.length; i++) { - csvContent.writeln("$i:00,${dailyData[i]}"); - } - - csvContent.writeln(""); - csvContent.writeln("Statistik Harian"); - csvContent.writeln("Total: 165.8 km/h"); - csvContent.writeln("Rata-rata: 6.9 km/h"); - csvContent.writeln("Maksimal: 11.0 km/h"); - csvContent.writeln("Minimal: 4.3 km/h"); - - showExportPreview(context, csvContent.toString(), "Data Harian Kecepatan Angin"); - } - - void _exportWeeklyWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - MINGGUAN"); - csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); - csvContent.writeln(""); - csvContent.writeln("Hari,Rata-rata (km/h)"); - - final days = ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu']; - final weeklyData = [6.5, 7.2, 7.8, 8.0, 7.5, 6.8, 5.5]; - - for (int i = 0; i < days.length; i++) { - csvContent.writeln("${days[i]},${weeklyData[i]}"); - } - - csvContent.writeln(""); - csvContent.writeln("Statistik Mingguan"); - csvContent.writeln("Total: 49.3 km/h"); - csvContent.writeln("Rata-rata: 7.0 km/h"); - csvContent.writeln("Maksimal: 8.0 km/h"); - csvContent.writeln("Minimal: 5.5 km/h"); - - showExportPreview(context, csvContent.toString(), "Data Mingguan Kecepatan Angin"); - } - - void _exportMonthlyWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - BULANAN"); - csvContent.writeln("Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); - csvContent.writeln(""); - csvContent.writeln("Tanggal,Rata-rata (km/h)"); - - for (int i = 1; i <= 28; i++) { - final value = (6.0 + (i % 6) * 0.8).toStringAsFixed(1); - csvContent.writeln("$i,$value"); - } - - csvContent.writeln(""); - csvContent.writeln("Statistik Bulanan"); - csvContent.writeln("Total: 180.5 km/h"); - csvContent.writeln("Rata-rata: 6.4 km/h"); - csvContent.writeln("Maksimal: 9.0 km/h"); - csvContent.writeln("Minimal: 4.0 km/h"); - - showExportPreview(context, csvContent.toString(), "Data Bulanan Kecepatan Angin"); - } - - void _exportAnnualWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - TAHUNAN"); - csvContent.writeln("Tahun: 2025"); - csvContent.writeln(""); - csvContent.writeln("Bulan,Rata-rata (km/h),Kecepatan Max (km/h)"); - - final months = [ - 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', - 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' - ]; - final averages = [5.5, 6.2, 6.8, 7.5, 7.8, 8.0, 8.2, 8.0, 7.2, 6.5, 5.8, 5.2]; - final maxSpeed = [12.0, 13.5, 14.0, 15.5, 16.0, 16.2, 16.5, 16.0, 15.0, 14.0, 12.5, 11.0]; - - for (int i = 0; i < months.length; i++) { - csvContent.writeln("${months[i]},${averages[i]},${maxSpeed[i]}"); - } - - csvContent.writeln(""); - csvContent.writeln("STATISTIK TAHUNAN"); - csvContent.writeln("Rata-rata Tahunan: 7.1 km/h"); - csvContent.writeln("Kecepatan Max Tertinggi: 16.5 km/h"); - csvContent.writeln("Kecepatan Min Terendah: 5.2 km/h"); - - showExportPreview(context, csvContent.toString(), "Data Tahunan Kecepatan Angin"); - } - - /// DATA GENERATORS - List _getWindSpeedPeriodData() { - switch (_selectedPeriod) { - case "Hari Ini": - // use live-updated hourly speeds if available - return List.generate(24, (i) { - final value = _dailySpeeds[i]; - return FlSpot(i.toDouble(), value); - }); - case "Minggu Ini": - return [ - const FlSpot(0, 6.5), - const FlSpot(1, 7.2), - const FlSpot(2, 7.8), - const FlSpot(3, 8.0), - const FlSpot(4, 7.5), - const FlSpot(5, 6.8), - const FlSpot(6, 5.5), - ]; - case "Bulan Ini": - return [ - const FlSpot(0, 6.0), - const FlSpot(1, 6.5), - const FlSpot(2, 7.0), - const FlSpot(3, 7.5), - const FlSpot(4, 7.8), - const FlSpot(5, 8.0), - const FlSpot(6, 8.2), - const FlSpot(7, 8.0), - const FlSpot(8, 7.5), - const FlSpot(9, 7.0), - const FlSpot(10, 6.5), - const FlSpot(11, 6.0), - ]; - default: - return []; - } - } - - /// UI BUILDERS - Widget _buildMonitoringGraphBlock() { - return Card( - elevation: 4, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - child: Padding( - padding: const EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text( - "Status Kecepatan Angin", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - Container( - padding: const EdgeInsets.symmetric( - horizontal: 10, - vertical: 5, - ), - decoration: BoxDecoration( - color: _isOnline ? Colors.green.shade100 : Colors.red.shade100, - borderRadius: BorderRadius.circular(20), - ), - child: Text( - _isOnline ? "ONLINE" : "OFFLINE", - style: TextStyle( - fontSize: 11, - fontWeight: FontWeight.w600, - color: _isOnline ? Colors.green : Colors.red, - ), - ), - ), - ], - ), - const SizedBox(height: 16), - - /// PERIOD SELECTOR + EXPORT - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Row( - children: ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { - return Padding( - padding: const EdgeInsets.only(right: 8), - child: ChoiceChip( - label: Text(period), - selected: _selectedPeriod == period, - onSelected: (selected) { - setState(() { - _selectedPeriod = period; - }); - }, - selectedColor: Colors.green, - labelStyle: TextStyle( - color: _selectedPeriod == period - ? Colors.white - : Colors.black, - ), - ), - ); - }).toList(), - ), - ), - ), - const SizedBox(width: 8), - ElevatedButton.icon( - onPressed: () { - if (_selectedPeriod == "Hari Ini") { - _exportDailyWindData(); - } else if (_selectedPeriod == "Minggu Ini") { - _exportWeeklyWindData(); - } else if (_selectedPeriod == "Bulan Ini") { - _exportMonthlyWindData(); - } - }, - icon: const Icon(Icons.download, size: 16), - label: const Text("Export"), - style: ElevatedButton.styleFrom( - backgroundColor: Colors.orange, - foregroundColor: Colors.white, - padding: const EdgeInsets.symmetric( - horizontal: 10, - vertical: 6, - ), - textStyle: const TextStyle(fontSize: 11), - ), - ), - ], - ), - const SizedBox(height: 16), - - /// GRAPH - SizedBox( - height: 300, - child: LineChart( - LineChartData( - gridData: FlGridData( - show: true, - drawHorizontalLine: true, - drawVerticalLine: false, - horizontalInterval: 1, - getDrawingHorizontalLine: (value) { - return FlLine( - color: Colors.grey.shade300, - strokeWidth: 1, - ); - }, - ), - titlesData: FlTitlesData( - show: true, - bottomTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - interval: getPeriodInterval(_selectedPeriod), - getTitlesWidget: (value, meta) { - return Text( - getPeriodLabel(_selectedPeriod, value), - style: const TextStyle( - fontSize: 10, - color: Colors.grey, - ), - ); - }, - ), - ), - leftTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - interval: 1, - getTitlesWidget: (value, meta) { - return Text( - value.toInt().toString(), - style: const TextStyle( - fontSize: 9, - color: Colors.grey, - ), - ); - }, - reservedSize: 28, - ), - ), - topTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - rightTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - ), - borderData: FlBorderData( - show: true, - border: Border( - left: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - bottom: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - ), - ), - lineBarsData: [ - LineChartBarData( - spots: _getWindSpeedPeriodData(), // uses _dailySpeeds now - isCurved: true, - barWidth: 2.5, - dotData: FlDotData( - show: true, - getDotPainter: (spot, percent, barData, index) { - return FlDotCirclePainter( - radius: 4, - color: Colors.green, - strokeWidth: 0, - ); - }, - ), - color: Colors.green, - belowBarData: BarAreaData( - show: true, - color: Colors.green.withOpacity(0.1), - ), - ), - ], - ), - ), - ), - ], - ), - ), - ); - } - - Widget _buildWindSpeedExplanation() { - return Container( - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.green.shade50, - borderRadius: BorderRadius.circular(12), - border: Border.all(color: Colors.green.shade200), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - "Penjelasan Kecepatan Angin", - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.bold, - color: Colors.green, - ), - ), - const SizedBox(height: 10), - const Text( - "Kecepatan angin adalah laju gerakan massa udara yang mengalir secara horizontal. Data kecepatan angin penting untuk prediksi cuaca, manajemen rawan angin, perencanaan energi terbarukan (angin), serta membantu dalam pengeringan hasil pertanian. Pengukuran dilakukan dalam satuan km/h.", - style: TextStyle( - fontSize: 12, - height: 1.6, - color: Colors.green, - ), - ), - ], - ), - ); - } - - Widget _buildAnnualWindGraphSection() { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - "Statistik Tahunan Kecepatan Angin", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 15), - - /// STATS - Row( - children: [ - Expanded( - child: StatCard( - title: "Rata-rata Tahunan", - value: "7.1 km/h", - color: Colors.green, - icon: Icons.air, - ), - ), - const SizedBox(width: 10), - Expanded( - child: StatCard( - title: "Kecepatan Max", - value: "16.5 km/h", - color: Colors.red, - icon: Icons.trending_up, - ), - ), - ], - ), - const SizedBox(height: 20), - - /// CHART - const Text( - "Grafik Tahunan - Rata-rata & Kecepatan Maksimal", - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w600, - ), - ), - const SizedBox(height: 12), - Card( - elevation: 3, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - child: Padding( - padding: const EdgeInsets.all(16), - child: SizedBox( - height: 320, - child: LineChart( - LineChartData( - gridData: FlGridData( - show: true, - drawHorizontalLine: true, - drawVerticalLine: false, - horizontalInterval: 2, - getDrawingHorizontalLine: (value) { - return FlLine( - color: Colors.grey.shade300, - strokeWidth: 1, - ); - }, - ), - titlesData: FlTitlesData( - show: true, - bottomTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - getTitlesWidget: (value, meta) { - final months = [ - 'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', - 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des' - ]; - return Text( - months[value.toInt()], - style: const TextStyle( - fontSize: 10, - color: Colors.grey, - ), - ); - }, - reservedSize: 30, - ), - ), - leftTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - getTitlesWidget: (value, meta) { - return Text( - '${value.toInt()} km/h', - style: const TextStyle( - fontSize: 9, - color: Colors.grey, - ), - ); - }, - reservedSize: 50, - ), - ), - rightTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - topTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - ), - borderData: FlBorderData( - show: true, - border: Border( - left: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - bottom: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - ), - ), - lineBarsData: [ - /// Rata-rata - LineChartBarData( - spots: const [ - FlSpot(0, 5.5), - FlSpot(1, 6.2), - FlSpot(2, 6.8), - FlSpot(3, 7.5), - FlSpot(4, 7.8), - FlSpot(5, 8.0), - FlSpot(6, 8.2), - FlSpot(7, 8.0), - FlSpot(8, 7.2), - FlSpot(9, 6.5), - FlSpot(10, 5.8), - FlSpot(11, 5.2), - ], - isCurved: true, - barWidth: 2.5, - dotData: FlDotData( - show: true, - getDotPainter: (spot, percent, barData, index) { - return FlDotCirclePainter( - radius: 4, - color: Colors.green, - strokeWidth: 0, - ); - }, - ), - color: Colors.green, - belowBarData: BarAreaData( - show: true, - color: Colors.green.withOpacity(0.1), - ), - ), - /// Max Speed - LineChartBarData( - spots: const [ - FlSpot(0, 12.0), - FlSpot(1, 13.5), - FlSpot(2, 14.0), - FlSpot(3, 15.5), - FlSpot(4, 16.0), - FlSpot(5, 16.2), - FlSpot(6, 16.5), - FlSpot(7, 16.0), - FlSpot(8, 15.0), - FlSpot(9, 14.0), - FlSpot(10, 12.5), - FlSpot(11, 11.0), - ], - isCurved: true, - barWidth: 2.5, - dotData: FlDotData( - show: true, - getDotPainter: (spot, percent, barData, index) { - return FlDotCirclePainter( - radius: 4, - color: Colors.red, - strokeWidth: 0, - ); - }, - ), - color: Colors.red, - ), - ], - ), - ), - ), - ), - ), - const SizedBox(height: 15), - - /// LEGEND - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - width: 16, - height: 16, - decoration: BoxDecoration( - color: Colors.green, - borderRadius: BorderRadius.circular(3), - ), - ), - const SizedBox(width: 8), - const Text( - "Rata-rata (km/h)", - style: TextStyle(fontSize: 12), - ), - const SizedBox(width: 20), - Container( - width: 16, - height: 16, - decoration: BoxDecoration( - color: Colors.red, - borderRadius: BorderRadius.circular(3), - ), - ), - const SizedBox(width: 8), - const Text( - "Kecepatan Max (km/h)", - style: TextStyle(fontSize: 12), - ), - ], - ), - const SizedBox(height: 15), - Center( - child: ElevatedButton.icon( - onPressed: () => _exportAnnualWindData(), - icon: const Icon(Icons.file_download), - label: const Text("Download Excel Tahunan"), - style: ElevatedButton.styleFrom( - backgroundColor: Colors.green, - foregroundColor: Colors.white, - ), - ), - ), - ], - ); - } -} From e449c50bb3eb835c73903d82fbc1c40724738067 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Sat, 11 Apr 2026 11:18:23 +0700 Subject: [PATCH 20/28] ok --- .../widgets/wind_speed_annual_section.dart | 9 +- .../wind_speed_monitoring_screen.dart | 8 +- linux/flutter/generated_plugins.cmake | 1 + pubspec.lock | 196 +++++++++++++++++- pubspec.yaml | 28 +-- windows/flutter/generated_plugins.cmake | 1 + 6 files changed, 222 insertions(+), 21 deletions(-) diff --git a/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart b/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart index 7925fd1..9fa9922 100644 --- a/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart +++ b/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart @@ -10,7 +10,8 @@ class WindSpeedAnnualSection extends StatelessWidget { super.key, required this.onExportAnnual, }); - + final double _rataRata = 0.0; + final double _kecepatanMax = 0.0; @override Widget build(BuildContext context) { return Column( @@ -25,11 +26,11 @@ class WindSpeedAnnualSection extends StatelessWidget { ), const SizedBox(height: 15), Row( - children: const [ + children: [ Expanded( child: StatCard( title: "Rata-rata Tahunan", - value: "7.1 km/h", + value: this._rataRata.toStringAsFixed(2), color: Colors.green, icon: Icons.air, ), @@ -38,7 +39,7 @@ class WindSpeedAnnualSection extends StatelessWidget { Expanded( child: StatCard( title: "Kecepatan Max", - value: "16.5 km/h", + value: this._kecepatanMax.toStringAsFixed(2), color: Colors.red, icon: Icons.trending_up, ), diff --git a/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart index f315bf5..cbddc47 100644 --- a/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart +++ b/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart @@ -8,6 +8,7 @@ import 'widgets/wind_speed_annual_section.dart'; import 'widgets/wind_speed_explanation.dart'; import 'widgets/wind_speed_graph_block.dart'; import 'widgets/wind_speed_status_block.dart'; +import 'package:google_fonts/google_fonts.dart'; class WindSpeedMonitoringScreen extends StatefulWidget { const WindSpeedMonitoringScreen({super.key}); @@ -279,8 +280,13 @@ class _WindSpeedMonitoringScreenState extends State { Widget build(BuildContext context) { return Scaffold( appBar: AppBar( - title: const Text("Monitoring Kecepatan Angin"), + title: Text( + "Wind Speed", + style: GoogleFonts.rubik( + color: Colors.black, fontWeight: FontWeight.bold), + ), centerTitle: true, + backgroundColor: const Color.fromARGB(37, 158, 158, 158), ), body: Padding( padding: const EdgeInsets.all(16), diff --git a/linux/flutter/generated_plugins.cmake b/linux/flutter/generated_plugins.cmake index 2e1de87..be1ee3e 100644 --- a/linux/flutter/generated_plugins.cmake +++ b/linux/flutter/generated_plugins.cmake @@ -6,6 +6,7 @@ list(APPEND FLUTTER_PLUGIN_LIST ) list(APPEND FLUTTER_FFI_PLUGIN_LIST + jni ) set(PLUGIN_BUNDLED_LIBRARIES) diff --git a/pubspec.lock b/pubspec.lock index f2d3ad9..db41fa9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -9,6 +9,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.66" + args: + dependency: transitive + description: + name: args + sha256: d0481093c50b1da8910eb0bb301626d4d8eb7284aa739614d2b394ee09e3ea04 + url: "https://pub.dev" + source: hosted + version: "2.7.0" async: dependency: transitive description: @@ -73,6 +81,14 @@ packages: url: "https://pub.dev" source: hosted version: "5.1.1" + code_assets: + dependency: transitive + description: + name: code_assets + sha256: "83ccdaa064c980b5596c35dd64a8d3ecc68620174ab9b90b6343b753aa721687" + url: "https://pub.dev" + source: hosted + version: "1.0.0" collection: dependency: transitive description: @@ -81,6 +97,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.19.1" + crypto: + dependency: transitive + description: + name: crypto + sha256: c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf + url: "https://pub.dev" + source: hosted + version: "3.0.7" cupertino_icons: dependency: "direct main" description: @@ -105,6 +129,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.3.3" + ffi: + dependency: transitive + description: + name: ffi + sha256: "6d7fd89431262d8f3125e81b50d3847a091d846eafcd4fdb88dd06f36d705a45" + url: "https://pub.dev" + source: hosted + version: "2.2.0" + file: + dependency: transitive + description: + name: file + sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4 + url: "https://pub.dev" + source: hosted + version: "7.0.1" firebase_auth: dependency: "direct main" description: @@ -216,6 +256,22 @@ packages: description: flutter source: sdk version: "0.0.0" + glob: + dependency: transitive + description: + name: glob + sha256: c3f1ee72c96f8f78935e18aa8cecced9ab132419e8625dc187e1c2408efc20de + url: "https://pub.dev" + source: hosted + version: "2.1.3" + google_fonts: + dependency: "direct main" + description: + name: google_fonts + sha256: db9df7a5898d894eeda4c78143f35c30a243558be439518972366880b80bf88e + url: "https://pub.dev" + source: hosted + version: "8.0.2" google_identity_services_web: dependency: transitive description: @@ -264,6 +320,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + hooks: + dependency: transitive + description: + name: hooks + sha256: e79ed1e8e1929bc6ecb6ec85f0cb519c887aa5b423705ded0d0f2d9226def388 + url: "https://pub.dev" + source: hosted + version: "1.0.2" http: dependency: transitive description: @@ -288,6 +352,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.20.2" + jni: + dependency: transitive + description: + name: jni + sha256: c2230682d5bc2362c1c9e8d3c7f406d9cbba23ab3f2e203a025dd47e0fb2e68f + url: "https://pub.dev" + source: hosted + version: "1.0.0" + jni_flutter: + dependency: transitive + description: + name: jni_flutter + sha256: "8b59e590786050b1cd866677dddaf76b1ade5e7bc751abe04b86e84d379d3ba6" + url: "https://pub.dev" + source: hosted + version: "1.0.1" leak_tracker: dependency: transitive description: @@ -320,6 +400,14 @@ packages: url: "https://pub.dev" source: hosted version: "3.0.0" + logging: + dependency: transitive + description: + name: logging + sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61 + url: "https://pub.dev" + source: hosted + version: "1.3.0" matcher: dependency: transitive description: @@ -344,6 +432,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.17.0" + native_toolchain_c: + dependency: transitive + description: + name: native_toolchain_c + sha256: "6ba77bb18063eebe9de401f5e6437e95e1438af0a87a3a39084fbd37c90df572" + url: "https://pub.dev" + source: hosted + version: "0.17.6" nested: dependency: transitive description: @@ -352,6 +448,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + objective_c: + dependency: transitive + description: + name: objective_c + sha256: "100a1c87616ab6ed41ec263b083c0ef3261ee6cd1dc3b0f35f8ddfa4f996fe52" + url: "https://pub.dev" + source: hosted + version: "9.3.0" + package_config: + dependency: transitive + description: + name: package_config + sha256: f096c55ebb7deb7e384101542bfba8c52696c1b56fca2eb62827989ef2353bbc + url: "https://pub.dev" + source: hosted + version: "2.2.0" path: dependency: transitive description: @@ -360,6 +472,62 @@ packages: url: "https://pub.dev" source: hosted version: "1.9.1" + path_provider: + dependency: transitive + description: + name: path_provider + sha256: "50c5dd5b6e1aaf6fb3a78b33f6aa3afca52bf903a8a5298f53101fdaee55bbcd" + url: "https://pub.dev" + source: hosted + version: "2.1.5" + path_provider_android: + dependency: transitive + description: + name: path_provider_android + sha256: "69cbd515a62b94d32a7944f086b2f82b4ac40a1d45bebfc00813a430ab2dabcd" + url: "https://pub.dev" + source: hosted + version: "2.3.1" + path_provider_foundation: + dependency: transitive + description: + name: path_provider_foundation + sha256: "2a376b7d6392d80cd3705782d2caa734ca4727776db0b6ec36ef3f1855197699" + url: "https://pub.dev" + source: hosted + version: "2.6.0" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279 + url: "https://pub.dev" + source: hosted + version: "2.2.1" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7 + url: "https://pub.dev" + source: hosted + version: "2.3.0" + platform: + dependency: transitive + description: + name: platform + sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984" + url: "https://pub.dev" + source: hosted + version: "3.1.6" plugin_platform_interface: dependency: transitive description: @@ -376,6 +544,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.1.5+1" + pub_semver: + dependency: transitive + description: + name: pub_semver + sha256: "5bfcf68ca79ef689f8990d1160781b4bad40a3bd5e5218ad4076ddb7f4081585" + url: "https://pub.dev" + source: hosted + version: "2.2.0" rxdart: dependency: "direct main" description: @@ -476,6 +652,22 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15" + url: "https://pub.dev" + source: hosted + version: "1.1.0" + yaml: + dependency: transitive + description: + name: yaml + sha256: b9da305ac7c39faa3f030eccd175340f968459dae4af175130b3fc47e40d76ce + url: "https://pub.dev" + source: hosted + version: "3.1.3" sdks: - dart: ">=3.9.0 <4.0.0" - flutter: ">=3.35.0" + dart: ">=3.10.3 <4.0.0" + flutter: ">=3.38.4" diff --git a/pubspec.yaml b/pubspec.yaml index 699ec7f..179a7fd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -5,29 +5,29 @@ version: 1.0.0+1 environment: sdk: ^3.1.0 dependencies: + bloc: ^8.1.0 + cloud_firestore: ^6.1.1 + cupertino_icons: ^1.0.8 + equatable: ^2.0.5 + firebase_auth: ^6.1.3 + firebase_core: ^4.3.0 + firebase_database: ^12.1.3 + fl_chart: ^1.1.1 flutter: sdk: flutter - firebase_core: ^4.3.0 - firebase_auth: ^6.1.3 - cloud_firestore: ^6.1.1 - rxdart: ^0.27.7 - google_sign_in: ^7.2.0 - bloc: ^8.1.0 flutter_bloc: ^8.1.0 - equatable: ^2.0.5 + google_fonts: ^8.0.2 + google_sign_in: ^7.2.0 + intl: ^0.20.2 + rxdart: ^0.27.7 user_repository: path: packages/user_repository - cupertino_icons: ^1.0.8 - fl_chart: ^1.1.1 - firebase_database: ^12.1.3 - intl: ^0.20.2 dev_dependencies: + flutter_lints: ^3.0.0 flutter_test: sdk: flutter - flutter_lints: ^3.0.0 flutter: uses-material-design: true - # assets: - # - assets/images/ \ No newline at end of file + # - assets/images/ diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index b83b40a..37c2b78 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -9,6 +9,7 @@ list(APPEND FLUTTER_PLUGIN_LIST ) list(APPEND FLUTTER_FFI_PLUGIN_LIST + jni ) set(PLUGIN_BUNDLED_LIBRARIES) From 5d7d61fbaac81be949c7479100d6d6338bd6cf58 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Sat, 11 Apr 2026 11:19:15 +0700 Subject: [PATCH 21/28] sa --- .../wind_speed/widgets/wind_speed_annual_section.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart b/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart index 9fa9922..60806c7 100644 --- a/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart +++ b/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart @@ -142,7 +142,7 @@ class WindSpeedAnnualSection extends StatelessWidget { ), LineChartBarData( spots: const [ - FlSpot(0, 12.0), + FlSpot(0, 12.0), //sadds FlSpot(1, 13.5), FlSpot(2, 14.0), FlSpot(3, 15.5), From 3675c0188dab389845c9a56f692999b69a770d63 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Sun, 12 Apr 2026 13:55:12 +0700 Subject: [PATCH 22/28] oke --- lib/app.dart | 12 +- .../monitoring_bloc/monitoring_bloc.dart | 50 +++ .../monitoring_bloc/monitoring_event.dart | 25 ++ .../monitoring_bloc/monitoring_state.dart | 34 ++ lib/main.dart | 8 +- lib/screens/home/blocs/home_bloc.dart | 0 lib/screens/home/blocs/home_event.dart | 0 lib/screens/home/blocs/home_state.dart | 0 lib/screens/home/views/home_screen.dart | 2 +- .../air_quality_monitoring_screen.dart | 147 +++++++-- .../evaporasi_monitoring_screen.dart | 2 +- .../widgets/monitoring_shared.dart | 0 .../wind_speed/blocs/wind_speed_bloc.dart | 15 + .../wind_speed/blocs/wind_speed_event.dart | 0 .../wind_speed/blocs/wind_speed_state.dart | 0 .../wind_speed/views/annual_section.dart | 226 ++++++++++++++ .../explanation.dart} | 18 +- .../wind_speed/views/graph_block.dart | 253 +++++++++++++++ .../wind_speed/views/status_block.dart | 95 ++++++ .../wind_speed_annual_section.dart | 10 +- .../wind_speed_graph_block.dart | 16 +- .../widgets/wind_speed_status_block.dart | 68 ---- .../monitoring/wind_speed/wind_speed.dart | 272 ++++++++++++++++ .../wind_speed_monitoring_screen.dart | 94 +----- .../lib/monitoring_repository.dart | 4 + .../lib/src/firebase_monitoring_repo.dart | 23 ++ .../lib/src/models/models.dart | 1 + .../lib/src/models/wind_speed.dart | 21 ++ .../lib/src/monitoring_repo.dart | 7 + packages/monitoring_repository/pubspec.lock | 290 ++++++++++++++++++ packages/monitoring_repository/pubspec.yaml | 56 ++++ pubspec.lock | 9 +- pubspec.yaml | 4 +- test/widget_test.dart | 71 ++++- 34 files changed, 1630 insertions(+), 203 deletions(-) create mode 100644 lib/blocs/monitoring_bloc/monitoring_bloc.dart create mode 100644 lib/blocs/monitoring_bloc/monitoring_event.dart create mode 100644 lib/blocs/monitoring_bloc/monitoring_state.dart create mode 100644 lib/screens/home/blocs/home_bloc.dart create mode 100644 lib/screens/home/blocs/home_event.dart create mode 100644 lib/screens/home/blocs/home_state.dart rename lib/screens/monitoring/{ => shared}/widgets/monitoring_shared.dart (100%) create mode 100644 lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart create mode 100644 lib/screens/monitoring/wind_speed/blocs/wind_speed_event.dart create mode 100644 lib/screens/monitoring/wind_speed/blocs/wind_speed_state.dart create mode 100644 lib/screens/monitoring/wind_speed/views/annual_section.dart rename lib/screens/monitoring/wind_speed/{widgets/wind_speed_explanation.dart => views/explanation.dart} (70%) create mode 100644 lib/screens/monitoring/wind_speed/views/graph_block.dart create mode 100644 lib/screens/monitoring/wind_speed/views/status_block.dart rename lib/screens/monitoring/wind_speed/{widgets => views}/wind_speed_annual_section.dart (96%) rename lib/screens/monitoring/wind_speed/{widgets => views}/wind_speed_graph_block.dart (92%) delete mode 100644 lib/screens/monitoring/wind_speed/widgets/wind_speed_status_block.dart create mode 100644 lib/screens/monitoring/wind_speed/wind_speed.dart create mode 100644 packages/monitoring_repository/lib/monitoring_repository.dart create mode 100644 packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart create mode 100644 packages/monitoring_repository/lib/src/models/models.dart create mode 100644 packages/monitoring_repository/lib/src/models/wind_speed.dart create mode 100644 packages/monitoring_repository/lib/src/monitoring_repo.dart create mode 100644 packages/monitoring_repository/pubspec.lock create mode 100644 packages/monitoring_repository/pubspec.yaml diff --git a/lib/app.dart b/lib/app.dart index 722bab2..ddd5e93 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -2,19 +2,19 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:klimatologiot/app_view.dart'; import 'package:user_repository/user_repository.dart'; +import 'package:monitoring_repository/monitoring_repository.dart'; import 'blocs/authentication_bloc/authentication_bloc.dart'; class MyApp extends StatelessWidget { final UserRepository userRepository; - const MyApp(this.userRepository, {super.key}); + final MonitoringRepository monitoringRepository; + const MyApp(this.userRepository, this.monitoringRepository, {super.key}); @override Widget build(BuildContext context) { return RepositoryProvider( - create: (context) => AuthenticationBloc( - userRepository: userRepository - ), - child: const MyAppView(), + create: (context) => AuthenticationBloc(userRepository: userRepository), + child: const MyAppView(), ); } -} \ No newline at end of file +} diff --git a/lib/blocs/monitoring_bloc/monitoring_bloc.dart b/lib/blocs/monitoring_bloc/monitoring_bloc.dart new file mode 100644 index 0000000..9d83ea7 --- /dev/null +++ b/lib/blocs/monitoring_bloc/monitoring_bloc.dart @@ -0,0 +1,50 @@ +import 'dart:async'; + +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; +import 'package:firebase_database/firebase_database.dart'; + +part 'monitoring_event.dart'; +part 'monitoring_state.dart'; + +class MonitoringBloc extends Bloc { + final DatabaseReference _realtimeRef = + FirebaseDatabase.instance.ref('anemometer/realtime'); + StreamSubscription? _realtimeSub; + + MonitoringBloc() : super(const MonitoringState.initial()) { + on(_onLoadMonitoringData); + on(_onMonitoringDataUpdated); + } + + void _onLoadMonitoringData( + LoadMonitoringData event, Emitter emit) { + emit(const MonitoringState.loading()); + + // Start listening to realtime data + _realtimeSub = _realtimeRef.onValue.listen((event) { + final data = event.snapshot.value; + if (data is Map) { + final speed = (data['kecepatan'] ?? 0).toDouble(); + final timestamp = data['timestamp'] ?? 0; + final waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + + add(MonitoringDataUpdated(speed: speed, timestamp: waktu)); + } + }); + } + + void _onMonitoringDataUpdated( + MonitoringDataUpdated event, Emitter emit) { + emit(MonitoringState.loaded( + currentSpeed: event.speed, + lastUpdateTime: event.timestamp, + )); + } + + @override + Future close() { + _realtimeSub?.cancel(); + return super.close(); + } +} diff --git a/lib/blocs/monitoring_bloc/monitoring_event.dart b/lib/blocs/monitoring_bloc/monitoring_event.dart new file mode 100644 index 0000000..e93e753 --- /dev/null +++ b/lib/blocs/monitoring_bloc/monitoring_event.dart @@ -0,0 +1,25 @@ +part of 'monitoring_bloc.dart'; + +sealed class MonitoringEvent extends Equatable { + const MonitoringEvent(); + + @override + List get props => []; +} + +class LoadMonitoringData extends MonitoringEvent { + const LoadMonitoringData(); +} + +class MonitoringDataUpdated extends MonitoringEvent { + final double speed; + final DateTime timestamp; + + const MonitoringDataUpdated({ + required this.speed, + required this.timestamp, + }); + + @override + List get props => [speed, timestamp]; +} diff --git a/lib/blocs/monitoring_bloc/monitoring_state.dart b/lib/blocs/monitoring_bloc/monitoring_state.dart new file mode 100644 index 0000000..9e28f38 --- /dev/null +++ b/lib/blocs/monitoring_bloc/monitoring_state.dart @@ -0,0 +1,34 @@ +part of 'monitoring_bloc.dart'; + +class MonitoringState extends Equatable { + final MonitoringStatus status; + final double? currentSpeed; + final DateTime? lastUpdateTime; + + const MonitoringState._({ + this.status = MonitoringStatus.initial, + this.currentSpeed, + this.lastUpdateTime, + }); + + const MonitoringState.initial() : this._(); + + const MonitoringState.loading() : this._(status: MonitoringStatus.loading); + + const MonitoringState.loaded({ + required double currentSpeed, + required DateTime lastUpdateTime, + }) : this._( + status: MonitoringStatus.loaded, + currentSpeed: currentSpeed, + lastUpdateTime: lastUpdateTime, + ); + + const MonitoringState.error(String message) + : this._(status: MonitoringStatus.error); + + @override + List get props => [status, currentSpeed, lastUpdateTime]; +} + +enum MonitoringStatus { initial, loading, loaded, error } diff --git a/lib/main.dart b/lib/main.dart index 24a3171..eb74045 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:klimatologiot/simple_bloc_observer.dart'; import 'package:klimatologiot/app.dart'; import 'package:user_repository/user_repository.dart'; +import 'package:monitoring_repository/monitoring_repository.dart'; import 'firebase_options.dart'; void main() async { @@ -12,5 +13,8 @@ void main() async { options: DefaultFirebaseOptions.currentPlatform, ); Bloc.observer = SimpleBlocObserver(); - runApp(MyApp(FirebaseUserRepo())); -} \ No newline at end of file + runApp(MyApp( + FirebaseUserRepo(), + FirebaseMonitoringRepo(), + )); +} diff --git a/lib/screens/home/blocs/home_bloc.dart b/lib/screens/home/blocs/home_bloc.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/screens/home/blocs/home_event.dart b/lib/screens/home/blocs/home_event.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/screens/home/blocs/home_state.dart b/lib/screens/home/blocs/home_state.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/screens/home/views/home_screen.dart b/lib/screens/home/views/home_screen.dart index b933854..8521eb9 100644 --- a/lib/screens/home/views/home_screen.dart +++ b/lib/screens/home/views/home_screen.dart @@ -5,7 +5,7 @@ import 'package:firebase_database/firebase_database.dart'; import 'dart:async'; import '../../../blocs/authentication_bloc/authentication_bloc.dart'; import '../../monitoring/evaporasi_monitoring_screen.dart'; -import '../../monitoring/wind_speed/wind_speed_monitoring_screen.dart'; +import '../../monitoring/wind_speed/wind_speed.dart'; import '../../monitoring/air_quality_monitoring_screen.dart'; class HomeScreen extends StatefulWidget { diff --git a/lib/screens/monitoring/air_quality_monitoring_screen.dart b/lib/screens/monitoring/air_quality_monitoring_screen.dart index 32059d7..ea75308 100644 --- a/lib/screens/monitoring/air_quality_monitoring_screen.dart +++ b/lib/screens/monitoring/air_quality_monitoring_screen.dart @@ -1,16 +1,18 @@ import 'package:flutter/material.dart'; import 'package:fl_chart/fl_chart.dart'; -import 'widgets/monitoring_shared.dart'; +import 'shared/widgets/monitoring_shared.dart'; /// AIR QUALITY MONITORING SCREEN class AirQualityMonitoringScreen extends StatefulWidget { const AirQualityMonitoringScreen({super.key}); @override - State createState() => _AirQualityMonitoringScreenState(); + State createState() => + _AirQualityMonitoringScreenState(); } -class _AirQualityMonitoringScreenState extends State { +class _AirQualityMonitoringScreenState + extends State { String _selectedPeriod = "Hari Ini"; @override @@ -61,8 +63,30 @@ class _AirQualityMonitoringScreenState extends State csvContent.writeln("Jam,AQI (Air Quality Index)"); final dailyData = [ - 68.0, 70.0, 72.0, 75.0, 78.0, 80.0, 78.0, 75.0, 72.0, 70.0, - 68.0, 65.0, 60.0, 58.0, 60.0, 62.0, 65.0, 68.0, 70.0, 72.0, 75.0, 78.0, 76.0, 74.0 + 68.0, + 70.0, + 72.0, + 75.0, + 78.0, + 80.0, + 78.0, + 75.0, + 72.0, + 70.0, + 68.0, + 65.0, + 60.0, + 58.0, + 60.0, + 62.0, + 65.0, + 68.0, + 70.0, + 72.0, + 75.0, + 78.0, + 76.0, + 74.0 ]; for (int i = 0; i < dailyData.length; i++) { csvContent.writeln("$i:00,${dailyData[i]}"); @@ -75,7 +99,8 @@ class _AirQualityMonitoringScreenState extends State csvContent.writeln("Maksimal: 80 AQI"); csvContent.writeln("Minimal: 58 AQI"); - showExportPreview(context, csvContent.toString(), "Data Harian Kualitas Udara"); + showExportPreview( + context, csvContent.toString(), "Data Harian Kualitas Udara"); } void _exportWeeklyAirQualityData() { @@ -85,7 +110,15 @@ class _AirQualityMonitoringScreenState extends State csvContent.writeln(""); csvContent.writeln("Hari,Rata-rata AQI"); - final days = ['Senin', 'Selasa', 'Rabu', 'Kamis', 'Jumat', 'Sabtu', 'Minggu']; + final days = [ + 'Senin', + 'Selasa', + 'Rabu', + 'Kamis', + 'Jumat', + 'Sabtu', + 'Minggu' + ]; final weeklyData = [68.0, 72.0, 75.0, 78.0, 72.0, 68.0, 62.0]; for (int i = 0; i < days.length; i++) { @@ -99,13 +132,15 @@ class _AirQualityMonitoringScreenState extends State csvContent.writeln("Maksimal: 78 AQI"); csvContent.writeln("Minimal: 62 AQI"); - showExportPreview(context, csvContent.toString(), "Data Mingguan Kualitas Udara"); + showExportPreview( + context, csvContent.toString(), "Data Mingguan Kualitas Udara"); } void _exportMonthlyAirQualityData() { final StringBuffer csvContent = StringBuffer(); csvContent.writeln("DATA MONITORING KUALITAS UDARA - BULANAN"); - csvContent.writeln("Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); + csvContent.writeln( + "Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); csvContent.writeln(""); csvContent.writeln("Tanggal,Rata-rata AQI"); @@ -121,7 +156,8 @@ class _AirQualityMonitoringScreenState extends State csvContent.writeln("Maksimal: 82 AQI"); csvContent.writeln("Minimal: 55 AQI"); - showExportPreview(context, csvContent.toString(), "Data Bulanan Kualitas Udara"); + showExportPreview( + context, csvContent.toString(), "Data Bulanan Kualitas Udara"); } void _exportAnnualAirQualityData() { @@ -132,11 +168,47 @@ class _AirQualityMonitoringScreenState extends State csvContent.writeln("Bulan,Rata-rata AQI,AQI Max"); final months = [ - 'Januari', 'Februari', 'Maret', 'April', 'Mei', 'Juni', - 'Juli', 'Agustus', 'September', 'Oktober', 'November', 'Desember' + 'Januari', + 'Februari', + 'Maret', + 'April', + 'Mei', + 'Juni', + 'Juli', + 'Agustus', + 'September', + 'Oktober', + 'November', + 'Desember' + ]; + final averages = [ + 68.0, + 70.0, + 72.5, + 75.0, + 78.0, + 80.0, + 82.0, + 80.0, + 75.0, + 70.0, + 68.0, + 65.0 + ]; + final maxAqi = [ + 85.0, + 88.0, + 90.0, + 95.0, + 98.0, + 100.0, + 102.0, + 100.0, + 95.0, + 90.0, + 85.0, + 80.0 ]; - final averages = [68.0, 70.0, 72.5, 75.0, 78.0, 80.0, 82.0, 80.0, 75.0, 70.0, 68.0, 65.0]; - final maxAqi = [85.0, 88.0, 90.0, 95.0, 98.0, 100.0, 102.0, 100.0, 95.0, 90.0, 85.0, 80.0]; for (int i = 0; i < months.length; i++) { csvContent.writeln("${months[i]},${averages[i]},${maxAqi[i]}"); @@ -148,7 +220,8 @@ class _AirQualityMonitoringScreenState extends State csvContent.writeln("AQI Max Teringgi: 102.0"); csvContent.writeln("AQI Min Terendah: 65.0"); - showExportPreview(context, csvContent.toString(), "Data Tahunan Kualitas Udara"); + showExportPreview( + context, csvContent.toString(), "Data Tahunan Kualitas Udara"); } /// DATA GENERATORS @@ -157,8 +230,30 @@ class _AirQualityMonitoringScreenState extends State case "Hari Ini": return List.generate(24, (i) { final values = [ - 68.0, 70.0, 72.0, 75.0, 78.0, 80.0, 78.0, 75.0, 72.0, 70.0, - 68.0, 65.0, 60.0, 58.0, 60.0, 62.0, 65.0, 68.0, 70.0, 72.0, 75.0, 78.0, 76.0, 74.0 + 68.0, + 70.0, + 72.0, + 75.0, + 78.0, + 80.0, + 78.0, + 75.0, + 72.0, + 70.0, + 68.0, + 65.0, + 60.0, + 58.0, + 60.0, + 62.0, + 65.0, + 68.0, + 70.0, + 72.0, + 75.0, + 78.0, + 76.0, + 74.0 ]; return FlSpot(i.toDouble(), values[i]); }); @@ -244,7 +339,8 @@ class _AirQualityMonitoringScreenState extends State child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( - children: ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { + children: + ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { return Padding( padding: const EdgeInsets.only(right: 8), child: ChoiceChip( @@ -504,8 +600,18 @@ class _AirQualityMonitoringScreenState extends State showTitles: true, getTitlesWidget: (value, meta) { final months = [ - 'Jan', 'Feb', 'Mar', 'Apr', 'Mei', 'Jun', - 'Jul', 'Agu', 'Sep', 'Okt', 'Nov', 'Des' + 'Jan', + 'Feb', + 'Mar', + 'Apr', + 'Mei', + 'Jun', + 'Jul', + 'Agu', + 'Sep', + 'Okt', + 'Nov', + 'Des' ]; return Text( months[value.toInt()], @@ -588,6 +694,7 @@ class _AirQualityMonitoringScreenState extends State color: Colors.orange.withOpacity(0.1), ), ), + /// AQI Max LineChartBarData( spots: const [ diff --git a/lib/screens/monitoring/evaporasi_monitoring_screen.dart b/lib/screens/monitoring/evaporasi_monitoring_screen.dart index 488aae8..3e67031 100644 --- a/lib/screens/monitoring/evaporasi_monitoring_screen.dart +++ b/lib/screens/monitoring/evaporasi_monitoring_screen.dart @@ -3,7 +3,7 @@ import 'package:fl_chart/fl_chart.dart'; import 'package:firebase_database/firebase_database.dart'; import 'dart:async'; import 'package:intl/intl.dart'; -import 'widgets/monitoring_shared.dart'; +import 'shared/widgets/monitoring_shared.dart'; /// EVAPORASI MONITORING SCREEN class EvaporasiMonitoringScreen extends StatefulWidget { diff --git a/lib/screens/monitoring/widgets/monitoring_shared.dart b/lib/screens/monitoring/shared/widgets/monitoring_shared.dart similarity index 100% rename from lib/screens/monitoring/widgets/monitoring_shared.dart rename to lib/screens/monitoring/shared/widgets/monitoring_shared.dart diff --git a/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart b/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart new file mode 100644 index 0000000..b320ff6 --- /dev/null +++ b/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart @@ -0,0 +1,15 @@ +import 'package:monitoring_repository/monitoring_repository.dart'; + +class WindSpeedBloc { + final MonitoringRepository _repo; + + WindSpeedBloc({required MonitoringRepository repo}) : _repo = repo; + + void startListening() { + // 3. Sekarang kamu bisa akses _repo di dalam lingkup class ini + _repo.getSensorStream('anemometer/realtime').listen((event) { + // Olah datanya di sini + print(event.snapshot.value); + }); + } +} diff --git a/lib/screens/monitoring/wind_speed/blocs/wind_speed_event.dart b/lib/screens/monitoring/wind_speed/blocs/wind_speed_event.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/screens/monitoring/wind_speed/blocs/wind_speed_state.dart b/lib/screens/monitoring/wind_speed/blocs/wind_speed_state.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/screens/monitoring/wind_speed/views/annual_section.dart b/lib/screens/monitoring/wind_speed/views/annual_section.dart new file mode 100644 index 0000000..b414642 --- /dev/null +++ b/lib/screens/monitoring/wind_speed/views/annual_section.dart @@ -0,0 +1,226 @@ +import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; + +import '../../shared/widgets/monitoring_shared.dart'; + +class WindSpeedAnnualSection extends StatelessWidget { + final VoidCallback onExportAnnual; + + const WindSpeedAnnualSection({ + super.key, + required this.onExportAnnual, + }); + final double _rataRata = 0.0; + final double _kecepatanMax = 0.0; + @override + Widget build(BuildContext context) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Statistik Tahunan Kecepatan Angin", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 15), + Row( + children: [ + Expanded( + child: StatCard( + title: "Rata-rata Tahunan", + value: this._rataRata.toStringAsFixed(2), + color: const Color.fromARGB(255, 76, 120, 175), + icon: Icons.air, + ), + ), + SizedBox(width: 10), + Expanded( + child: StatCard( + title: "Kecepatan Max", + value: this._kecepatanMax.toStringAsFixed(2), + color: const Color.fromARGB(255, 109, 109, 109), + icon: Icons.trending_up, + ), + ), + ], + ), + const SizedBox(height: 20), + const Text( + "Grafik Tahunan - Rata-rata & Kecepatan Maksimal", + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.w600, + ), + ), + const SizedBox(height: 12), + Card( + elevation: 3, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: SizedBox( + height: 320, + child: LineChart( + LineChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 2, + getDrawingHorizontalLine: (value) { + return FlLine( + color: const Color.fromARGB(255, 224, 224, 224), + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + topTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + rightTitles: AxisTitles( + sideTitles: SideTitles(showTitles: false), + ), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + lineBarsData: [ + LineChartBarData( + spots: const [ + FlSpot(0, 5.5), + FlSpot(1, 6.2), + FlSpot(2, 6.8), + FlSpot(3, 7.5), + FlSpot(4, 7.8), + FlSpot(5, 8.0), + FlSpot(6, 8.2), + FlSpot(7, 8.0), + FlSpot(8, 7.2), + FlSpot(9, 6.5), + FlSpot(10, 5.8), + FlSpot(11, 5.2), + ], + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.green, + strokeWidth: 0, + ); + }, + ), + color: Colors.green, + belowBarData: BarAreaData( + show: true, + color: Colors.green.withOpacity(0.1), + ), + ), + LineChartBarData( + spots: const [ + FlSpot(0, 12.0), + FlSpot(1, 13.5), + FlSpot(2, 14.0), + FlSpot(3, 15.5), + FlSpot(4, 16.0), + FlSpot(5, 16.2), + FlSpot(6, 16.5), + FlSpot(7, 16.0), + FlSpot(8, 15.0), + FlSpot(9, 14.0), + FlSpot(10, 12.5), + FlSpot(11, 11.0), + ], + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: Colors.red, + strokeWidth: 0, + ); + }, + ), + color: Colors.red, + ), + ], + ), + ), + ), + ), + ), + const SizedBox(height: 15), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.green, + borderRadius: BorderRadius.circular(3), + ), + ), + const SizedBox(width: 8), + const Text( + "Rata-rata (km/h)", + style: TextStyle(fontSize: 12), + ), + const SizedBox(width: 20), + Container( + width: 16, + height: 16, + decoration: BoxDecoration( + color: Colors.red, + borderRadius: BorderRadius.circular(3), + ), + ), + const SizedBox(width: 8), + const Text( + "Kecepatan Max (km/h)", + style: TextStyle(fontSize: 12), + ), + ], + ), + const SizedBox(height: 15), + Center( + child: ElevatedButton.icon( + onPressed: onExportAnnual, + icon: const Icon(Icons.file_download), + label: const Text("Download Excel Tahunan"), + style: ElevatedButton.styleFrom( + backgroundColor: Colors.green, + foregroundColor: Colors.white, + ), + ), + ), + ], + ); + } +} diff --git a/lib/screens/monitoring/wind_speed/widgets/wind_speed_explanation.dart b/lib/screens/monitoring/wind_speed/views/explanation.dart similarity index 70% rename from lib/screens/monitoring/wind_speed/widgets/wind_speed_explanation.dart rename to lib/screens/monitoring/wind_speed/views/explanation.dart index 6e6bb90..49b3340 100644 --- a/lib/screens/monitoring/wind_speed/widgets/wind_speed_explanation.dart +++ b/lib/screens/monitoring/wind_speed/views/explanation.dart @@ -8,10 +8,16 @@ class WindSpeedExplanation extends StatelessWidget { return Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( - color: Colors.green.shade50, - borderRadius: BorderRadius.circular(12), - border: Border.all(color: Colors.green.shade200), - ), + color: const Color.fromARGB(255, 232, 240, 245), + borderRadius: BorderRadius.circular(12), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.2), + blurRadius: 3, + spreadRadius: 0, + offset: const Offset(0, 5), + ) + ]), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: const [ @@ -20,7 +26,7 @@ class WindSpeedExplanation extends StatelessWidget { style: TextStyle( fontSize: 14, fontWeight: FontWeight.bold, - color: Colors.green, + color: Color.fromARGB(255, 0, 0, 0), ), ), SizedBox(height: 10), @@ -29,7 +35,7 @@ class WindSpeedExplanation extends StatelessWidget { style: TextStyle( fontSize: 12, height: 1.6, - color: Colors.green, + color: Color.fromARGB(255, 0, 0, 0), ), ), ], diff --git a/lib/screens/monitoring/wind_speed/views/graph_block.dart b/lib/screens/monitoring/wind_speed/views/graph_block.dart new file mode 100644 index 0000000..c24a730 --- /dev/null +++ b/lib/screens/monitoring/wind_speed/views/graph_block.dart @@ -0,0 +1,253 @@ +import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; + +import '../../shared/widgets/monitoring_shared.dart'; + +class WindSpeedGraphBlock extends StatelessWidget { + final String selectedPeriod; + final List dailySpeeds; + final bool isOnline; + final ValueChanged onPeriodChanged; + final ValueChanged onExportPressed; + + const WindSpeedGraphBlock({ + super.key, + required this.selectedPeriod, + required this.dailySpeeds, + required this.isOnline, + required this.onPeriodChanged, + required this.onExportPressed, + }); + + List _getPeriodSpots() { + switch (selectedPeriod) { + case "Hari Ini": + return List.generate(24, (i) { + final value = dailySpeeds[i]; + return FlSpot(i.toDouble(), value); + }); + case "Minggu Ini": + return const [ + FlSpot(0, 6.5), + FlSpot(1, 7.2), + FlSpot(2, 7.8), + FlSpot(3, 8.0), + FlSpot(4, 7.5), + FlSpot(5, 6.8), + FlSpot(6, 5.5), + ]; + case "Bulan Ini": + return const [ + FlSpot(0, 6.0), + FlSpot(1, 6.5), + FlSpot(2, 7.0), + FlSpot(3, 7.5), + FlSpot(4, 7.8), + FlSpot(5, 8.0), + FlSpot(6, 8.2), + FlSpot(7, 8.0), + FlSpot(8, 7.5), + FlSpot(9, 7.0), + FlSpot(10, 6.5), + FlSpot(11, 6.0), + ]; + default: + return []; + } + } + + @override + Widget build(BuildContext context) { + return Card( + elevation: 4, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + const Text( + "Status Kecepatan Angin", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.bold, + ), + ), + Container( + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 5, + ), + decoration: BoxDecoration( + color: + isOnline ? Colors.green.shade100 : Colors.red.shade100, + borderRadius: BorderRadius.circular(20), + ), + child: Text( + isOnline ? "ONLINE" : "OFFLINE", + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.w600, + color: isOnline ? Colors.green : Colors.red, + ), + ), + ), + ], + ), + const SizedBox(height: 16), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Expanded( + child: SingleChildScrollView( + scrollDirection: Axis.horizontal, + child: Row( + children: + ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { + return Padding( + padding: const EdgeInsets.only(right: 8), + child: ChoiceChip( + label: Text(period), + selected: selectedPeriod == period, + onSelected: (selected) { + if (selected) { + onPeriodChanged(period); + } + }, + side: BorderSide.none, + backgroundColor: Colors.grey.withOpacity(0.1), + selectedColor: + const Color.fromARGB(255, 0, 136, 255), + labelStyle: TextStyle( + color: selectedPeriod == period + ? Colors.white + : Colors.black, + ), + ), + ); + }).toList(), + ), + ), + ), + const SizedBox(width: 8), + ElevatedButton.icon( + onPressed: () => onExportPressed(selectedPeriod), + icon: const Icon(Icons.download, size: 16), + label: const Text("Export"), + style: ElevatedButton.styleFrom( + backgroundColor: const Color.fromARGB(255, 0, 145, 255), + foregroundColor: Colors.white, + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 6, + ), + textStyle: const TextStyle(fontSize: 11), + ), + ), + ], + ), + const SizedBox(height: 16), + SizedBox( + height: 300, + child: LineChart( + LineChartData( + gridData: FlGridData( + show: true, + drawHorizontalLine: true, + drawVerticalLine: false, + horizontalInterval: 1, + getDrawingHorizontalLine: (value) { + return FlLine( + color: Colors.grey.shade300, + strokeWidth: 1, + ); + }, + ), + titlesData: FlTitlesData( + show: true, + bottomTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: getPeriodInterval(selectedPeriod), + getTitlesWidget: (value, meta) { + return Text( + getPeriodLabel(selectedPeriod, value), + style: const TextStyle( + fontSize: 10, + color: Colors.grey, + ), + ); + }, + ), + ), + leftTitles: AxisTitles( + sideTitles: SideTitles( + showTitles: true, + interval: 1, + getTitlesWidget: (value, meta) { + return Text( + value.toInt().toString(), + style: const TextStyle( + fontSize: 9, + color: Colors.grey, + ), + ); + }, + reservedSize: 28, + ), + ), + topTitles: + AxisTitles(sideTitles: SideTitles(showTitles: false)), + rightTitles: + AxisTitles(sideTitles: SideTitles(showTitles: false)), + ), + borderData: FlBorderData( + show: true, + border: Border( + left: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + bottom: BorderSide( + color: Colors.grey.shade300, + width: 1, + ), + ), + ), + lineBarsData: [ + LineChartBarData( + spots: _getPeriodSpots(), + isCurved: true, + barWidth: 2.5, + dotData: FlDotData( + show: true, + getDotPainter: (spot, percent, barData, index) { + return FlDotCirclePainter( + radius: 4, + color: const Color.fromARGB(255, 0, 191, 255), + strokeWidth: 0, + ); + }, + ), + color: const Color.fromARGB(255, 0, 191, 255), + belowBarData: BarAreaData( + show: true, + color: const Color.fromARGB(255, 0, 115, 255) + .withOpacity(0.1), + ), + ), + ], + ), + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/screens/monitoring/wind_speed/views/status_block.dart b/lib/screens/monitoring/wind_speed/views/status_block.dart new file mode 100644 index 0000000..24b305a --- /dev/null +++ b/lib/screens/monitoring/wind_speed/views/status_block.dart @@ -0,0 +1,95 @@ +import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; + +class WindSpeedStatusBlock extends StatelessWidget { + final double currentSpeed; + final bool isOnline; + final DateTime lastUpdateTime; + + const WindSpeedStatusBlock({ + super.key, + required this.currentSpeed, + required this.isOnline, + required this.lastUpdateTime, + }); + + @override + Widget build(BuildContext context) { + final formattedTime = + DateFormat("dd MMM yyyy • HH:mm:ss").format(lastUpdateTime); + + /// ====== Current Speed bagian kode kecepatan angin ===== /// + return Padding( + padding: const EdgeInsets.only(bottom: 12), + child: Container( + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: Colors.grey.withOpacity(0.12), + borderRadius: BorderRadius.circular(16), + boxShadow: [ + BoxShadow( + color: Colors.black.withOpacity(0.05), + blurRadius: 12, + offset: const Offset(0, 4), + ), + ], + ), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + "Kecepatan Angin", + style: TextStyle( + fontSize: 18, + fontWeight: FontWeight.bold, + ), + ), + const SizedBox(height: 12), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "${currentSpeed.toStringAsFixed(2)} km/h", + style: const TextStyle( + fontSize: 28, + fontWeight: FontWeight.bold, + color: Color.fromARGB(255, 0, 0, 0), + ), + ), + + /// ==== bagian online offline status tampilan ==== /// + Container( + padding: const EdgeInsets.symmetric( + horizontal: 10, + vertical: 5, + ), + decoration: BoxDecoration( + color: + isOnline ? Colors.green.shade100 : Colors.red.shade100, + borderRadius: BorderRadius.circular(20), + ), + child: Text( + isOnline ? "ONLINE" : "OFFLINE", + style: TextStyle( + fontSize: 11, + fontWeight: FontWeight.w600, + color: isOnline ? Colors.green : Colors.red, + ), + ), + ), + ], + ), + const SizedBox(height: 10), + Text( + "Update: $formattedTime", + style: const TextStyle( + fontSize: 12, + color: Colors.grey, + ), + ), + ], + ), + ), + ); + } +} diff --git a/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart b/lib/screens/monitoring/wind_speed/views/wind_speed_annual_section.dart similarity index 96% rename from lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart rename to lib/screens/monitoring/wind_speed/views/wind_speed_annual_section.dart index 60806c7..b414642 100644 --- a/lib/screens/monitoring/wind_speed/widgets/wind_speed_annual_section.dart +++ b/lib/screens/monitoring/wind_speed/views/wind_speed_annual_section.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:fl_chart/fl_chart.dart'; -import '../../widgets/monitoring_shared.dart'; +import '../../shared/widgets/monitoring_shared.dart'; class WindSpeedAnnualSection extends StatelessWidget { final VoidCallback onExportAnnual; @@ -31,7 +31,7 @@ class WindSpeedAnnualSection extends StatelessWidget { child: StatCard( title: "Rata-rata Tahunan", value: this._rataRata.toStringAsFixed(2), - color: Colors.green, + color: const Color.fromARGB(255, 76, 120, 175), icon: Icons.air, ), ), @@ -40,7 +40,7 @@ class WindSpeedAnnualSection extends StatelessWidget { child: StatCard( title: "Kecepatan Max", value: this._kecepatanMax.toStringAsFixed(2), - color: Colors.red, + color: const Color.fromARGB(255, 109, 109, 109), icon: Icons.trending_up, ), ), @@ -73,7 +73,7 @@ class WindSpeedAnnualSection extends StatelessWidget { horizontalInterval: 2, getDrawingHorizontalLine: (value) { return FlLine( - color: Colors.grey.shade300, + color: const Color.fromARGB(255, 224, 224, 224), strokeWidth: 1, ); }, @@ -142,7 +142,7 @@ class WindSpeedAnnualSection extends StatelessWidget { ), LineChartBarData( spots: const [ - FlSpot(0, 12.0), //sadds + FlSpot(0, 12.0), FlSpot(1, 13.5), FlSpot(2, 14.0), FlSpot(3, 15.5), diff --git a/lib/screens/monitoring/wind_speed/widgets/wind_speed_graph_block.dart b/lib/screens/monitoring/wind_speed/views/wind_speed_graph_block.dart similarity index 92% rename from lib/screens/monitoring/wind_speed/widgets/wind_speed_graph_block.dart rename to lib/screens/monitoring/wind_speed/views/wind_speed_graph_block.dart index 5a52f97..c24a730 100644 --- a/lib/screens/monitoring/wind_speed/widgets/wind_speed_graph_block.dart +++ b/lib/screens/monitoring/wind_speed/views/wind_speed_graph_block.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:fl_chart/fl_chart.dart'; -import '../../widgets/monitoring_shared.dart'; +import '../../shared/widgets/monitoring_shared.dart'; class WindSpeedGraphBlock extends StatelessWidget { final String selectedPeriod; @@ -119,7 +119,10 @@ class WindSpeedGraphBlock extends StatelessWidget { onPeriodChanged(period); } }, - selectedColor: Colors.green, + side: BorderSide.none, + backgroundColor: Colors.grey.withOpacity(0.1), + selectedColor: + const Color.fromARGB(255, 0, 136, 255), labelStyle: TextStyle( color: selectedPeriod == period ? Colors.white @@ -137,7 +140,7 @@ class WindSpeedGraphBlock extends StatelessWidget { icon: const Icon(Icons.download, size: 16), label: const Text("Export"), style: ElevatedButton.styleFrom( - backgroundColor: Colors.orange, + backgroundColor: const Color.fromARGB(255, 0, 145, 255), foregroundColor: Colors.white, padding: const EdgeInsets.symmetric( horizontal: 10, @@ -226,15 +229,16 @@ class WindSpeedGraphBlock extends StatelessWidget { getDotPainter: (spot, percent, barData, index) { return FlDotCirclePainter( radius: 4, - color: Colors.green, + color: const Color.fromARGB(255, 0, 191, 255), strokeWidth: 0, ); }, ), - color: Colors.green, + color: const Color.fromARGB(255, 0, 191, 255), belowBarData: BarAreaData( show: true, - color: Colors.green.withOpacity(0.1), + color: const Color.fromARGB(255, 0, 115, 255) + .withOpacity(0.1), ), ), ], diff --git a/lib/screens/monitoring/wind_speed/widgets/wind_speed_status_block.dart b/lib/screens/monitoring/wind_speed/widgets/wind_speed_status_block.dart deleted file mode 100644 index d3e5177..0000000 --- a/lib/screens/monitoring/wind_speed/widgets/wind_speed_status_block.dart +++ /dev/null @@ -1,68 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; - -class WindSpeedStatusBlock extends StatelessWidget { - final double currentSpeed; - final bool isOnline; - final DateTime lastUpdateTime; - - const WindSpeedStatusBlock({ - super.key, - required this.currentSpeed, - required this.isOnline, - required this.lastUpdateTime, - }); - - @override - Widget build(BuildContext context) { - final formattedTime = - DateFormat("dd MMM yyyy • HH:mm:ss").format(lastUpdateTime); - return Padding( - padding: const EdgeInsets.only(bottom: 12), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "${currentSpeed.toStringAsFixed(2)} km/h", - style: const TextStyle( - fontSize: 28, - fontWeight: FontWeight.bold, - color: Colors.green, - ), - ), - Container( - padding: const EdgeInsets.symmetric( - horizontal: 10, - vertical: 5, - ), - decoration: BoxDecoration( - color: isOnline ? Colors.green.shade100 : Colors.red.shade100, - borderRadius: BorderRadius.circular(20), - ), - child: Text( - isOnline ? "ONLINE" : "OFFLINE", - style: TextStyle( - fontSize: 11, - fontWeight: FontWeight.w600, - color: isOnline ? Colors.green : Colors.red, - ), - ), - ), - ], - ), - const SizedBox(height: 4), - Text( - "Update: $formattedTime", - style: const TextStyle( - fontSize: 12, - color: Colors.grey, - ), - ), - ], - ), - ); - } -} diff --git a/lib/screens/monitoring/wind_speed/wind_speed.dart b/lib/screens/monitoring/wind_speed/wind_speed.dart new file mode 100644 index 0000000..db2c12a --- /dev/null +++ b/lib/screens/monitoring/wind_speed/wind_speed.dart @@ -0,0 +1,272 @@ +import 'dart:async'; + +import '../'; +import 'package:flutter/material.dart'; + +import '../shared/widgets/monitoring_shared.dart'; +import 'views/annual_section.dart'; +import 'views/explanation.dart'; +import 'views/graph_block.dart'; +import 'views/status_block.dart'; +import 'package:google_fonts/google_fonts.dart'; + +class WindSpeedMonitoringScreen extends StatefulWidget { + const WindSpeedMonitoringScreen({super.key}); + + @override + State createState() => + _WindSpeedMonitoringScreenState(); +} + +class _WindSpeedMonitoringScreenState extends State { + String _selectedPeriod = "Hari Ini"; + + // realtime values + DateTime? _lastUpdateTime; + double _currentSpeed = 0.0; + final List _dailySpeeds = List.filled(24, 0.0); + + // hourly aggregation helpers (PRO version) + double _hourlyTotalSpeed = 0.0; + int _hourlyCount = 0; + int _currentHour = DateTime.now().hour; + + bool get _isOnline { + if (_lastUpdateTime == null) return false; + final diff = DateTime.now().difference(_lastUpdateTime!); + return diff.inSeconds <= 5; + } + + @override + void initState() { + super.initState(); + _realtimeSub = _realtimeRef.onValue.listen(_onRealtimeData); + } + + void _onRealtimeData(DatabaseEvent event) { + final data = event.snapshot.value; + + if (data is Map) { + final speed = (data['kecepatan'] ?? 0).toDouble(); + final timestamp = data['timestamp'] ?? 0; + + final waktu = + DateTime.fromMillisecondsSinceEpoch(timestamp * 1000).toLocal(); + + setState(() { + _currentSpeed = speed; + _lastUpdateTime = waktu; + + final incomingHour = waktu.hour; + + if (incomingHour != _currentHour) { + if (_hourlyCount > 0) { + final avg = _hourlyTotalSpeed / _hourlyCount; + _dailySpeeds[_currentHour] = avg; + } + + _hourlyTotalSpeed = 0.0; + _hourlyCount = 0; + _currentHour = incomingHour; + + if (incomingHour == 0) { + for (int i = 0; i < 24; i++) { + _dailySpeeds[i] = 0.0; + } + } + } + + _hourlyTotalSpeed += speed; + _hourlyCount++; + }); + } + } + + @override + void dispose() { + _realtimeSub?.cancel(); + super.dispose(); + } + + void _handleExportSelectedPeriod(String period) { + switch (period) { + case "Hari Ini": + _exportDailyWindData(); + break; + case "Minggu Ini": + _exportWeeklyWindData(); + break; + case "Bulan Ini": + _exportMonthlyWindData(); + break; + } + } + + void _exportDailyWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - HARIAN (24 JAM)"); + csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); + csvContent.writeln(""); + csvContent.writeln("Jam,Kecepatan (km/h)"); + + final dailyData = []; + + for (int i = 0; i < dailyData.length; i++) { + csvContent.writeln("$i:00,${dailyData[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Harian"); + csvContent.writeln("Total: 165.8 km/h"); + csvContent.writeln("Rata-rata: 6.9 km/h"); + csvContent.writeln("Maksimal: 11.0 km/h"); + csvContent.writeln("Minimal: 4.3 km/h"); + + showExportPreview( + context, csvContent.toString(), "Data Harian Kecepatan Angin"); + } + + void _exportWeeklyWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - MINGGUAN"); + csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); + csvContent.writeln(""); + csvContent.writeln("Hari,Rata-rata (km/h)"); + + final days = [ + 'Senin', + 'Selasa', + 'Rabu', + 'Kamis', + 'Jumat', + 'Sabtu', + 'Minggu' + ]; + final weeklyData = [6.5, 7.2, 7.8, 8.0, 7.5, 6.8, 5.5]; + + for (int i = 0; i < days.length; i++) { + csvContent.writeln("${days[i]},${weeklyData[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Mingguan"); + csvContent.writeln("Total: 49.3 km/h"); + csvContent.writeln("Rata-rata: 7.0 km/h"); + csvContent.writeln("Maksimal: 8.0 km/h"); + csvContent.writeln("Minimal: 5.5 km/h"); + + showExportPreview( + context, csvContent.toString(), "Data Mingguan Kecepatan Angin"); + } + + void _exportMonthlyWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - BULANAN"); + csvContent.writeln( + "Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); + csvContent.writeln(""); + csvContent.writeln("Tanggal,Rata-rata (km/h)"); + + for (int i = 1; i <= 28; i++) { + final value = (6.0 + (i % 6) * 0.8).toStringAsFixed(1); + csvContent.writeln("$i,$value"); + } + + csvContent.writeln(""); + csvContent.writeln("Statistik Bulanan"); + csvContent.writeln("Total: 180.5 km/h"); + csvContent.writeln("Rata-rata: 6.4 km/h"); + csvContent.writeln("Maksimal: 9.0 km/h"); + csvContent.writeln("Minimal: 4.0 km/h"); + + showExportPreview( + context, csvContent.toString(), "Data Bulanan Kecepatan Angin"); + } + + void _exportAnnualWindData() { + final StringBuffer csvContent = StringBuffer(); + csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - TAHUNAN"); + csvContent.writeln("Tahun: 2025"); + csvContent.writeln(""); + csvContent.writeln("Bulan,Rata-rata (km/h),Kecepatan Max (km/h)"); + + final months = [ + 'Januari', + 'Februari', + 'Maret', + 'April', + 'Mei', + 'Juni', + 'Juli', + 'Agustus', + 'September', + 'Oktober', + 'November', + 'Desember' + ]; + final averages = []; + final maxSpeed = []; + + for (int i = 0; i < months.length; i++) { + csvContent.writeln("${months[i]},${averages[i]},${maxSpeed[i]}"); + } + + csvContent.writeln(""); + csvContent.writeln("STATISTIK TAHUNAN"); + csvContent.writeln("Rata-rata Tahunan: 7.1 km/h"); + csvContent.writeln("Kecepatan Max Tertinggi: 16.5 km/h"); + csvContent.writeln("Kecepatan Min Terendah: 5.2 km/h"); + + showExportPreview( + context, csvContent.toString(), "Data Tahunan Kecepatan Angin"); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: Text( + "Wind Speed", + style: GoogleFonts.rubik( + color: Colors.black, fontWeight: FontWeight.bold), + ), + centerTitle: true, + backgroundColor: const Color.fromARGB(37, 158, 158, 158), + ), + body: Padding( + padding: const EdgeInsets.all(16), + child: SingleChildScrollView( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (_lastUpdateTime != null) + WindSpeedStatusBlock( + currentSpeed: _currentSpeed, + isOnline: _isOnline, + lastUpdateTime: _lastUpdateTime!, + ), + const SizedBox(height: 20), + WindSpeedGraphBlock( + selectedPeriod: _selectedPeriod, + dailySpeeds: _dailySpeeds, + isOnline: _isOnline, + onPeriodChanged: (period) { + setState(() { + _selectedPeriod = period; + }); + }, + onExportPressed: _handleExportSelectedPeriod, + ), + const SizedBox(height: 25), + const WindSpeedExplanation(), + const SizedBox(height: 25), + WindSpeedAnnualSection( + onExportAnnual: _exportAnnualWindData, + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart index cbddc47..b60ca89 100644 --- a/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart +++ b/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart @@ -3,11 +3,11 @@ import 'dart:async'; import 'package:firebase_database/firebase_database.dart'; import 'package:flutter/material.dart'; -import '../widgets/monitoring_shared.dart'; -import 'widgets/wind_speed_annual_section.dart'; -import 'widgets/wind_speed_explanation.dart'; -import 'widgets/wind_speed_graph_block.dart'; -import 'widgets/wind_speed_status_block.dart'; +import '../shared/widgets/monitoring_shared.dart'; +import 'views/annual_section.dart'; +import 'views/explanation.dart'; +import 'views/graph_block.dart'; +import 'views/status_block.dart'; import 'package:google_fonts/google_fonts.dart'; class WindSpeedMonitoringScreen extends StatefulWidget { @@ -21,21 +21,6 @@ class WindSpeedMonitoringScreen extends StatefulWidget { class _WindSpeedMonitoringScreenState extends State { String _selectedPeriod = "Hari Ini"; - // realtime database state - final DatabaseReference _realtimeRef = - FirebaseDatabase.instance.ref('anemometer/realtime'); - StreamSubscription? _realtimeSub; - - // realtime values - DateTime? _lastUpdateTime; - double _currentSpeed = 0.0; - final List _dailySpeeds = List.filled(24, 0.0); - - // hourly aggregation helpers (PRO version) - double _hourlyTotalSpeed = 0.0; - int _hourlyCount = 0; - int _currentHour = DateTime.now().hour; - bool get _isOnline { if (_lastUpdateTime == null) return false; final diff = DateTime.now().difference(_lastUpdateTime!); @@ -55,7 +40,8 @@ class _WindSpeedMonitoringScreenState extends State { final speed = (data['kecepatan'] ?? 0).toDouble(); final timestamp = data['timestamp'] ?? 0; - final waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); + final waktu = + DateTime.fromMillisecondsSinceEpoch(timestamp * 1000).toLocal(); setState(() { _currentSpeed = speed; @@ -113,32 +99,7 @@ class _WindSpeedMonitoringScreenState extends State { csvContent.writeln(""); csvContent.writeln("Jam,Kecepatan (km/h)"); - final dailyData = [ - 5.0, - 5.2, - 4.8, - 4.5, - 4.3, - 4.6, - 5.1, - 6.0, - 7.2, - 8.5, - 9.0, - 10.2, - 11.0, - 10.5, - 10.0, - 9.2, - 8.0, - 6.5, - 5.5, - 5.0, - 4.8, - 4.5, - 5.0, - 5.2 - ]; + final dailyData = []; for (int i = 0; i < dailyData.length; i++) { csvContent.writeln("$i:00,${dailyData[i]}"); @@ -233,34 +194,8 @@ class _WindSpeedMonitoringScreenState extends State { 'November', 'Desember' ]; - final averages = [ - 5.5, - 6.2, - 6.8, - 7.5, - 7.8, - 8.0, - 8.2, - 8.0, - 7.2, - 6.5, - 5.8, - 5.2 - ]; - final maxSpeed = [ - 12.0, - 13.5, - 14.0, - 15.5, - 16.0, - 16.2, - 16.5, - 16.0, - 15.0, - 14.0, - 12.5, - 11.0 - ]; + final averages = []; + final maxSpeed = []; for (int i = 0; i < months.length; i++) { csvContent.writeln("${months[i]},${averages[i]},${maxSpeed[i]}"); @@ -294,20 +229,13 @@ class _WindSpeedMonitoringScreenState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - const Text( - "Kecepatan Angin", - style: TextStyle( - fontSize: 22, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 20), if (_lastUpdateTime != null) WindSpeedStatusBlock( currentSpeed: _currentSpeed, isOnline: _isOnline, lastUpdateTime: _lastUpdateTime!, ), + const SizedBox(height: 20), WindSpeedGraphBlock( selectedPeriod: _selectedPeriod, dailySpeeds: _dailySpeeds, diff --git a/packages/monitoring_repository/lib/monitoring_repository.dart b/packages/monitoring_repository/lib/monitoring_repository.dart new file mode 100644 index 0000000..626b971 --- /dev/null +++ b/packages/monitoring_repository/lib/monitoring_repository.dart @@ -0,0 +1,4 @@ +library monitoring_repository; + +export 'src/monitoring_repo.dart'; +export 'src/firebase_monitoring_repo.dart'; diff --git a/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart b/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart new file mode 100644 index 0000000..465237d --- /dev/null +++ b/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart @@ -0,0 +1,23 @@ +import 'dart:developer'; +import 'dart:async'; +import 'package:rxdart/rxdart.dart'; +import 'package:firebase_database/firebase_database.dart'; +import 'package:monitoring_repository/monitoring_repository.dart'; + +/// === ambil data dari realtime database firebase === /// +class FirebaseMonitoringRepo implements MonitoringRepository { + final FirebaseDatabase _db = FirebaseDatabase.instance; + + // Satu fungsi untuk semua jenis sensor + // Kamu cukup masukkan "path" database-nya saja + @override + Stream getSensorStream(String path) { + return _db.ref(path).onValue; + } + + @override + // Jika ingin mengambil data sekali saja (bukan stream) + Future getSensorSnapshot(String path) async { + return await _db.ref(path).get(); + } +} diff --git a/packages/monitoring_repository/lib/src/models/models.dart b/packages/monitoring_repository/lib/src/models/models.dart new file mode 100644 index 0000000..fd4175e --- /dev/null +++ b/packages/monitoring_repository/lib/src/models/models.dart @@ -0,0 +1 @@ +export 'wind_speed.dart'; diff --git a/packages/monitoring_repository/lib/src/models/wind_speed.dart b/packages/monitoring_repository/lib/src/models/wind_speed.dart new file mode 100644 index 0000000..221cfb6 --- /dev/null +++ b/packages/monitoring_repository/lib/src/models/wind_speed.dart @@ -0,0 +1,21 @@ +class MyWindSpeed { + double speed; + int pulse; + DateTime timestamp; + + MyWindSpeed({ + required this.speed, + required this.pulse, + required this.timestamp, + }); + + factory MyWindSpeed.fromJson(Map json) { + return MyWindSpeed( + speed: (json['speed'] ?? 0).toDouble(), + pulse: (json['pulse'] ?? 0) as int, + timestamp: DateTime.fromMillisecondsSinceEpoch( + (json['timestamp'] ?? 0) * 1000, // kalau dari Unix detik + ), + ); + } +} diff --git a/packages/monitoring_repository/lib/src/monitoring_repo.dart b/packages/monitoring_repository/lib/src/monitoring_repo.dart new file mode 100644 index 0000000..83b7bba --- /dev/null +++ b/packages/monitoring_repository/lib/src/monitoring_repo.dart @@ -0,0 +1,7 @@ +import 'package:firebase_database/firebase_database.dart'; + +abstract class MonitoringRepository { + Stream getSensorStream(String path); + + Future getSensorSnapshot(String path); +} diff --git a/packages/monitoring_repository/pubspec.lock b/packages/monitoring_repository/pubspec.lock new file mode 100644 index 0000000..db981f1 --- /dev/null +++ b/packages/monitoring_repository/pubspec.lock @@ -0,0 +1,290 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + _flutterfire_internals: + dependency: transitive + description: + name: _flutterfire_internals + sha256: f698de6eb8a0dd7a9a931bbfe13568e8b77e702eb2deb13dd83480c5373e7746 + url: "https://pub.dev" + source: hosted + version: "1.3.68" + async: + dependency: transitive + description: + name: async + sha256: e2eb0491ba5ddb6177742d2da23904574082139b07c1e33b8503b9f46f3e1a37 + url: "https://pub.dev" + source: hosted + version: "2.13.1" + boolean_selector: + dependency: transitive + description: + name: boolean_selector + sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" + url: "https://pub.dev" + source: hosted + version: "2.1.2" + characters: + dependency: transitive + description: + name: characters + sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 + url: "https://pub.dev" + source: hosted + version: "1.4.0" + clock: + dependency: transitive + description: + name: clock + sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b + url: "https://pub.dev" + source: hosted + version: "1.1.2" + collection: + dependency: transitive + description: + name: collection + sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" + url: "https://pub.dev" + source: hosted + version: "1.19.1" + fake_async: + dependency: transitive + description: + name: fake_async + sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" + url: "https://pub.dev" + source: hosted + version: "1.3.3" + firebase_core: + dependency: transitive + description: + name: firebase_core + sha256: "2f988dab915efde3b3105268dbd69efce0e8570d767a218ccd914afd0c10c8cc" + url: "https://pub.dev" + source: hosted + version: "4.6.0" + firebase_core_platform_interface: + dependency: transitive + description: + name: firebase_core_platform_interface + sha256: "0ecda14c1bfc9ed8cac303dd0f8d04a320811b479362a9a4efb14fd331a473ce" + url: "https://pub.dev" + source: hosted + version: "6.0.3" + firebase_core_web: + dependency: transitive + description: + name: firebase_core_web + sha256: "1399ab1f0ac3b503d8a9be64a4c997fc066bbf33f701f42866e5569f26205ebe" + url: "https://pub.dev" + source: hosted + version: "3.5.1" + firebase_database: + dependency: "direct main" + description: + name: firebase_database + sha256: "05358855166c943a2fe9321bce69ab6b583c9a49e70e01b5297ef03f8bea50b9" + url: "https://pub.dev" + source: hosted + version: "12.2.0" + firebase_database_platform_interface: + dependency: transitive + description: + name: firebase_database_platform_interface + sha256: "83278cc315ad0f36a5e30fc7f3d1c6edc722340347d41ea17f57e52176bb98f8" + url: "https://pub.dev" + source: hosted + version: "0.3.1" + firebase_database_web: + dependency: transitive + description: + name: firebase_database_web + sha256: "77df7f7c59f4bba33f06644f76e28a8acc594487f1aaa4c79947abf491a7ae70" + url: "https://pub.dev" + source: hosted + version: "0.2.7+5" + flutter: + dependency: "direct main" + description: flutter + source: sdk + version: "0.0.0" + flutter_lints: + dependency: "direct dev" + description: + name: flutter_lints + sha256: "3105dc8492f6183fb076ccf1f351ac3d60564bff92e20bfc4af9cc1651f4e7e1" + url: "https://pub.dev" + source: hosted + version: "6.0.0" + flutter_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + leak_tracker: + dependency: transitive + description: + name: leak_tracker + sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" + url: "https://pub.dev" + source: hosted + version: "11.0.2" + leak_tracker_flutter_testing: + dependency: transitive + description: + name: leak_tracker_flutter_testing + sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" + url: "https://pub.dev" + source: hosted + version: "3.0.10" + leak_tracker_testing: + dependency: transitive + description: + name: leak_tracker_testing + sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" + url: "https://pub.dev" + source: hosted + version: "3.0.2" + lints: + dependency: transitive + description: + name: lints + sha256: "12f842a479589fea194fe5c5a3095abc7be0c1f2ddfa9a0e76aed1dbd26a87df" + url: "https://pub.dev" + source: hosted + version: "6.1.0" + matcher: + dependency: transitive + description: + name: matcher + sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 + url: "https://pub.dev" + source: hosted + version: "0.12.17" + material_color_utilities: + dependency: transitive + description: + name: material_color_utilities + sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec + url: "https://pub.dev" + source: hosted + version: "0.11.1" + meta: + dependency: transitive + description: + name: meta + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" + url: "https://pub.dev" + source: hosted + version: "1.17.0" + path: + dependency: transitive + description: + name: path + sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" + url: "https://pub.dev" + source: hosted + version: "1.9.1" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" + url: "https://pub.dev" + source: hosted + version: "2.1.8" + rxdart: + dependency: "direct main" + description: + name: rxdart + sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb" + url: "https://pub.dev" + source: hosted + version: "0.27.7" + sky_engine: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" + source_span: + dependency: transitive + description: + name: source_span + sha256: "56a02f1f4cd1a2d96303c0144c93bd6d909eea6bee6bf5a0e0b685edbd4c47ab" + url: "https://pub.dev" + source: hosted + version: "1.10.2" + stack_trace: + dependency: transitive + description: + name: stack_trace + sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" + url: "https://pub.dev" + source: hosted + version: "1.12.1" + stream_channel: + dependency: transitive + description: + name: stream_channel + sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" + url: "https://pub.dev" + source: hosted + version: "2.1.4" + string_scanner: + dependency: transitive + description: + name: string_scanner + sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" + url: "https://pub.dev" + source: hosted + version: "1.4.1" + term_glyph: + dependency: transitive + description: + name: term_glyph + sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" + url: "https://pub.dev" + source: hosted + version: "1.2.2" + test_api: + dependency: transitive + description: + name: test_api + sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55 + url: "https://pub.dev" + source: hosted + version: "0.7.7" + vector_math: + dependency: transitive + description: + name: vector_math + sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b + url: "https://pub.dev" + source: hosted + version: "2.2.0" + vm_service: + dependency: transitive + description: + name: vm_service + sha256: "45caa6c5917fa127b5dbcfbd1fa60b14e583afdc08bfc96dda38886ca252eb60" + url: "https://pub.dev" + source: hosted + version: "15.0.2" + web: + dependency: transitive + description: + name: web + sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a" + url: "https://pub.dev" + source: hosted + version: "1.1.1" +sdks: + dart: ">=3.10.7 <4.0.0" + flutter: ">=3.22.0" diff --git a/packages/monitoring_repository/pubspec.yaml b/packages/monitoring_repository/pubspec.yaml new file mode 100644 index 0000000..c58f077 --- /dev/null +++ b/packages/monitoring_repository/pubspec.yaml @@ -0,0 +1,56 @@ +name: monitoring_repository +description: 'A new Flutter package project.' +version: 0.0.1 +homepage: + +environment: + sdk: ^3.10.7 + flutter: '>=1.17.0' + +dependencies: + flutter: + sdk: flutter + rxdart: ^0.27.7 + firebase_database: ^12.1.3 + +dev_dependencies: + flutter_test: + sdk: flutter + flutter_lints: ^6.0.0 + +# For information on the generic Dart part of this file, see the +# following page: https://dart.dev/tools/pub/pubspec + +# The following section is specific to Flutter packages. +flutter: + + # To add assets to your package, add an assets section, like this: + # assets: + # - images/a_dot_burr.jpeg + # - images/a_dot_ham.jpeg + # + # For details regarding assets in packages, see + # https://flutter.dev/to/asset-from-package + # + # An image asset can refer to one or more resolution-specific "variants", see + # https://flutter.dev/to/resolution-aware-images + + # To add custom fonts to your package, add a fonts section here, + # in this "flutter" section. Each entry in this list should have a + # "family" key with the font family name, and a "fonts" key with a + # list giving the asset and other descriptors for the font. For + # example: + # fonts: + # - family: Schyler + # fonts: + # - asset: fonts/Schyler-Regular.ttf + # - asset: fonts/Schyler-Italic.ttf + # style: italic + # - family: Trajan Pro + # fonts: + # - asset: fonts/TrajanPro.ttf + # - asset: fonts/TrajanPro_Bold.ttf + # weight: 700 + # + # For details regarding fonts in packages, see + # https://flutter.dev/to/font-from-package diff --git a/pubspec.lock b/pubspec.lock index db41fa9..a88d640 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -432,6 +432,13 @@ packages: url: "https://pub.dev" source: hosted version: "1.17.0" + monitoring_repository: + dependency: "direct main" + description: + path: "packages/monitoring_repository" + relative: true + source: path + version: "0.0.1" native_toolchain_c: dependency: transitive description: @@ -669,5 +676,5 @@ packages: source: hosted version: "3.1.3" sdks: - dart: ">=3.10.3 <4.0.0" + dart: ">=3.10.7 <4.0.0" flutter: ">=3.38.4" diff --git a/pubspec.yaml b/pubspec.yaml index 179a7fd..a9c35a5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: klimatologiot -description: "A new Flutter project." +description: 'A new Flutter project.' publish_to: 'none' version: 1.0.0+1 environment: @@ -22,6 +22,8 @@ dependencies: rxdart: ^0.27.7 user_repository: path: packages/user_repository + monitoring_repository: + path: packages/monitoring_repository dev_dependencies: flutter_lints: ^3.0.0 diff --git a/test/widget_test.dart b/test/widget_test.dart index 7096fb9..7a974a8 100644 --- a/test/widget_test.dart +++ b/test/widget_test.dart @@ -5,15 +5,80 @@ // gestures. You can also use WidgetTester to find child widgets in the widget // tree, read text, and verify that the values of widget properties are correct. +import 'package:firebase_database/firebase_database.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; +import 'package:monitoring_repository/monitoring_repository.dart'; +import 'package:user_repository/user_repository.dart'; +import '../lib/app.dart'; -import 'package:klimatologiot/main.dart'; +// import 'package:klimatologiot/main.dart'; + +class FakeUserRepository implements UserRepository { + @override + Stream get user => const Stream.empty(); + + @override + Future logOut() async {} + + @override + Future setUserData(MyUser user) { + // TODO: implement setUserData + throw UnimplementedError(); + } + + @override + Future signIn(String email, String password) { + // TODO: implement signIn + throw UnimplementedError(); + } + + @override + Future signInWithGoogle() { + // TODO: implement signInWithGoogle + throw UnimplementedError(); + } + + @override + Future signUp(MyUser myUser, String password) { + // TODO: implement signUp + throw UnimplementedError(); + } + + // tambahin kalau ada method lain +} + +class FakeMonitoringRepository implements MonitoringRepository { + get _db => null; + + // Satu fungsi untuk semua jenis sensor + // Kamu cukup masukkan "path" database-nya saja + + @override + // Jika ingin mengambil data sekali saja (bukan stream) + Future getSensorSnapshot(String path) async { + return await _db.ref(path).get(); + } + + @override + Stream getSensorStream(String path) { + // TODO: implement getSensorStream + throw UnimplementedError(); + } +} void main() { - testWidgets('Counter increments smoke test', (WidgetTester tester) async { + testWidgets('App loads', (WidgetTester tester) async { + final fakeRepo = FakeUserRepository(); + final fakeMonitoring = FakeUserRepository(); // Build our app and trigger a frame. - await tester.pumpWidget(const MyApp()); + await tester.pumpWidget( + MyApp(fakeRepo, fakeMonitoring as MonitoringRepository), + ); + + await tester.pump(); + + expect(find.byType(MaterialApp), findsOneWidget); // Verify that our counter starts at 0. expect(find.text('0'), findsOneWidget); From ea24df2e53eb6650dd4b83f33fc3198511e3f91f Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Sun, 12 Apr 2026 14:03:50 +0700 Subject: [PATCH 23/28] e --- packages/monitoring_repository/lib/src/models/evaporasi.dart | 0 packages/monitoring_repository/lib/src/models/wind_speed.dart | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 packages/monitoring_repository/lib/src/models/evaporasi.dart diff --git a/packages/monitoring_repository/lib/src/models/evaporasi.dart b/packages/monitoring_repository/lib/src/models/evaporasi.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/monitoring_repository/lib/src/models/wind_speed.dart b/packages/monitoring_repository/lib/src/models/wind_speed.dart index 221cfb6..8aa88fb 100644 --- a/packages/monitoring_repository/lib/src/models/wind_speed.dart +++ b/packages/monitoring_repository/lib/src/models/wind_speed.dart @@ -15,7 +15,7 @@ class MyWindSpeed { pulse: (json['pulse'] ?? 0) as int, timestamp: DateTime.fromMillisecondsSinceEpoch( (json['timestamp'] ?? 0) * 1000, // kalau dari Unix detik - ), + ).toLocal(), ); } } From 015ff0da93913296926a9ef77bcaba144255d534 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Sun, 12 Apr 2026 16:58:22 +0700 Subject: [PATCH 24/28] josssssss --- .../lib/src/firebase_monitoring_repo.dart | 23 +++++++++++++++---- .../lib/src/models/models.dart | 2 ++ .../lib/src/models/pressure_sensor.dart | 0 .../lib/src/monitoring_repo.dart | 11 +++++++-- 4 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 packages/monitoring_repository/lib/src/models/pressure_sensor.dart diff --git a/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart b/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart index 465237d..142ed18 100644 --- a/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart +++ b/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart @@ -11,13 +11,28 @@ class FirebaseMonitoringRepo implements MonitoringRepository { // Satu fungsi untuk semua jenis sensor // Kamu cukup masukkan "path" database-nya saja @override - Stream getSensorStream(String path) { - return _db.ref(path).onValue; + Stream getSensorStream( + String path, + T Function(Map json) mapper, + ) { + /// === ambil data mentah dari firebase === /// + return _db.ref(path).onValue.map((event) { + /// == ambil value-nya dan pastikan tipenya map == /// + final data = event.snapshot.value as Map? ?? {}; + + /// == masukan ke dalam "pabrik" (mapper) agar jadi objek == /// + return mapper(data); + }); } @override // Jika ingin mengambil data sekali saja (bukan stream) - Future getSensorSnapshot(String path) async { - return await _db.ref(path).get(); + Future getSensorSnapshot( + String path, + T Function(Map json) mapper, + ) async { + final snapshot = await _db.ref(path).get(); + final data = snapshot.value as Map? ?? {}; + return mapper(data); } } diff --git a/packages/monitoring_repository/lib/src/models/models.dart b/packages/monitoring_repository/lib/src/models/models.dart index fd4175e..f4c6e66 100644 --- a/packages/monitoring_repository/lib/src/models/models.dart +++ b/packages/monitoring_repository/lib/src/models/models.dart @@ -1 +1,3 @@ export 'wind_speed.dart'; +export 'evaporasi.dart'; +export 'pressure_sensor.dart'; diff --git a/packages/monitoring_repository/lib/src/models/pressure_sensor.dart b/packages/monitoring_repository/lib/src/models/pressure_sensor.dart new file mode 100644 index 0000000..e69de29 diff --git a/packages/monitoring_repository/lib/src/monitoring_repo.dart b/packages/monitoring_repository/lib/src/monitoring_repo.dart index 83b7bba..74f922f 100644 --- a/packages/monitoring_repository/lib/src/monitoring_repo.dart +++ b/packages/monitoring_repository/lib/src/monitoring_repo.dart @@ -1,7 +1,14 @@ import 'package:firebase_database/firebase_database.dart'; +import 'models/models.dart'; abstract class MonitoringRepository { - Stream getSensorStream(String path); + Stream getSensorStream( + String path, + T Function(Map json) mapper, + ); - Future getSensorSnapshot(String path); + Future getSensorSnapshot( + String path, + T Function(Map json) mapper, + ); } From 60b2047eaef9c0cbd24850ba2006c830c2b33dbc Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Sun, 12 Apr 2026 17:28:16 +0700 Subject: [PATCH 25/28] jossss --- lib/screens/home/views/home_screen.dart | 774 +----------------- .../wind_speed/blocs/wind_speed_bloc.dart | 45 +- .../wind_speed/blocs/wind_speed_event.dart | 24 + .../wind_speed/blocs/wind_speed_state.dart | 33 + .../wind_speed/views/annual_section.dart | 226 ----- .../wind_speed/views/explanation.dart | 45 - .../wind_speed/views/graph_block.dart | 253 ------ .../wind_speed/views/status_block.dart | 95 --- .../wind_speed/views/wind_speed.dart | 1 + .../views/wind_speed_annual_section.dart | 226 ----- .../views/wind_speed_graph_block.dart | 253 ------ .../monitoring/wind_speed/wind_speed.dart | 272 ------ .../wind_speed_monitoring_screen.dart | 262 ------ .../lib/monitoring_repository.dart | 1 + .../lib/src/monitoring_repo.dart | 1 - 15 files changed, 98 insertions(+), 2413 deletions(-) delete mode 100644 lib/screens/monitoring/wind_speed/views/annual_section.dart delete mode 100644 lib/screens/monitoring/wind_speed/views/explanation.dart delete mode 100644 lib/screens/monitoring/wind_speed/views/graph_block.dart delete mode 100644 lib/screens/monitoring/wind_speed/views/status_block.dart create mode 100644 lib/screens/monitoring/wind_speed/views/wind_speed.dart delete mode 100644 lib/screens/monitoring/wind_speed/views/wind_speed_annual_section.dart delete mode 100644 lib/screens/monitoring/wind_speed/views/wind_speed_graph_block.dart delete mode 100644 lib/screens/monitoring/wind_speed/wind_speed.dart delete mode 100644 lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart diff --git a/lib/screens/home/views/home_screen.dart b/lib/screens/home/views/home_screen.dart index 8521eb9..2831845 100644 --- a/lib/screens/home/views/home_screen.dart +++ b/lib/screens/home/views/home_screen.dart @@ -1,780 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:fl_chart/fl_chart.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:firebase_database/firebase_database.dart'; -import 'dart:async'; -import '../../../blocs/authentication_bloc/authentication_bloc.dart'; -import '../../monitoring/evaporasi_monitoring_screen.dart'; -import '../../monitoring/wind_speed/wind_speed.dart'; -import '../../monitoring/air_quality_monitoring_screen.dart'; -class HomeScreen extends StatefulWidget { +class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); - @override - State createState() => _HomeScreenState(); -} - -// simple model to represent one activity log item -class ActivityItem { - final String type; // evaporasi, angin, udara, etc - final String message; - final DateTime time; - - ActivityItem({ - required this.type, - required this.message, - required this.time, - }); -} - -class _HomeScreenState extends State { - // Firebase realtime database references - final DatabaseReference _evaporasiRef = - FirebaseDatabase.instance.ref('kelompok1/evaporasi'); - final DatabaseReference _windSpeedRef = - FirebaseDatabase.instance.ref('anemometer/realtime'); - final DatabaseReference _airQualityRef = - FirebaseDatabase.instance.ref('air_quality/realtime'); - - // Stream subscriptions - StreamSubscription? _evaporasiSub; - StreamSubscription? _windSpeedSub; - StreamSubscription? _airQualitySub; - - // Realtime values - double _currentEvaporasi = 0.0; - double _currentWindSpeed = 0.0; - double _currentAirQuality = 0.0; - - DateTime? _evaporasiUpdateTime; - DateTime? _windSpeedUpdateTime; - DateTime? _airQualityUpdateTime; - - // Hourly data for charts (24 hours) - final List _evaporasiData = List.filled(24, 0.0); - final List _windSpeedData = List.filled(24, 0.0); - final List _airQualityData = List.filled(24, 0.0); - - // activity log - final List _activities = []; - - // Hourly aggregation helpers - double _evaporasiHourlyTotal = 0.0; - int _evaporasiHourlyCount = 0; - - double _windSpeedHourlyTotal = 0.0; - int _windSpeedHourlyCount = 0; - - double _airQualityHourlyTotal = 0.0; - int _airQualityHourlyCount = 0; - - int _currentHour = DateTime.now().hour; - - @override - void initState() { - super.initState(); - _evaporasiSub = _evaporasiRef.onValue.listen(_onEvaporasiData); - _windSpeedSub = _windSpeedRef.onValue.listen(_onWindSpeedData); - _airQualitySub = _airQualityRef.onValue.listen(_onAirQualityData); - } - - void _onEvaporasiData(DatabaseEvent event) { - final data = event.snapshot.value; - if (data is Map) { - final value = double.tryParse( - (data['evaporasi'] ?? data['nilai'] ?? 0).toString()) ?? - 0.0; - DateTime waktu; - - if (data.containsKey('timestamp')) { - final timestamp = - int.tryParse(data['timestamp']?.toString() ?? '0') ?? 0; - waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); - } else { - final hour = int.tryParse(data['jam']?.toString() ?? '0') ?? 0; - final minute = int.tryParse(data['menit']?.toString() ?? '0') ?? 0; - final now = DateTime.now(); - waktu = DateTime(now.year, now.month, now.day, hour, minute); - } - - setState(() { - _currentEvaporasi = value; - _evaporasiUpdateTime = waktu; - - // add to activity log - _activities.insert( - 0, - ActivityItem( - type: "evaporasi", - message: "Evaporasi tercatat ${value.toStringAsFixed(1)} mm", - time: waktu, - ), - ); - if (_activities.length > 50) _activities.removeLast(); - - final incomingHour = waktu.hour; - - if (incomingHour != _currentHour) { - if (_evaporasiHourlyCount > 0) { - final avg = _evaporasiHourlyTotal / _evaporasiHourlyCount; - _evaporasiData[_currentHour] = avg; - } - - _evaporasiHourlyTotal = 0.0; - _evaporasiHourlyCount = 0; - - _currentHour = incomingHour; - - if (incomingHour == 0) { - for (int i = 0; i < 24; i++) { - _evaporasiData[i] = 0.0; - } - } - } - - _evaporasiHourlyTotal += value; - _evaporasiHourlyCount++; - }); - } - } - - void _onWindSpeedData(DatabaseEvent event) { - final data = event.snapshot.value; - if (data is Map) { - final value = (data['kecepatan'] ?? 0).toDouble(); - final timestamp = data['timestamp'] ?? 0; - final waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); - - setState(() { - _currentWindSpeed = value; - _windSpeedUpdateTime = waktu; - - // add to activity log - _activities.insert( - 0, - ActivityItem( - type: "angin", - message: - "Kecepatan angin update menjadi ${value.toStringAsFixed(1)} km/h", - time: waktu, - ), - ); - if (_activities.length > 50) _activities.removeLast(); - - final incomingHour = waktu.hour; - - if (incomingHour != _currentHour) { - if (_windSpeedHourlyCount > 0) { - final avg = _windSpeedHourlyTotal / _windSpeedHourlyCount; - _windSpeedData[_currentHour] = avg; - } - - _windSpeedHourlyTotal = 0.0; - _windSpeedHourlyCount = 0; - - _currentHour = incomingHour; - - if (incomingHour == 0) { - for (int i = 0; i < 24; i++) { - _windSpeedData[i] = 0.0; - } - } - } - - _windSpeedHourlyTotal += value; - _windSpeedHourlyCount++; - }); - } - } - - void _onAirQualityData(DatabaseEvent event) { - final data = event.snapshot.value; - if (data is Map) { - final value = (data['aqi'] ?? 0).toDouble(); - final timestamp = data['timestamp'] ?? 0; - final waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); - - setState(() { - _currentAirQuality = value; - _airQualityUpdateTime = waktu; - - // add to activity log - _activities.insert( - 0, - ActivityItem( - type: "udara", - message: "AQI berubah menjadi ${value.toStringAsFixed(0)}", - time: waktu, - ), - ); - if (_activities.length > 50) _activities.removeLast(); - - final incomingHour = waktu.hour; - - if (incomingHour != _currentHour) { - if (_airQualityHourlyCount > 0) { - final avg = _airQualityHourlyTotal / _airQualityHourlyCount; - _airQualityData[_currentHour] = avg; - } - - _airQualityHourlyTotal = 0.0; - _airQualityHourlyCount = 0; - - _currentHour = incomingHour; - - if (incomingHour == 0) { - for (int i = 0; i < 24; i++) { - _airQualityData[i] = 0.0; - } - } - } - - _airQualityHourlyTotal += value; - _airQualityHourlyCount++; - }); - } - } - - @override - void dispose() { - _evaporasiSub?.cancel(); - _windSpeedSub?.cancel(); - _airQualitySub?.cancel(); - super.dispose(); - } - @override Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const Text("Monitoring Klimatologi"), - centerTitle: true, - ), - - /// 🔹 SIDEBAR (MENU 3 GARIS DI KIRI) - drawer: Drawer( - child: SafeArea( - child: ListView( - padding: EdgeInsets.zero, - children: [ - // 🔹 HEADER DENGAN AKUN INFO (dynamic dari AuthenticationBloc) - BlocBuilder( - builder: (context, state) { - final user = state.user; - final displayName = (user != null && user.name.isNotEmpty) - ? user.name - : 'Pengguna'; - final email = (user != null && user.email.isNotEmpty) - ? user.email - : 'Tidak ada email'; - final initials = (displayName.isNotEmpty) - ? displayName - .trim() - .split(' ') - .map((e) => e.isNotEmpty ? e[0] : '') - .take(2) - .join() - : 'U'; - - return UserAccountsDrawerHeader( - accountName: Text( - displayName, - style: const TextStyle(fontWeight: FontWeight.bold), - ), - accountEmail: Text(email), - currentAccountPicture: CircleAvatar( - backgroundColor: Colors.blue, - child: Text( - initials.toUpperCase(), - style: const TextStyle( - fontSize: 24, - fontWeight: FontWeight.bold, - color: Colors.white, - ), - ), - ), - ); - }, - ), - - // 🔹 DASHBOARD MENU - ListTile( - leading: const Icon(Icons.dashboard), - title: const Text("Dashboard"), - onTap: () { - Navigator.pop(context); - }, - ), - - const Divider(), - - // 🔹 MONITORING MENU - const Padding( - padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8), - child: Text( - "Monitoring", - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.bold, - color: Colors.grey, - ), - ), - ), - - _buildDrawerItem( - context, - "Evaporasi", - Icons.opacity, - ), - _buildDrawerItem( - context, - "Kecepatan Angin", - Icons.air, - ), - _buildDrawerItem( - context, - "Kualitas Udara", - Icons.cloud, - ), - const Divider(), - ListTile( - leading: const Icon(Icons.logout), - title: const Text('Logout'), - onTap: () async { - Navigator.pop(context); - // trigger logout via bloc - final bloc = context.read(); - bloc.add(const AuthenticationLogoutRequested()); - }, - ), - ], - ), - ), - ), - - /// 🔹 DASHBOARD UTAMA - 3 MONITORING - body: Padding( - padding: const EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - BlocBuilder( - builder: (context, state) { - final name = state.user?.name.isNotEmpty == true - ? state.user!.name - : 'Pengguna'; - return Text( - 'Selamat Datang $name', - style: const TextStyle( - fontSize: 22, - fontWeight: FontWeight.bold, - ), - ); - }, - ), - const SizedBox(height: 10), - const Text( - "Recent Activity", - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 16), - Expanded( - child: _activities.isEmpty - ? const Center(child: Text("Belum ada aktivitas")) - : ListView.builder( - itemCount: _activities.length, - itemBuilder: (context, index) { - final item = _activities[index]; - return _buildActivityTile(item); - }, - ), - ), - ], - ), - ), - ); - } - - /// DATA BLOCK - PREVIEW DATA HARI INI - Widget _buildDataBlock( - String title, - String value, - String unit, - Color color, - IconData icon, - ) { - return Expanded( - child: Container( - margin: const EdgeInsets.symmetric(horizontal: 4), - padding: const EdgeInsets.all(12), - decoration: BoxDecoration( - color: color.withOpacity(0.1), - borderRadius: BorderRadius.circular(12), - border: Border.all(color: color, width: 2), - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Icon(icon, color: color, size: 28), - const SizedBox(height: 8), - Text( - title, - style: const TextStyle( - fontSize: 12, - fontWeight: FontWeight.w600, - ), - textAlign: TextAlign.center, - ), - const SizedBox(height: 6), - Row( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.baseline, - textBaseline: TextBaseline.alphabetic, - children: [ - Text( - value, - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - color: color, - ), - ), - const SizedBox(width: 4), - Text( - unit, - style: TextStyle( - fontSize: 11, - color: Colors.grey.shade700, - ), - ), - ], - ), - ], - ), - ), - ); - } - - /// DRAWER ITEM - Widget _buildDrawerItem( - BuildContext context, - String title, - IconData icon, - ) { - return ListTile( - leading: Icon(icon), - title: Text(title), - onTap: () { - Navigator.pop(context); - Widget screen; - if (title == "Evaporasi") { - screen = const EvaporasiMonitoringScreen(); - } else if (title == "Kecepatan Angin") { - screen = const WindSpeedMonitoringScreen(); - } else if (title == "Kualitas Udara") { - screen = const AirQualityMonitoringScreen(); - } else { - return; - } - Navigator.push( - context, - MaterialPageRoute(builder: (context) => screen), - ); - }, - ); - } - - /// DASHBOARD CARD - PREVIEW GRAFIK 24 JAM - Widget _buildDashboardCard(BuildContext context, String title) { - return GestureDetector( - onTap: () { - Widget screen; - if (title == "Evaporasi") { - screen = const EvaporasiMonitoringScreen(); - } else if (title == "Kecepatan Angin") { - screen = const WindSpeedMonitoringScreen(); - } else if (title == "Kualitas Udara") { - screen = const AirQualityMonitoringScreen(); - } else { - return; - } - Navigator.push( - context, - MaterialPageRoute(builder: (context) => screen), - ); - }, - child: Card( - elevation: 4, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - child: Padding( - padding: const EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - title, - style: const TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - Container( - padding: const EdgeInsets.symmetric( - horizontal: 12, - vertical: 6, - ), - decoration: BoxDecoration( - color: Colors.green.shade100, - borderRadius: BorderRadius.circular(20), - ), - child: const Text( - "24 Jam", - style: TextStyle( - fontSize: 11, - fontWeight: FontWeight.w600, - color: Colors.green, - ), - ), - ), - ], - ), - const SizedBox(height: 16), - SizedBox( - height: 200, - child: LineChart( - LineChartData( - gridData: FlGridData( - show: true, - drawHorizontalLine: true, - drawVerticalLine: false, - horizontalInterval: 1, - getDrawingHorizontalLine: (value) { - return FlLine( - color: Colors.grey.shade300, - strokeWidth: 1, - ); - }, - ), - titlesData: FlTitlesData( - show: true, - bottomTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - interval: 3, - getTitlesWidget: (value, meta) { - return Text( - '${value.toInt()}h', - style: const TextStyle( - fontSize: 10, - color: Colors.grey, - ), - ); - }, - ), - ), - leftTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - interval: 1, - getTitlesWidget: (value, meta) { - return Text( - value.toInt().toString(), - style: const TextStyle( - fontSize: 9, - color: Colors.grey, - ), - ); - }, - reservedSize: 28, - ), - ), - topTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - rightTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - ), - borderData: FlBorderData( - show: true, - border: Border( - left: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - bottom: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - ), - ), - lineBarsData: [ - LineChartBarData( - spots: _getMonitoringData(title), - isCurved: true, - barWidth: 2.5, - dotData: FlDotData( - show: true, - getDotPainter: (spot, percent, barData, index) { - return FlDotCirclePainter( - radius: 4, - color: _getColorByTitle(title), - strokeWidth: 0, - ); - }, - ), - color: _getColorByTitle(title), - belowBarData: BarAreaData( - show: true, - color: _getColorByTitle(title).withOpacity(0.1), - ), - ), - ], - ), - ), - ), - const SizedBox(height: 12), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "Rata-rata: ${_getAverageData(title)}", - style: TextStyle( - fontSize: 12, - color: Colors.grey.shade700, - fontWeight: FontWeight.w600, - ), - ), - Text( - "Tap untuk detail", - style: TextStyle( - fontSize: 12, - color: Colors.grey.shade600, - fontStyle: FontStyle.italic, - ), - ), - ], - ), - ], - ), - ), - ), - ); - } - - /// GET MONITORING DATA FOR 24 HOURS - List _getMonitoringData(String title) { - late final List data; - - switch (title) { - case "Evaporasi": - data = _evaporasiData; - break; - case "Kecepatan Angin": - data = _windSpeedData; - break; - case "Kualitas Udara": - data = _airQualityData; - break; - default: - data = []; - } - - return List.generate( - data.length, - (index) => FlSpot(index.toDouble(), data[index]), - ); - } - - /// GET AVERAGE VALUE - String _getAverageData(String title) { - late final double average; - late final String unit; - - switch (title) { - case "Evaporasi": - average = _evaporasiData.isNotEmpty - ? _evaporasiData.reduce((a, b) => a + b) / _evaporasiData.length - : 0.0; - unit = "mm"; - break; - case "Kecepatan Angin": - average = _windSpeedData.isNotEmpty - ? _windSpeedData.reduce((a, b) => a + b) / _windSpeedData.length - : 0.0; - unit = "km/h"; - break; - case "Kualitas Udara": - average = _airQualityData.isNotEmpty - ? _airQualityData.reduce((a, b) => a + b) / _airQualityData.length - : 0.0; - unit = "AQI"; - break; - default: - return "N/A"; - } - - return "${average.toStringAsFixed(1)} $unit"; - } - - /// GET COLOR BY TITLE - Color _getColorByTitle(String title) { - switch (title) { - case "Evaporasi": - return Colors.blue; - case "Kecepatan Angin": - return Colors.green; - case "Kualitas Udara": - return Colors.orange; - default: - return Colors.grey; - } - } - - /// ACTIVITY TILE - Widget _buildActivityTile(ActivityItem item) { - IconData icon; - Color color; - - switch (item.type) { - case "evaporasi": - icon = Icons.opacity; - color = Colors.blue; - break; - case "angin": - icon = Icons.air; - color = Colors.green; - break; - case "udara": - icon = Icons.cloud; - color = Colors.orange; - break; - default: - icon = Icons.info; - color = Colors.grey; - } - - return Card( - margin: const EdgeInsets.only(bottom: 12), - child: ListTile( - leading: CircleAvatar( - backgroundColor: color.withOpacity(0.2), - child: Icon(icon, color: color), - ), - title: Text(item.message), - subtitle: Text( - "${item.time.hour}:${item.time.minute.toString().padLeft(2, '0')}", - ), - ), - ); + return Scaffold(); } } diff --git a/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart b/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart index b320ff6..e5b929f 100644 --- a/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart +++ b/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart @@ -1,15 +1,44 @@ +import 'dart:async'; +import 'package:bloc/bloc.dart'; +import 'package:equatable/equatable.dart'; import 'package:monitoring_repository/monitoring_repository.dart'; -class WindSpeedBloc { - final MonitoringRepository _repo; +part 'wind_speed_event.dart'; +part 'wind_speed_state.dart'; - WindSpeedBloc({required MonitoringRepository repo}) : _repo = repo; +class WindSpeedBloc extends Bloc { + final MonitoringRepository _repository; + StreamSubscription? _subscription; - void startListening() { - // 3. Sekarang kamu bisa akses _repo di dalam lingkup class ini - _repo.getSensorStream('anemometer/realtime').listen((event) { - // Olah datanya di sini - print(event.snapshot.value); + WindSpeedBloc({required MonitoringRepository repository}) + : _repository = repository, + super(const WindSpeedState()) { + // Handler saat aplikasi minta mulai monitoring + on((event, emit) { + _subscription?.cancel(); + _subscription = _repository + .getSensorStream( + 'anemometer/realtime', (json) => MyWindSpeed.fromJson(json)) + .listen((data) => add(_WindSpeedUpdated(data))); + }); + + // Handler saat ada data baru masuk (Pindahan logika dari Screen) + on<_WindSpeedUpdated>((event, emit) { + // Di sini kamu bisa tambahkan logika hitung rata-rata/grafik harian + emit(state.copyWith( + currentSpeed: event.data.speed, + isLoading: false, + )); + }); + + on((event, emit) { + emit(state.copyWith(selectedPeriod: event.period)); }); } + + @override + Future close() { + _subscription?.cancel(); // Supaya tidak bocor memorinya + return super.close(); + } } diff --git a/lib/screens/monitoring/wind_speed/blocs/wind_speed_event.dart b/lib/screens/monitoring/wind_speed/blocs/wind_speed_event.dart index e69de29..445c8c6 100644 --- a/lib/screens/monitoring/wind_speed/blocs/wind_speed_event.dart +++ b/lib/screens/monitoring/wind_speed/blocs/wind_speed_event.dart @@ -0,0 +1,24 @@ +part of 'wind_speed_bloc.dart'; + +sealed class WindSpeedEvent extends Equatable { + const WindSpeedEvent(); + @override + List get props => []; +} + +// Perintah untuk mulai dengerin data Firebase +class WatchWindSpeedStarted extends WindSpeedEvent {} + +// Perintah kalau user ganti filter (Hari Ini, Minggu Ini, dll) +class WindSpeedPeriodChanged extends WindSpeedEvent { + final String period; + const WindSpeedPeriodChanged(this.period); +} + +// Event internal: saat data baru masuk dari Firebase +class _WindSpeedUpdated extends WindSpeedEvent { + final MyWindSpeed data; + const _WindSpeedUpdated(this.data); + @override + List get props => [data]; +} diff --git a/lib/screens/monitoring/wind_speed/blocs/wind_speed_state.dart b/lib/screens/monitoring/wind_speed/blocs/wind_speed_state.dart index e69de29..fa9b167 100644 --- a/lib/screens/monitoring/wind_speed/blocs/wind_speed_state.dart +++ b/lib/screens/monitoring/wind_speed/blocs/wind_speed_state.dart @@ -0,0 +1,33 @@ +part of 'wind_speed_bloc.dart'; + +class WindSpeedState extends Equatable { + final double currentSpeed; + final String selectedPeriod; + final List dailySpeeds; // Untuk grafik + final bool isLoading; + + const WindSpeedState({ + this.currentSpeed = 0.0, + this.selectedPeriod = "Hari Ini", + this.dailySpeeds = const [], + this.isLoading = true, + }); + + WindSpeedState copyWith({ + double? currentSpeed, + String? selectedPeriod, + List? dailySpeeds, + bool? isLoading, + }) { + return WindSpeedState( + currentSpeed: currentSpeed ?? this.currentSpeed, + selectedPeriod: selectedPeriod ?? this.selectedPeriod, + dailySpeeds: dailySpeeds ?? this.dailySpeeds, + isLoading: isLoading ?? this.isLoading, + ); + } + + @override + List get props => + [currentSpeed, selectedPeriod, dailySpeeds, isLoading]; +} diff --git a/lib/screens/monitoring/wind_speed/views/annual_section.dart b/lib/screens/monitoring/wind_speed/views/annual_section.dart deleted file mode 100644 index b414642..0000000 --- a/lib/screens/monitoring/wind_speed/views/annual_section.dart +++ /dev/null @@ -1,226 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:fl_chart/fl_chart.dart'; - -import '../../shared/widgets/monitoring_shared.dart'; - -class WindSpeedAnnualSection extends StatelessWidget { - final VoidCallback onExportAnnual; - - const WindSpeedAnnualSection({ - super.key, - required this.onExportAnnual, - }); - final double _rataRata = 0.0; - final double _kecepatanMax = 0.0; - @override - Widget build(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - "Statistik Tahunan Kecepatan Angin", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 15), - Row( - children: [ - Expanded( - child: StatCard( - title: "Rata-rata Tahunan", - value: this._rataRata.toStringAsFixed(2), - color: const Color.fromARGB(255, 76, 120, 175), - icon: Icons.air, - ), - ), - SizedBox(width: 10), - Expanded( - child: StatCard( - title: "Kecepatan Max", - value: this._kecepatanMax.toStringAsFixed(2), - color: const Color.fromARGB(255, 109, 109, 109), - icon: Icons.trending_up, - ), - ), - ], - ), - const SizedBox(height: 20), - const Text( - "Grafik Tahunan - Rata-rata & Kecepatan Maksimal", - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w600, - ), - ), - const SizedBox(height: 12), - Card( - elevation: 3, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - child: Padding( - padding: const EdgeInsets.all(16), - child: SizedBox( - height: 320, - child: LineChart( - LineChartData( - gridData: FlGridData( - show: true, - drawHorizontalLine: true, - drawVerticalLine: false, - horizontalInterval: 2, - getDrawingHorizontalLine: (value) { - return FlLine( - color: const Color.fromARGB(255, 224, 224, 224), - strokeWidth: 1, - ); - }, - ), - titlesData: FlTitlesData( - show: true, - bottomTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - leftTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - topTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - rightTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - ), - borderData: FlBorderData( - show: true, - border: Border( - left: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - bottom: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - ), - ), - lineBarsData: [ - LineChartBarData( - spots: const [ - FlSpot(0, 5.5), - FlSpot(1, 6.2), - FlSpot(2, 6.8), - FlSpot(3, 7.5), - FlSpot(4, 7.8), - FlSpot(5, 8.0), - FlSpot(6, 8.2), - FlSpot(7, 8.0), - FlSpot(8, 7.2), - FlSpot(9, 6.5), - FlSpot(10, 5.8), - FlSpot(11, 5.2), - ], - isCurved: true, - barWidth: 2.5, - dotData: FlDotData( - show: true, - getDotPainter: (spot, percent, barData, index) { - return FlDotCirclePainter( - radius: 4, - color: Colors.green, - strokeWidth: 0, - ); - }, - ), - color: Colors.green, - belowBarData: BarAreaData( - show: true, - color: Colors.green.withOpacity(0.1), - ), - ), - LineChartBarData( - spots: const [ - FlSpot(0, 12.0), - FlSpot(1, 13.5), - FlSpot(2, 14.0), - FlSpot(3, 15.5), - FlSpot(4, 16.0), - FlSpot(5, 16.2), - FlSpot(6, 16.5), - FlSpot(7, 16.0), - FlSpot(8, 15.0), - FlSpot(9, 14.0), - FlSpot(10, 12.5), - FlSpot(11, 11.0), - ], - isCurved: true, - barWidth: 2.5, - dotData: FlDotData( - show: true, - getDotPainter: (spot, percent, barData, index) { - return FlDotCirclePainter( - radius: 4, - color: Colors.red, - strokeWidth: 0, - ); - }, - ), - color: Colors.red, - ), - ], - ), - ), - ), - ), - ), - const SizedBox(height: 15), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - width: 16, - height: 16, - decoration: BoxDecoration( - color: Colors.green, - borderRadius: BorderRadius.circular(3), - ), - ), - const SizedBox(width: 8), - const Text( - "Rata-rata (km/h)", - style: TextStyle(fontSize: 12), - ), - const SizedBox(width: 20), - Container( - width: 16, - height: 16, - decoration: BoxDecoration( - color: Colors.red, - borderRadius: BorderRadius.circular(3), - ), - ), - const SizedBox(width: 8), - const Text( - "Kecepatan Max (km/h)", - style: TextStyle(fontSize: 12), - ), - ], - ), - const SizedBox(height: 15), - Center( - child: ElevatedButton.icon( - onPressed: onExportAnnual, - icon: const Icon(Icons.file_download), - label: const Text("Download Excel Tahunan"), - style: ElevatedButton.styleFrom( - backgroundColor: Colors.green, - foregroundColor: Colors.white, - ), - ), - ), - ], - ); - } -} diff --git a/lib/screens/monitoring/wind_speed/views/explanation.dart b/lib/screens/monitoring/wind_speed/views/explanation.dart deleted file mode 100644 index 49b3340..0000000 --- a/lib/screens/monitoring/wind_speed/views/explanation.dart +++ /dev/null @@ -1,45 +0,0 @@ -import 'package:flutter/material.dart'; - -class WindSpeedExplanation extends StatelessWidget { - const WindSpeedExplanation({super.key}); - - @override - Widget build(BuildContext context) { - return Container( - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: const Color.fromARGB(255, 232, 240, 245), - borderRadius: BorderRadius.circular(12), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.2), - blurRadius: 3, - spreadRadius: 0, - offset: const Offset(0, 5), - ) - ]), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: const [ - Text( - "Penjelasan Kecepatan Angin", - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.bold, - color: Color.fromARGB(255, 0, 0, 0), - ), - ), - SizedBox(height: 10), - Text( - "Kecepatan angin adalah laju gerakan massa udara yang mengalir secara horizontal. Data kecepatan angin penting untuk prediksi cuaca, manajemen rawan angin, perencanaan energi terbarukan (angin), serta membantu dalam pengeringan hasil pertanian. Pengukuran dilakukan dalam satuan km/h.", - style: TextStyle( - fontSize: 12, - height: 1.6, - color: Color.fromARGB(255, 0, 0, 0), - ), - ), - ], - ), - ); - } -} diff --git a/lib/screens/monitoring/wind_speed/views/graph_block.dart b/lib/screens/monitoring/wind_speed/views/graph_block.dart deleted file mode 100644 index c24a730..0000000 --- a/lib/screens/monitoring/wind_speed/views/graph_block.dart +++ /dev/null @@ -1,253 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:fl_chart/fl_chart.dart'; - -import '../../shared/widgets/monitoring_shared.dart'; - -class WindSpeedGraphBlock extends StatelessWidget { - final String selectedPeriod; - final List dailySpeeds; - final bool isOnline; - final ValueChanged onPeriodChanged; - final ValueChanged onExportPressed; - - const WindSpeedGraphBlock({ - super.key, - required this.selectedPeriod, - required this.dailySpeeds, - required this.isOnline, - required this.onPeriodChanged, - required this.onExportPressed, - }); - - List _getPeriodSpots() { - switch (selectedPeriod) { - case "Hari Ini": - return List.generate(24, (i) { - final value = dailySpeeds[i]; - return FlSpot(i.toDouble(), value); - }); - case "Minggu Ini": - return const [ - FlSpot(0, 6.5), - FlSpot(1, 7.2), - FlSpot(2, 7.8), - FlSpot(3, 8.0), - FlSpot(4, 7.5), - FlSpot(5, 6.8), - FlSpot(6, 5.5), - ]; - case "Bulan Ini": - return const [ - FlSpot(0, 6.0), - FlSpot(1, 6.5), - FlSpot(2, 7.0), - FlSpot(3, 7.5), - FlSpot(4, 7.8), - FlSpot(5, 8.0), - FlSpot(6, 8.2), - FlSpot(7, 8.0), - FlSpot(8, 7.5), - FlSpot(9, 7.0), - FlSpot(10, 6.5), - FlSpot(11, 6.0), - ]; - default: - return []; - } - } - - @override - Widget build(BuildContext context) { - return Card( - elevation: 4, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - child: Padding( - padding: const EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text( - "Status Kecepatan Angin", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - Container( - padding: const EdgeInsets.symmetric( - horizontal: 10, - vertical: 5, - ), - decoration: BoxDecoration( - color: - isOnline ? Colors.green.shade100 : Colors.red.shade100, - borderRadius: BorderRadius.circular(20), - ), - child: Text( - isOnline ? "ONLINE" : "OFFLINE", - style: TextStyle( - fontSize: 11, - fontWeight: FontWeight.w600, - color: isOnline ? Colors.green : Colors.red, - ), - ), - ), - ], - ), - const SizedBox(height: 16), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Row( - children: - ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { - return Padding( - padding: const EdgeInsets.only(right: 8), - child: ChoiceChip( - label: Text(period), - selected: selectedPeriod == period, - onSelected: (selected) { - if (selected) { - onPeriodChanged(period); - } - }, - side: BorderSide.none, - backgroundColor: Colors.grey.withOpacity(0.1), - selectedColor: - const Color.fromARGB(255, 0, 136, 255), - labelStyle: TextStyle( - color: selectedPeriod == period - ? Colors.white - : Colors.black, - ), - ), - ); - }).toList(), - ), - ), - ), - const SizedBox(width: 8), - ElevatedButton.icon( - onPressed: () => onExportPressed(selectedPeriod), - icon: const Icon(Icons.download, size: 16), - label: const Text("Export"), - style: ElevatedButton.styleFrom( - backgroundColor: const Color.fromARGB(255, 0, 145, 255), - foregroundColor: Colors.white, - padding: const EdgeInsets.symmetric( - horizontal: 10, - vertical: 6, - ), - textStyle: const TextStyle(fontSize: 11), - ), - ), - ], - ), - const SizedBox(height: 16), - SizedBox( - height: 300, - child: LineChart( - LineChartData( - gridData: FlGridData( - show: true, - drawHorizontalLine: true, - drawVerticalLine: false, - horizontalInterval: 1, - getDrawingHorizontalLine: (value) { - return FlLine( - color: Colors.grey.shade300, - strokeWidth: 1, - ); - }, - ), - titlesData: FlTitlesData( - show: true, - bottomTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - interval: getPeriodInterval(selectedPeriod), - getTitlesWidget: (value, meta) { - return Text( - getPeriodLabel(selectedPeriod, value), - style: const TextStyle( - fontSize: 10, - color: Colors.grey, - ), - ); - }, - ), - ), - leftTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - interval: 1, - getTitlesWidget: (value, meta) { - return Text( - value.toInt().toString(), - style: const TextStyle( - fontSize: 9, - color: Colors.grey, - ), - ); - }, - reservedSize: 28, - ), - ), - topTitles: - AxisTitles(sideTitles: SideTitles(showTitles: false)), - rightTitles: - AxisTitles(sideTitles: SideTitles(showTitles: false)), - ), - borderData: FlBorderData( - show: true, - border: Border( - left: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - bottom: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - ), - ), - lineBarsData: [ - LineChartBarData( - spots: _getPeriodSpots(), - isCurved: true, - barWidth: 2.5, - dotData: FlDotData( - show: true, - getDotPainter: (spot, percent, barData, index) { - return FlDotCirclePainter( - radius: 4, - color: const Color.fromARGB(255, 0, 191, 255), - strokeWidth: 0, - ); - }, - ), - color: const Color.fromARGB(255, 0, 191, 255), - belowBarData: BarAreaData( - show: true, - color: const Color.fromARGB(255, 0, 115, 255) - .withOpacity(0.1), - ), - ), - ], - ), - ), - ), - ], - ), - ), - ); - } -} diff --git a/lib/screens/monitoring/wind_speed/views/status_block.dart b/lib/screens/monitoring/wind_speed/views/status_block.dart deleted file mode 100644 index 24b305a..0000000 --- a/lib/screens/monitoring/wind_speed/views/status_block.dart +++ /dev/null @@ -1,95 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:intl/intl.dart'; - -class WindSpeedStatusBlock extends StatelessWidget { - final double currentSpeed; - final bool isOnline; - final DateTime lastUpdateTime; - - const WindSpeedStatusBlock({ - super.key, - required this.currentSpeed, - required this.isOnline, - required this.lastUpdateTime, - }); - - @override - Widget build(BuildContext context) { - final formattedTime = - DateFormat("dd MMM yyyy • HH:mm:ss").format(lastUpdateTime); - - /// ====== Current Speed bagian kode kecepatan angin ===== /// - return Padding( - padding: const EdgeInsets.only(bottom: 12), - child: Container( - padding: const EdgeInsets.all(16), - decoration: BoxDecoration( - color: Colors.grey.withOpacity(0.12), - borderRadius: BorderRadius.circular(16), - boxShadow: [ - BoxShadow( - color: Colors.black.withOpacity(0.05), - blurRadius: 12, - offset: const Offset(0, 4), - ), - ], - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - "Kecepatan Angin", - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 12), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Text( - "${currentSpeed.toStringAsFixed(2)} km/h", - style: const TextStyle( - fontSize: 28, - fontWeight: FontWeight.bold, - color: Color.fromARGB(255, 0, 0, 0), - ), - ), - - /// ==== bagian online offline status tampilan ==== /// - Container( - padding: const EdgeInsets.symmetric( - horizontal: 10, - vertical: 5, - ), - decoration: BoxDecoration( - color: - isOnline ? Colors.green.shade100 : Colors.red.shade100, - borderRadius: BorderRadius.circular(20), - ), - child: Text( - isOnline ? "ONLINE" : "OFFLINE", - style: TextStyle( - fontSize: 11, - fontWeight: FontWeight.w600, - color: isOnline ? Colors.green : Colors.red, - ), - ), - ), - ], - ), - const SizedBox(height: 10), - Text( - "Update: $formattedTime", - style: const TextStyle( - fontSize: 12, - color: Colors.grey, - ), - ), - ], - ), - ), - ); - } -} diff --git a/lib/screens/monitoring/wind_speed/views/wind_speed.dart b/lib/screens/monitoring/wind_speed/views/wind_speed.dart new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/lib/screens/monitoring/wind_speed/views/wind_speed.dart @@ -0,0 +1 @@ + diff --git a/lib/screens/monitoring/wind_speed/views/wind_speed_annual_section.dart b/lib/screens/monitoring/wind_speed/views/wind_speed_annual_section.dart deleted file mode 100644 index b414642..0000000 --- a/lib/screens/monitoring/wind_speed/views/wind_speed_annual_section.dart +++ /dev/null @@ -1,226 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:fl_chart/fl_chart.dart'; - -import '../../shared/widgets/monitoring_shared.dart'; - -class WindSpeedAnnualSection extends StatelessWidget { - final VoidCallback onExportAnnual; - - const WindSpeedAnnualSection({ - super.key, - required this.onExportAnnual, - }); - final double _rataRata = 0.0; - final double _kecepatanMax = 0.0; - @override - Widget build(BuildContext context) { - return Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - "Statistik Tahunan Kecepatan Angin", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - const SizedBox(height: 15), - Row( - children: [ - Expanded( - child: StatCard( - title: "Rata-rata Tahunan", - value: this._rataRata.toStringAsFixed(2), - color: const Color.fromARGB(255, 76, 120, 175), - icon: Icons.air, - ), - ), - SizedBox(width: 10), - Expanded( - child: StatCard( - title: "Kecepatan Max", - value: this._kecepatanMax.toStringAsFixed(2), - color: const Color.fromARGB(255, 109, 109, 109), - icon: Icons.trending_up, - ), - ), - ], - ), - const SizedBox(height: 20), - const Text( - "Grafik Tahunan - Rata-rata & Kecepatan Maksimal", - style: TextStyle( - fontSize: 14, - fontWeight: FontWeight.w600, - ), - ), - const SizedBox(height: 12), - Card( - elevation: 3, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - child: Padding( - padding: const EdgeInsets.all(16), - child: SizedBox( - height: 320, - child: LineChart( - LineChartData( - gridData: FlGridData( - show: true, - drawHorizontalLine: true, - drawVerticalLine: false, - horizontalInterval: 2, - getDrawingHorizontalLine: (value) { - return FlLine( - color: const Color.fromARGB(255, 224, 224, 224), - strokeWidth: 1, - ); - }, - ), - titlesData: FlTitlesData( - show: true, - bottomTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - leftTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - topTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - rightTitles: AxisTitles( - sideTitles: SideTitles(showTitles: false), - ), - ), - borderData: FlBorderData( - show: true, - border: Border( - left: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - bottom: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - ), - ), - lineBarsData: [ - LineChartBarData( - spots: const [ - FlSpot(0, 5.5), - FlSpot(1, 6.2), - FlSpot(2, 6.8), - FlSpot(3, 7.5), - FlSpot(4, 7.8), - FlSpot(5, 8.0), - FlSpot(6, 8.2), - FlSpot(7, 8.0), - FlSpot(8, 7.2), - FlSpot(9, 6.5), - FlSpot(10, 5.8), - FlSpot(11, 5.2), - ], - isCurved: true, - barWidth: 2.5, - dotData: FlDotData( - show: true, - getDotPainter: (spot, percent, barData, index) { - return FlDotCirclePainter( - radius: 4, - color: Colors.green, - strokeWidth: 0, - ); - }, - ), - color: Colors.green, - belowBarData: BarAreaData( - show: true, - color: Colors.green.withOpacity(0.1), - ), - ), - LineChartBarData( - spots: const [ - FlSpot(0, 12.0), - FlSpot(1, 13.5), - FlSpot(2, 14.0), - FlSpot(3, 15.5), - FlSpot(4, 16.0), - FlSpot(5, 16.2), - FlSpot(6, 16.5), - FlSpot(7, 16.0), - FlSpot(8, 15.0), - FlSpot(9, 14.0), - FlSpot(10, 12.5), - FlSpot(11, 11.0), - ], - isCurved: true, - barWidth: 2.5, - dotData: FlDotData( - show: true, - getDotPainter: (spot, percent, barData, index) { - return FlDotCirclePainter( - radius: 4, - color: Colors.red, - strokeWidth: 0, - ); - }, - ), - color: Colors.red, - ), - ], - ), - ), - ), - ), - ), - const SizedBox(height: 15), - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Container( - width: 16, - height: 16, - decoration: BoxDecoration( - color: Colors.green, - borderRadius: BorderRadius.circular(3), - ), - ), - const SizedBox(width: 8), - const Text( - "Rata-rata (km/h)", - style: TextStyle(fontSize: 12), - ), - const SizedBox(width: 20), - Container( - width: 16, - height: 16, - decoration: BoxDecoration( - color: Colors.red, - borderRadius: BorderRadius.circular(3), - ), - ), - const SizedBox(width: 8), - const Text( - "Kecepatan Max (km/h)", - style: TextStyle(fontSize: 12), - ), - ], - ), - const SizedBox(height: 15), - Center( - child: ElevatedButton.icon( - onPressed: onExportAnnual, - icon: const Icon(Icons.file_download), - label: const Text("Download Excel Tahunan"), - style: ElevatedButton.styleFrom( - backgroundColor: Colors.green, - foregroundColor: Colors.white, - ), - ), - ), - ], - ); - } -} diff --git a/lib/screens/monitoring/wind_speed/views/wind_speed_graph_block.dart b/lib/screens/monitoring/wind_speed/views/wind_speed_graph_block.dart deleted file mode 100644 index c24a730..0000000 --- a/lib/screens/monitoring/wind_speed/views/wind_speed_graph_block.dart +++ /dev/null @@ -1,253 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:fl_chart/fl_chart.dart'; - -import '../../shared/widgets/monitoring_shared.dart'; - -class WindSpeedGraphBlock extends StatelessWidget { - final String selectedPeriod; - final List dailySpeeds; - final bool isOnline; - final ValueChanged onPeriodChanged; - final ValueChanged onExportPressed; - - const WindSpeedGraphBlock({ - super.key, - required this.selectedPeriod, - required this.dailySpeeds, - required this.isOnline, - required this.onPeriodChanged, - required this.onExportPressed, - }); - - List _getPeriodSpots() { - switch (selectedPeriod) { - case "Hari Ini": - return List.generate(24, (i) { - final value = dailySpeeds[i]; - return FlSpot(i.toDouble(), value); - }); - case "Minggu Ini": - return const [ - FlSpot(0, 6.5), - FlSpot(1, 7.2), - FlSpot(2, 7.8), - FlSpot(3, 8.0), - FlSpot(4, 7.5), - FlSpot(5, 6.8), - FlSpot(6, 5.5), - ]; - case "Bulan Ini": - return const [ - FlSpot(0, 6.0), - FlSpot(1, 6.5), - FlSpot(2, 7.0), - FlSpot(3, 7.5), - FlSpot(4, 7.8), - FlSpot(5, 8.0), - FlSpot(6, 8.2), - FlSpot(7, 8.0), - FlSpot(8, 7.5), - FlSpot(9, 7.0), - FlSpot(10, 6.5), - FlSpot(11, 6.0), - ]; - default: - return []; - } - } - - @override - Widget build(BuildContext context) { - return Card( - elevation: 4, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), - ), - child: Padding( - padding: const EdgeInsets.all(16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - const Text( - "Status Kecepatan Angin", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - ), - ), - Container( - padding: const EdgeInsets.symmetric( - horizontal: 10, - vertical: 5, - ), - decoration: BoxDecoration( - color: - isOnline ? Colors.green.shade100 : Colors.red.shade100, - borderRadius: BorderRadius.circular(20), - ), - child: Text( - isOnline ? "ONLINE" : "OFFLINE", - style: TextStyle( - fontSize: 11, - fontWeight: FontWeight.w600, - color: isOnline ? Colors.green : Colors.red, - ), - ), - ), - ], - ), - const SizedBox(height: 16), - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Expanded( - child: SingleChildScrollView( - scrollDirection: Axis.horizontal, - child: Row( - children: - ["Hari Ini", "Minggu Ini", "Bulan Ini"].map((period) { - return Padding( - padding: const EdgeInsets.only(right: 8), - child: ChoiceChip( - label: Text(period), - selected: selectedPeriod == period, - onSelected: (selected) { - if (selected) { - onPeriodChanged(period); - } - }, - side: BorderSide.none, - backgroundColor: Colors.grey.withOpacity(0.1), - selectedColor: - const Color.fromARGB(255, 0, 136, 255), - labelStyle: TextStyle( - color: selectedPeriod == period - ? Colors.white - : Colors.black, - ), - ), - ); - }).toList(), - ), - ), - ), - const SizedBox(width: 8), - ElevatedButton.icon( - onPressed: () => onExportPressed(selectedPeriod), - icon: const Icon(Icons.download, size: 16), - label: const Text("Export"), - style: ElevatedButton.styleFrom( - backgroundColor: const Color.fromARGB(255, 0, 145, 255), - foregroundColor: Colors.white, - padding: const EdgeInsets.symmetric( - horizontal: 10, - vertical: 6, - ), - textStyle: const TextStyle(fontSize: 11), - ), - ), - ], - ), - const SizedBox(height: 16), - SizedBox( - height: 300, - child: LineChart( - LineChartData( - gridData: FlGridData( - show: true, - drawHorizontalLine: true, - drawVerticalLine: false, - horizontalInterval: 1, - getDrawingHorizontalLine: (value) { - return FlLine( - color: Colors.grey.shade300, - strokeWidth: 1, - ); - }, - ), - titlesData: FlTitlesData( - show: true, - bottomTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - interval: getPeriodInterval(selectedPeriod), - getTitlesWidget: (value, meta) { - return Text( - getPeriodLabel(selectedPeriod, value), - style: const TextStyle( - fontSize: 10, - color: Colors.grey, - ), - ); - }, - ), - ), - leftTitles: AxisTitles( - sideTitles: SideTitles( - showTitles: true, - interval: 1, - getTitlesWidget: (value, meta) { - return Text( - value.toInt().toString(), - style: const TextStyle( - fontSize: 9, - color: Colors.grey, - ), - ); - }, - reservedSize: 28, - ), - ), - topTitles: - AxisTitles(sideTitles: SideTitles(showTitles: false)), - rightTitles: - AxisTitles(sideTitles: SideTitles(showTitles: false)), - ), - borderData: FlBorderData( - show: true, - border: Border( - left: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - bottom: BorderSide( - color: Colors.grey.shade300, - width: 1, - ), - ), - ), - lineBarsData: [ - LineChartBarData( - spots: _getPeriodSpots(), - isCurved: true, - barWidth: 2.5, - dotData: FlDotData( - show: true, - getDotPainter: (spot, percent, barData, index) { - return FlDotCirclePainter( - radius: 4, - color: const Color.fromARGB(255, 0, 191, 255), - strokeWidth: 0, - ); - }, - ), - color: const Color.fromARGB(255, 0, 191, 255), - belowBarData: BarAreaData( - show: true, - color: const Color.fromARGB(255, 0, 115, 255) - .withOpacity(0.1), - ), - ), - ], - ), - ), - ), - ], - ), - ), - ); - } -} diff --git a/lib/screens/monitoring/wind_speed/wind_speed.dart b/lib/screens/monitoring/wind_speed/wind_speed.dart deleted file mode 100644 index db2c12a..0000000 --- a/lib/screens/monitoring/wind_speed/wind_speed.dart +++ /dev/null @@ -1,272 +0,0 @@ -import 'dart:async'; - -import '../'; -import 'package:flutter/material.dart'; - -import '../shared/widgets/monitoring_shared.dart'; -import 'views/annual_section.dart'; -import 'views/explanation.dart'; -import 'views/graph_block.dart'; -import 'views/status_block.dart'; -import 'package:google_fonts/google_fonts.dart'; - -class WindSpeedMonitoringScreen extends StatefulWidget { - const WindSpeedMonitoringScreen({super.key}); - - @override - State createState() => - _WindSpeedMonitoringScreenState(); -} - -class _WindSpeedMonitoringScreenState extends State { - String _selectedPeriod = "Hari Ini"; - - // realtime values - DateTime? _lastUpdateTime; - double _currentSpeed = 0.0; - final List _dailySpeeds = List.filled(24, 0.0); - - // hourly aggregation helpers (PRO version) - double _hourlyTotalSpeed = 0.0; - int _hourlyCount = 0; - int _currentHour = DateTime.now().hour; - - bool get _isOnline { - if (_lastUpdateTime == null) return false; - final diff = DateTime.now().difference(_lastUpdateTime!); - return diff.inSeconds <= 5; - } - - @override - void initState() { - super.initState(); - _realtimeSub = _realtimeRef.onValue.listen(_onRealtimeData); - } - - void _onRealtimeData(DatabaseEvent event) { - final data = event.snapshot.value; - - if (data is Map) { - final speed = (data['kecepatan'] ?? 0).toDouble(); - final timestamp = data['timestamp'] ?? 0; - - final waktu = - DateTime.fromMillisecondsSinceEpoch(timestamp * 1000).toLocal(); - - setState(() { - _currentSpeed = speed; - _lastUpdateTime = waktu; - - final incomingHour = waktu.hour; - - if (incomingHour != _currentHour) { - if (_hourlyCount > 0) { - final avg = _hourlyTotalSpeed / _hourlyCount; - _dailySpeeds[_currentHour] = avg; - } - - _hourlyTotalSpeed = 0.0; - _hourlyCount = 0; - _currentHour = incomingHour; - - if (incomingHour == 0) { - for (int i = 0; i < 24; i++) { - _dailySpeeds[i] = 0.0; - } - } - } - - _hourlyTotalSpeed += speed; - _hourlyCount++; - }); - } - } - - @override - void dispose() { - _realtimeSub?.cancel(); - super.dispose(); - } - - void _handleExportSelectedPeriod(String period) { - switch (period) { - case "Hari Ini": - _exportDailyWindData(); - break; - case "Minggu Ini": - _exportWeeklyWindData(); - break; - case "Bulan Ini": - _exportMonthlyWindData(); - break; - } - } - - void _exportDailyWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - HARIAN (24 JAM)"); - csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); - csvContent.writeln(""); - csvContent.writeln("Jam,Kecepatan (km/h)"); - - final dailyData = []; - - for (int i = 0; i < dailyData.length; i++) { - csvContent.writeln("$i:00,${dailyData[i]}"); - } - - csvContent.writeln(""); - csvContent.writeln("Statistik Harian"); - csvContent.writeln("Total: 165.8 km/h"); - csvContent.writeln("Rata-rata: 6.9 km/h"); - csvContent.writeln("Maksimal: 11.0 km/h"); - csvContent.writeln("Minimal: 4.3 km/h"); - - showExportPreview( - context, csvContent.toString(), "Data Harian Kecepatan Angin"); - } - - void _exportWeeklyWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - MINGGUAN"); - csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); - csvContent.writeln(""); - csvContent.writeln("Hari,Rata-rata (km/h)"); - - final days = [ - 'Senin', - 'Selasa', - 'Rabu', - 'Kamis', - 'Jumat', - 'Sabtu', - 'Minggu' - ]; - final weeklyData = [6.5, 7.2, 7.8, 8.0, 7.5, 6.8, 5.5]; - - for (int i = 0; i < days.length; i++) { - csvContent.writeln("${days[i]},${weeklyData[i]}"); - } - - csvContent.writeln(""); - csvContent.writeln("Statistik Mingguan"); - csvContent.writeln("Total: 49.3 km/h"); - csvContent.writeln("Rata-rata: 7.0 km/h"); - csvContent.writeln("Maksimal: 8.0 km/h"); - csvContent.writeln("Minimal: 5.5 km/h"); - - showExportPreview( - context, csvContent.toString(), "Data Mingguan Kecepatan Angin"); - } - - void _exportMonthlyWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - BULANAN"); - csvContent.writeln( - "Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); - csvContent.writeln(""); - csvContent.writeln("Tanggal,Rata-rata (km/h)"); - - for (int i = 1; i <= 28; i++) { - final value = (6.0 + (i % 6) * 0.8).toStringAsFixed(1); - csvContent.writeln("$i,$value"); - } - - csvContent.writeln(""); - csvContent.writeln("Statistik Bulanan"); - csvContent.writeln("Total: 180.5 km/h"); - csvContent.writeln("Rata-rata: 6.4 km/h"); - csvContent.writeln("Maksimal: 9.0 km/h"); - csvContent.writeln("Minimal: 4.0 km/h"); - - showExportPreview( - context, csvContent.toString(), "Data Bulanan Kecepatan Angin"); - } - - void _exportAnnualWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - TAHUNAN"); - csvContent.writeln("Tahun: 2025"); - csvContent.writeln(""); - csvContent.writeln("Bulan,Rata-rata (km/h),Kecepatan Max (km/h)"); - - final months = [ - 'Januari', - 'Februari', - 'Maret', - 'April', - 'Mei', - 'Juni', - 'Juli', - 'Agustus', - 'September', - 'Oktober', - 'November', - 'Desember' - ]; - final averages = []; - final maxSpeed = []; - - for (int i = 0; i < months.length; i++) { - csvContent.writeln("${months[i]},${averages[i]},${maxSpeed[i]}"); - } - - csvContent.writeln(""); - csvContent.writeln("STATISTIK TAHUNAN"); - csvContent.writeln("Rata-rata Tahunan: 7.1 km/h"); - csvContent.writeln("Kecepatan Max Tertinggi: 16.5 km/h"); - csvContent.writeln("Kecepatan Min Terendah: 5.2 km/h"); - - showExportPreview( - context, csvContent.toString(), "Data Tahunan Kecepatan Angin"); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text( - "Wind Speed", - style: GoogleFonts.rubik( - color: Colors.black, fontWeight: FontWeight.bold), - ), - centerTitle: true, - backgroundColor: const Color.fromARGB(37, 158, 158, 158), - ), - body: Padding( - padding: const EdgeInsets.all(16), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (_lastUpdateTime != null) - WindSpeedStatusBlock( - currentSpeed: _currentSpeed, - isOnline: _isOnline, - lastUpdateTime: _lastUpdateTime!, - ), - const SizedBox(height: 20), - WindSpeedGraphBlock( - selectedPeriod: _selectedPeriod, - dailySpeeds: _dailySpeeds, - isOnline: _isOnline, - onPeriodChanged: (period) { - setState(() { - _selectedPeriod = period; - }); - }, - onExportPressed: _handleExportSelectedPeriod, - ), - const SizedBox(height: 25), - const WindSpeedExplanation(), - const SizedBox(height: 25), - WindSpeedAnnualSection( - onExportAnnual: _exportAnnualWindData, - ), - ], - ), - ), - ), - ); - } -} diff --git a/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart b/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart deleted file mode 100644 index b60ca89..0000000 --- a/lib/screens/monitoring/wind_speed/wind_speed_monitoring_screen.dart +++ /dev/null @@ -1,262 +0,0 @@ -import 'dart:async'; - -import 'package:firebase_database/firebase_database.dart'; -import 'package:flutter/material.dart'; - -import '../shared/widgets/monitoring_shared.dart'; -import 'views/annual_section.dart'; -import 'views/explanation.dart'; -import 'views/graph_block.dart'; -import 'views/status_block.dart'; -import 'package:google_fonts/google_fonts.dart'; - -class WindSpeedMonitoringScreen extends StatefulWidget { - const WindSpeedMonitoringScreen({super.key}); - - @override - State createState() => - _WindSpeedMonitoringScreenState(); -} - -class _WindSpeedMonitoringScreenState extends State { - String _selectedPeriod = "Hari Ini"; - - bool get _isOnline { - if (_lastUpdateTime == null) return false; - final diff = DateTime.now().difference(_lastUpdateTime!); - return diff.inSeconds <= 5; - } - - @override - void initState() { - super.initState(); - _realtimeSub = _realtimeRef.onValue.listen(_onRealtimeData); - } - - void _onRealtimeData(DatabaseEvent event) { - final data = event.snapshot.value; - - if (data is Map) { - final speed = (data['kecepatan'] ?? 0).toDouble(); - final timestamp = data['timestamp'] ?? 0; - - final waktu = - DateTime.fromMillisecondsSinceEpoch(timestamp * 1000).toLocal(); - - setState(() { - _currentSpeed = speed; - _lastUpdateTime = waktu; - - final incomingHour = waktu.hour; - - if (incomingHour != _currentHour) { - if (_hourlyCount > 0) { - final avg = _hourlyTotalSpeed / _hourlyCount; - _dailySpeeds[_currentHour] = avg; - } - - _hourlyTotalSpeed = 0.0; - _hourlyCount = 0; - _currentHour = incomingHour; - - if (incomingHour == 0) { - for (int i = 0; i < 24; i++) { - _dailySpeeds[i] = 0.0; - } - } - } - - _hourlyTotalSpeed += speed; - _hourlyCount++; - }); - } - } - - @override - void dispose() { - _realtimeSub?.cancel(); - super.dispose(); - } - - void _handleExportSelectedPeriod(String period) { - switch (period) { - case "Hari Ini": - _exportDailyWindData(); - break; - case "Minggu Ini": - _exportWeeklyWindData(); - break; - case "Bulan Ini": - _exportMonthlyWindData(); - break; - } - } - - void _exportDailyWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - HARIAN (24 JAM)"); - csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); - csvContent.writeln(""); - csvContent.writeln("Jam,Kecepatan (km/h)"); - - final dailyData = []; - - for (int i = 0; i < dailyData.length; i++) { - csvContent.writeln("$i:00,${dailyData[i]}"); - } - - csvContent.writeln(""); - csvContent.writeln("Statistik Harian"); - csvContent.writeln("Total: 165.8 km/h"); - csvContent.writeln("Rata-rata: 6.9 km/h"); - csvContent.writeln("Maksimal: 11.0 km/h"); - csvContent.writeln("Minimal: 4.3 km/h"); - - showExportPreview( - context, csvContent.toString(), "Data Harian Kecepatan Angin"); - } - - void _exportWeeklyWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - MINGGUAN"); - csvContent.writeln("Tanggal: ${DateTime.now().toString().split(' ')[0]}"); - csvContent.writeln(""); - csvContent.writeln("Hari,Rata-rata (km/h)"); - - final days = [ - 'Senin', - 'Selasa', - 'Rabu', - 'Kamis', - 'Jumat', - 'Sabtu', - 'Minggu' - ]; - final weeklyData = [6.5, 7.2, 7.8, 8.0, 7.5, 6.8, 5.5]; - - for (int i = 0; i < days.length; i++) { - csvContent.writeln("${days[i]},${weeklyData[i]}"); - } - - csvContent.writeln(""); - csvContent.writeln("Statistik Mingguan"); - csvContent.writeln("Total: 49.3 km/h"); - csvContent.writeln("Rata-rata: 7.0 km/h"); - csvContent.writeln("Maksimal: 8.0 km/h"); - csvContent.writeln("Minimal: 5.5 km/h"); - - showExportPreview( - context, csvContent.toString(), "Data Mingguan Kecepatan Angin"); - } - - void _exportMonthlyWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - BULANAN"); - csvContent.writeln( - "Bulan: ${DateTime.now().toString().split(' ')[0].substring(0, 7)}"); - csvContent.writeln(""); - csvContent.writeln("Tanggal,Rata-rata (km/h)"); - - for (int i = 1; i <= 28; i++) { - final value = (6.0 + (i % 6) * 0.8).toStringAsFixed(1); - csvContent.writeln("$i,$value"); - } - - csvContent.writeln(""); - csvContent.writeln("Statistik Bulanan"); - csvContent.writeln("Total: 180.5 km/h"); - csvContent.writeln("Rata-rata: 6.4 km/h"); - csvContent.writeln("Maksimal: 9.0 km/h"); - csvContent.writeln("Minimal: 4.0 km/h"); - - showExportPreview( - context, csvContent.toString(), "Data Bulanan Kecepatan Angin"); - } - - void _exportAnnualWindData() { - final StringBuffer csvContent = StringBuffer(); - csvContent.writeln("DATA MONITORING KECEPATAN ANGIN - TAHUNAN"); - csvContent.writeln("Tahun: 2025"); - csvContent.writeln(""); - csvContent.writeln("Bulan,Rata-rata (km/h),Kecepatan Max (km/h)"); - - final months = [ - 'Januari', - 'Februari', - 'Maret', - 'April', - 'Mei', - 'Juni', - 'Juli', - 'Agustus', - 'September', - 'Oktober', - 'November', - 'Desember' - ]; - final averages = []; - final maxSpeed = []; - - for (int i = 0; i < months.length; i++) { - csvContent.writeln("${months[i]},${averages[i]},${maxSpeed[i]}"); - } - - csvContent.writeln(""); - csvContent.writeln("STATISTIK TAHUNAN"); - csvContent.writeln("Rata-rata Tahunan: 7.1 km/h"); - csvContent.writeln("Kecepatan Max Tertinggi: 16.5 km/h"); - csvContent.writeln("Kecepatan Min Terendah: 5.2 km/h"); - - showExportPreview( - context, csvContent.toString(), "Data Tahunan Kecepatan Angin"); - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text( - "Wind Speed", - style: GoogleFonts.rubik( - color: Colors.black, fontWeight: FontWeight.bold), - ), - centerTitle: true, - backgroundColor: const Color.fromARGB(37, 158, 158, 158), - ), - body: Padding( - padding: const EdgeInsets.all(16), - child: SingleChildScrollView( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (_lastUpdateTime != null) - WindSpeedStatusBlock( - currentSpeed: _currentSpeed, - isOnline: _isOnline, - lastUpdateTime: _lastUpdateTime!, - ), - const SizedBox(height: 20), - WindSpeedGraphBlock( - selectedPeriod: _selectedPeriod, - dailySpeeds: _dailySpeeds, - isOnline: _isOnline, - onPeriodChanged: (period) { - setState(() { - _selectedPeriod = period; - }); - }, - onExportPressed: _handleExportSelectedPeriod, - ), - const SizedBox(height: 25), - const WindSpeedExplanation(), - const SizedBox(height: 25), - WindSpeedAnnualSection( - onExportAnnual: _exportAnnualWindData, - ), - ], - ), - ), - ), - ); - } -} diff --git a/packages/monitoring_repository/lib/monitoring_repository.dart b/packages/monitoring_repository/lib/monitoring_repository.dart index 626b971..e5ff71e 100644 --- a/packages/monitoring_repository/lib/monitoring_repository.dart +++ b/packages/monitoring_repository/lib/monitoring_repository.dart @@ -2,3 +2,4 @@ library monitoring_repository; export 'src/monitoring_repo.dart'; export 'src/firebase_monitoring_repo.dart'; +export 'src/models/models.dart'; diff --git a/packages/monitoring_repository/lib/src/monitoring_repo.dart b/packages/monitoring_repository/lib/src/monitoring_repo.dart index 74f922f..d97747b 100644 --- a/packages/monitoring_repository/lib/src/monitoring_repo.dart +++ b/packages/monitoring_repository/lib/src/monitoring_repo.dart @@ -1,4 +1,3 @@ -import 'package:firebase_database/firebase_database.dart'; import 'models/models.dart'; abstract class MonitoringRepository { From 1239b39e307e4bbaa3bfb3567a44d1e4836a8761 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Sun, 12 Apr 2026 21:11:40 +0700 Subject: [PATCH 26/28] ok --- images/atmosfer.png | Bin 0 -> 14210 bytes images/google-icon-logo.png | Bin 0 -> 15459 bytes .../monitoring_bloc/monitoring_bloc.dart | 49 ------------ .../monitoring_bloc/monitoring_event.dart | 24 ------ .../monitoring_bloc/monitoring_state.dart | 33 -------- lib/screens/auth/views/sign_in_screen.dart | 15 ++-- lib/screens/auth/views/sign_up_screen.dart | 14 ++-- lib/screens/home/views/home_screen.dart | 58 +++++++++++++- lib/screens/home/views/main_drawer.dart | 74 ++++++++++++++++++ .../lib/src/firebase_monitoring_repo.dart | 4 +- pubspec.yaml | 4 +- 11 files changed, 151 insertions(+), 124 deletions(-) create mode 100644 images/atmosfer.png create mode 100644 images/google-icon-logo.png create mode 100644 lib/screens/home/views/main_drawer.dart diff --git a/images/atmosfer.png b/images/atmosfer.png new file mode 100644 index 0000000000000000000000000000000000000000..9b5815cab4b83cfc8fa1f7ca74223f3eed3ba28c GIT binary patch literal 14210 zcmb`ucT`hd*Dsn7AR^L1q$327F4DUNNCE=Vdr<_Wqx70YAC)346p=0jk=~@Y_=ut+ zAdx055u~@!qXamc_dECAanCsad}DkJ7$JMkz1G}o&b8)mmK}e`1kQAx_dEy$VnQPH z%t0U;;9nZhIeOq@FMQ-L@If1N6KQ!4_=!GuKMwfL5Qwk~0)d!&&;G!f(#(9oMV?@N z+hB_TkKnMokK93FVPSG!{ysr&cLUw!0v>thZffy@K*AuT-VMv}yp5T#YGT zJ#;m+iy#{?%RgBNZv{<|dDm^a1BkO)s#E#l!)V4p!9bmIi#m~JH7v}k?*gd_{}X?+ zsONRW1qvIPo)Aup#M*mm1agvNTotytml_(wi#FjjKO%jNkXWez3DPcZcz>AtSH*8L zQa`>i@_`L-8Q{MVsJ_iTRk8Glv>$GB9c$_41L=e8#`n~X$sR(4AY-orD~+(6zj^R| z$d=|3d0fcQO%f-e*8mWL;7j(lQl`N zhUva6-yoeQJtC}!wxr5!s#n2tbnmJXrZ}NkjSI#H4(8e~^|#|k{Vdl?CPjJki4dI8Z zD-whx>+)epp8d3f83Px!$S;nh4&3RYll+5t z$md-jz4v3kdyVW(p!~BOx}nU7_Dl2=M4AsXi=I4I7|vr^&o5Dsn)`#7j|*6G-r;lg z9%d3nN)7tN_1L~p<)#_x|8XHR_*|g!_QtHAjze@h;$zV7ipkX^d{{A~!ZS^@8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oX<6nDP6QY9k8sR9T}&OUek62N1uC;Ry&p?In!ErKP`JK7TmiInrF61fI>EU$>%O zd>WhzypJ;S4>Nv#m~Q#~WA^U?kj&1n;>@fp7bt1}4$#LUsW;TKrI9^ymHz@H z@BffC0Fp68=SC!#_$uDHrCeJm_{PAF%SRm iZs-3d|LDjmM1ql3Iq0*#J@CF92&r$PS98<#@&5wZ6(i*U literal 0 HcmV?d00001 diff --git a/images/google-icon-logo.png b/images/google-icon-logo.png new file mode 100644 index 0000000000000000000000000000000000000000..1253984b36afd83972e9c754b41cdca78c222421 GIT binary patch literal 15459 zcmXwgWmr_-*Y=rVfB^&s5KwaHPNi$;6p(IEknV1VkWd7qrBO<{J4Pf#8Ug8)kZzEC z=l6fE_rrWSd(Am}uiERr*WNLj>WcWd6u1BY;43T1X#oHT@!t=Mg?=)eP*@58FhE&O zTE`c(myHwnc;jDxu8nsR0vw$PX<)bQ*x{PRUt*dqDVb6Mi)bFB^eU$G-s=%T2n#Ac zPa7S6v3C$o9GlbAakn5%*;AM-J@3R+4vS{|v*33>N;wvyR69UZ*XAL9^GWEL*lFkJ zjrj7X+Y1S68-av07;iMHPn$VzZadR=EHZ2%i883=nb4nrO`(kdmkm#iFQcahUq+3` z|D0B?oYAV|XDzLs`FThm{2s=TPT8cb0Py<<&f7tX!7J3HLtSI^LZ^<$vFz0>q z)WsHa?xhr`d#0AsjVHDnMwT+b;vt%j7q@2h4wI-Bu%m~i(ye-B(QNLEZb}Z+Ul9LmX&c8CAKrTL3(S^ykKN<$^M#bH zz}lHCBs6bW!*%&6c|~9|V04{q@yi1EdS)LtxSWJ@Rd2#8uQdY*xa3;Ty9@x0i!AsD zjt!gok@fJ1qzK)JrwQJ)n_;`Ts+G_q1*N7`jxzAvZH}b)HQ>I>I$`~$J&G;zJ~U0p zf_b5`lMb^IU~*{8ezKD<#Z` z##ad~Ac29@uGx6|LKVm))P3CiX^C<-ofk+K>|fTE^y$F$u;_U+d~(7TWYpX+r+QR$ zzwr22u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?d{4KFdHeWLG)KRGa%NJ-k*nuUNIJb=*E z|9ui?4T*0O^1jcya`Rw+AT&`$py*QdVC`O;`C0nAw`4>JyzFvYlf{dx`*-~qg(>82 zqH;L&KBFTn$S&7wMv6=Vj?<@by*%|gI%qK_+XnW~@mSIENdkHV##7(;D{0oiCbL+yS-q!-^3ChHZsio!MZyi_py(Z1ObZQL{X zJ4^SU(f*M7%d>;qcGTbMrI`*X=2G`u_N8+hV`C{;Y)lRL;@Kqa-C zzxcB-((eq(4jz_%4BkVhBd1kZXaFcb_x6Y}|q=;F|3<_^;C~Kji zhv*A!!SOPJubHYh_qu}GihO71JLGH8EDAf>fH_2^Y~&4J1_kR^;kV1VsCkhrf=9_Z z2Y;8R&(+p1**~nFH%CtV498&7CAniF?L;W|YTOm3*c=B7d_1L;6y)LU*de^1C=CD? z4$@wx>FEd@S;+D=;lwu45MX;REUc1ON{Y@1C8x0RVvYU;U2(urIPy#L*nu Qpq~KB^6GMxG8SR~4^^&{`2YX_ literal 0 HcmV?d00001 diff --git a/lib/blocs/monitoring_bloc/monitoring_bloc.dart b/lib/blocs/monitoring_bloc/monitoring_bloc.dart index 9d83ea7..8b13789 100644 --- a/lib/blocs/monitoring_bloc/monitoring_bloc.dart +++ b/lib/blocs/monitoring_bloc/monitoring_bloc.dart @@ -1,50 +1 @@ -import 'dart:async'; -import 'package:bloc/bloc.dart'; -import 'package:equatable/equatable.dart'; -import 'package:firebase_database/firebase_database.dart'; - -part 'monitoring_event.dart'; -part 'monitoring_state.dart'; - -class MonitoringBloc extends Bloc { - final DatabaseReference _realtimeRef = - FirebaseDatabase.instance.ref('anemometer/realtime'); - StreamSubscription? _realtimeSub; - - MonitoringBloc() : super(const MonitoringState.initial()) { - on(_onLoadMonitoringData); - on(_onMonitoringDataUpdated); - } - - void _onLoadMonitoringData( - LoadMonitoringData event, Emitter emit) { - emit(const MonitoringState.loading()); - - // Start listening to realtime data - _realtimeSub = _realtimeRef.onValue.listen((event) { - final data = event.snapshot.value; - if (data is Map) { - final speed = (data['kecepatan'] ?? 0).toDouble(); - final timestamp = data['timestamp'] ?? 0; - final waktu = DateTime.fromMillisecondsSinceEpoch(timestamp * 1000); - - add(MonitoringDataUpdated(speed: speed, timestamp: waktu)); - } - }); - } - - void _onMonitoringDataUpdated( - MonitoringDataUpdated event, Emitter emit) { - emit(MonitoringState.loaded( - currentSpeed: event.speed, - lastUpdateTime: event.timestamp, - )); - } - - @override - Future close() { - _realtimeSub?.cancel(); - return super.close(); - } -} diff --git a/lib/blocs/monitoring_bloc/monitoring_event.dart b/lib/blocs/monitoring_bloc/monitoring_event.dart index e93e753..8b13789 100644 --- a/lib/blocs/monitoring_bloc/monitoring_event.dart +++ b/lib/blocs/monitoring_bloc/monitoring_event.dart @@ -1,25 +1 @@ -part of 'monitoring_bloc.dart'; -sealed class MonitoringEvent extends Equatable { - const MonitoringEvent(); - - @override - List get props => []; -} - -class LoadMonitoringData extends MonitoringEvent { - const LoadMonitoringData(); -} - -class MonitoringDataUpdated extends MonitoringEvent { - final double speed; - final DateTime timestamp; - - const MonitoringDataUpdated({ - required this.speed, - required this.timestamp, - }); - - @override - List get props => [speed, timestamp]; -} diff --git a/lib/blocs/monitoring_bloc/monitoring_state.dart b/lib/blocs/monitoring_bloc/monitoring_state.dart index 9e28f38..8b13789 100644 --- a/lib/blocs/monitoring_bloc/monitoring_state.dart +++ b/lib/blocs/monitoring_bloc/monitoring_state.dart @@ -1,34 +1 @@ -part of 'monitoring_bloc.dart'; -class MonitoringState extends Equatable { - final MonitoringStatus status; - final double? currentSpeed; - final DateTime? lastUpdateTime; - - const MonitoringState._({ - this.status = MonitoringStatus.initial, - this.currentSpeed, - this.lastUpdateTime, - }); - - const MonitoringState.initial() : this._(); - - const MonitoringState.loading() : this._(status: MonitoringStatus.loading); - - const MonitoringState.loaded({ - required double currentSpeed, - required DateTime lastUpdateTime, - }) : this._( - status: MonitoringStatus.loaded, - currentSpeed: currentSpeed, - lastUpdateTime: lastUpdateTime, - ); - - const MonitoringState.error(String message) - : this._(status: MonitoringStatus.error); - - @override - List get props => [status, currentSpeed, lastUpdateTime]; -} - -enum MonitoringStatus { initial, loading, loaded, error } diff --git a/lib/screens/auth/views/sign_in_screen.dart b/lib/screens/auth/views/sign_in_screen.dart index f687089..4eedd24 100644 --- a/lib/screens/auth/views/sign_in_screen.dart +++ b/lib/screens/auth/views/sign_in_screen.dart @@ -124,19 +124,22 @@ class _SignInScreenState extends State { )), ) : const CircularProgressIndicator(), + + /// ======= Tombol Login Google ======= /// const SizedBox(height: 20), SizedBox( width: MediaQuery.of(context).size.width * 0.5, child: TextButton.icon( onPressed: () { + // == Mengirim event login Google ke Bloc == // context.read().add(GoogleSignInRequired()); }, - icon: const Text( - 'G', - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - color: Colors.blue, + icon: SizedBox( + height: 20, + width: 20, + child: Image.asset( + 'images/google-icon-logo.png', + fit: BoxFit.contain, ), ), label: const Text( diff --git a/lib/screens/auth/views/sign_up_screen.dart b/lib/screens/auth/views/sign_up_screen.dart index 32b70e5..a32223e 100644 --- a/lib/screens/auth/views/sign_up_screen.dart +++ b/lib/screens/auth/views/sign_up_screen.dart @@ -234,16 +234,16 @@ class _SignUpScreenState extends State { .read() .add(GoogleSignInRequired()); }, - icon: const Text( - 'G', - style: TextStyle( - fontSize: 20, - fontWeight: FontWeight.bold, - color: Colors.blue, + icon: SizedBox( + height: 20, + width: 20, + child: Image.asset( + 'images/google-icon-logo.png', + fit: BoxFit.contain, ), ), label: const Text( - 'Daftar dengan Google', + 'Sign In With Google', style: TextStyle( color: Colors.black, fontSize: 16, diff --git a/lib/screens/home/views/home_screen.dart b/lib/screens/home/views/home_screen.dart index 2831845..007c2ff 100644 --- a/lib/screens/home/views/home_screen.dart +++ b/lib/screens/home/views/home_screen.dart @@ -1,10 +1,66 @@ import 'package:flutter/material.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import '../../../blocs/authentication_bloc/authentication_bloc.dart'; +import 'main_drawer.dart'; class HomeScreen extends StatelessWidget { const HomeScreen({super.key}); @override Widget build(BuildContext context) { - return Scaffold(); + return Scaffold( + drawer: const MainDrawer(), + appBar: AppBar( + backgroundColor: Colors.white, + elevation: 0.5, // Kasih sedikit bayangan tipis agar elegan + centerTitle: false, + leading: Builder( + builder: (context) => IconButton( + icon: const Icon(Icons.menu, + color: Colors.black), // Ikon garis 3 horizontal + onPressed: () { + // ini kodenya untuk membuka: + Scaffold.of(context).openDrawer(); + }, + )), + title: Row( + children: [ + // Ganti dengan Image.asset jika sudah ada logo + const Icon(Icons.cloud_queue, color: Colors.blue, size: 28), + const SizedBox(width: 10), + Text( + "Klimatologi", + style: GoogleFonts.rubik( + color: Colors.black, + fontWeight: FontWeight.bold, + fontSize: 20, + ), + ), + ], + ), + actions: [ + IconButton( + icon: const Icon(Icons.notifications_none, color: Colors.black), + onPressed: () { + // Aksi notifikasi + }, + ), + IconButton( + icon: const Icon(Icons.logout, color: Colors.black), + onPressed: () { + // Trigger Logout di AuthenticationBloc kamu + context + .read() + .add(AuthenticationLogoutRequested()); + }, + ), + const SizedBox(width: 8), + ], + ), + body: const Center( + child: Text("body home page"), + ), + ); } } diff --git a/lib/screens/home/views/main_drawer.dart b/lib/screens/home/views/main_drawer.dart new file mode 100644 index 0000000..4f50ed7 --- /dev/null +++ b/lib/screens/home/views/main_drawer.dart @@ -0,0 +1,74 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import '../../../blocs/authentication_bloc/authentication_bloc.dart'; + +class MainDrawer extends StatelessWidget { + const MainDrawer({super.key}); + + @override + Widget build(BuildContext context) { + return Drawer( + child: Column( + children: [ + // Bagian Header (Tempat Nama/Email) + BlocBuilder( + builder: (context, state) { + // Mengambil email user dari Bloc Global + String userEmail = state.user?.email ?? "Guest"; + String userName = + userEmail.split('@')[0]; // Ambil depan email saja + + return UserAccountsDrawerHeader( + decoration: const BoxDecoration(color: Colors.blue), + currentAccountPicture: const CircleAvatar( + backgroundColor: Colors.white, + child: Icon(Icons.person, size: 40, color: Colors.blue), + ), + accountName: Text( + userName, + style: const TextStyle(fontWeight: FontWeight.bold), + ), + accountEmail: Text(userEmail), + ); + }, + ), + + // Daftar Menu + ListTile( + leading: const Icon(Icons.speed), + title: const Text("Wind Speed"), + onTap: () { + // Navigasi ke Wind Speed + }, + ), + ListTile( + leading: const Icon(Icons.water_drop), + title: const Text("Evaporasi"), + onTap: () {}, + ), + ListTile( + leading: Image.asset( + 'images/atmosfer.png', + height: 20, + width: 20, + ), + title: const Text("Udara"), + onTap: () {}, + ), + const Spacer(), // Dorong menu logout ke paling bawah + const Divider(), + ListTile( + leading: const Icon(Icons.logout, color: Colors.red), + title: const Text("Logout", style: TextStyle(color: Colors.red)), + onTap: () { + context + .read() + .add(AuthenticationLogoutRequested()); + }, + ), + const SizedBox(height: 20), + ], + ), + ); + } +} diff --git a/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart b/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart index 142ed18..b5da549 100644 --- a/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart +++ b/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart @@ -1,6 +1,6 @@ -import 'dart:developer'; +// import 'dart:developer'; import 'dart:async'; -import 'package:rxdart/rxdart.dart'; +// import 'package:rxdart/rxdart.dart'; import 'package:firebase_database/firebase_database.dart'; import 'package:monitoring_repository/monitoring_repository.dart'; diff --git a/pubspec.yaml b/pubspec.yaml index a9c35a5..15b45a0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,5 +31,5 @@ dev_dependencies: sdk: flutter flutter: uses-material-design: true - # assets: - # - assets/images/ + assets: + - images/ From adaeff826fdf5ebe49edf9b5571c4dcdb9f6c8d0 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Tue, 14 Apr 2026 14:00:25 +0700 Subject: [PATCH 27/28] woowww josssjissss --- images/windy.png | Bin 0 -> 10022 bytes .../auth/blocs/sign_in_bloc/sign_in_bloc.dart | 1 + .../auth/blocs/sign_up_bloc/sign_up_bloc.dart | 10 - lib/screens/auth/views/sign_in_screen.dart | 15 +- lib/screens/auth/views/sign_up_screen.dart | 141 ++++++------ lib/screens/auth/views/welcome_screen.dart | 160 +++++++------- lib/screens/home/views/main_drawer.dart | 8 +- .../evaporasi/blocs/evaporasi_bloc.dart | 0 .../evaporasi/blocs/evaporasi_event.dart | 0 .../evaporasi/blocs/evaporasi_state.dart | 0 .../views/evaporasi.dart} | 2 +- .../wind_speed/blocs/wind_speed_bloc.dart | 45 ++-- .../wind_speed/views/wind_speed.dart | 1 - .../wind_speed/views/wind_speed_screen.dart | 10 + packages/module_repository/pubspec.lock | 205 ------------------ packages/module_repository/pubspec.yaml | 26 --- .../lib/src/firebase_monitoring_repo.dart | 11 +- .../lib/src/firebase_user_repo.dart | 5 + pubspec.lock | 16 ++ pubspec.yaml | 5 +- web/index.html | 46 ++-- 21 files changed, 256 insertions(+), 451 deletions(-) create mode 100644 images/windy.png create mode 100644 lib/screens/monitoring/evaporasi/blocs/evaporasi_bloc.dart create mode 100644 lib/screens/monitoring/evaporasi/blocs/evaporasi_event.dart create mode 100644 lib/screens/monitoring/evaporasi/blocs/evaporasi_state.dart rename lib/screens/monitoring/{evaporasi_monitoring_screen.dart => evaporasi/views/evaporasi.dart} (99%) delete mode 100644 lib/screens/monitoring/wind_speed/views/wind_speed.dart create mode 100644 lib/screens/monitoring/wind_speed/views/wind_speed_screen.dart delete mode 100644 packages/module_repository/pubspec.lock delete mode 100644 packages/module_repository/pubspec.yaml diff --git a/images/windy.png b/images/windy.png new file mode 100644 index 0000000000000000000000000000000000000000..b5389caef65dec3971ce80f7549ca706d23acc9f GIT binary patch literal 10022 zcmdUVc{r49`~N*N7)uBtSz{Rc9w!6HnTjbFv>|2LON* zv@pd1022O+1Xx+%kJZS*-|z<;-r{r!04(V2{Ua_Zbi-c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JwaTa16A-&JN?)5 z38i`!UZWjY@q0dzjWPSJO26TaUqxasEM7WV$hsgAyM^xh@yH+tb7Pbv5{`Xp=rjQ4 zUl&4Oi*Wf%#{N5S*x3q3w|~?qLI`*-gq(hZE|QFWzHy5qB;18$&xHo`5><4sbb3Np zZ*8YG0FecZOOyYw8#31l-!w~+&aNqp`R%sX$edZ02Jf$h52!$MlA5@! z0>2^~BTyZ-lgGZ#KCVK=0J0T%5l%c zBha+|%aaKxxnZJ}REO=r3sVq>-sFKJ!jEb=8DcA6_e9-aP)F7*ZrdC$Pi>u`cmyWXQ2vSo0CccWx2dez-I>_P>i+04- zD>BETty68u5-Ny|jE1S0th%8U4#;r;VOpiN)6xRAEo>mZBGHI=0G*i>=N6c|LHhkO ze$EsFehD$8x8YLs>HHY*P$v^jU^+Sbl>a!3wQ2UW6aX%2iAV0w6Dmw#ho!lxUAz9o zzoT6r9WI|JV%brc&n>NZ%&o(b94CFb=Q!@VIZ^v$mEAAh{u|^LcDTFRL^xt*)TVVO z`8!?tDW)8JZ}A;bl6+gOH8OA24^H2($v@#DxZiE?R!s*Bjc~XMPRp1H)m%}hck~`S z+K{fb3A0nxu8i>hWaZ$_cm13NItxQ^S_t#9bRkvHZQ<5%XE@D3%2gXAxvb|#V((h_ zb3P9ubI5?WQ??QYL8;2Ig<@w25h=lsVLCF{57kly+ig>P@a@GIxmWq1`Okj4{x5T)|8h1L|LQJaSNMu@>FP%VIL8eD&1_Ad{N-`={{gYoj_Lpa literal 0 HcmV?d00001 diff --git a/lib/screens/auth/blocs/sign_in_bloc/sign_in_bloc.dart b/lib/screens/auth/blocs/sign_in_bloc/sign_in_bloc.dart index d9502d1..5cdc2c8 100644 --- a/lib/screens/auth/blocs/sign_in_bloc/sign_in_bloc.dart +++ b/lib/screens/auth/blocs/sign_in_bloc/sign_in_bloc.dart @@ -24,6 +24,7 @@ class SignInBloc extends Bloc { await _userRepository.signInWithGoogle(); } catch (e) { emit(SignInFailure()); + emit(SignInInitial()); } }); diff --git a/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart b/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart index 7da96f5..647c241 100644 --- a/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart +++ b/lib/screens/auth/blocs/sign_up_bloc/sign_up_bloc.dart @@ -20,15 +20,5 @@ class SignUpBloc extends Bloc { emit(SignUpFailure(e.toString())); } }); - - on((event, emit) async { - emit(SignUpProcess()); - try { - await _userRepository.signInWithGoogle(); - emit(SignUpSuccess()); - } catch (e) { - emit(SignUpFailure(e.toString())); - } - }); } } diff --git a/lib/screens/auth/views/sign_in_screen.dart b/lib/screens/auth/views/sign_in_screen.dart index 4eedd24..84e359a 100644 --- a/lib/screens/auth/views/sign_in_screen.dart +++ b/lib/screens/auth/views/sign_in_screen.dart @@ -25,19 +25,20 @@ class _SignInScreenState extends State { Widget build(BuildContext context) { return BlocListener( listener: (context, state) { - if (state is SignInSuccess) { - setState(() { - signInRequired = false; - }); - } else if (state is SignInProcess) { + if (state is SignInProcess) { setState(() { signInRequired = true; }); - } else if (state is SignInFailure) { + } else { setState(() { signInRequired = false; - _errorMsg = 'Invalid email or password'; }); + if (state is SignInFailure) { + setState(() { + // PERUBAHAN: Pesan error lebih umum karena Google gagal belum tentu soal password + _errorMsg = 'Sign in failed. Please try again.'; + }); + } } }, child: Form( diff --git a/lib/screens/auth/views/sign_up_screen.dart b/lib/screens/auth/views/sign_up_screen.dart index a32223e..5d50a2f 100644 --- a/lib/screens/auth/views/sign_up_screen.dart +++ b/lib/screens/auth/views/sign_up_screen.dart @@ -3,10 +3,13 @@ import 'package:user_repository/user_repository.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../components/my_text_field.dart'; -import '../blocs/sign_up_bloc/sign_up_bloc.dart'; +import '../blocs/sign_up_bloc/sign_up_bloc.dart' as signUp; +// import '../../../blocs/authentication_bloc/authentication_bloc.dart'; +import '../blocs/sign_in_bloc/sign_in_bloc.dart' as signIn; class SignUpScreen extends StatefulWidget { - const SignUpScreen({super.key}); + final VoidCallback? onSignInTap; + const SignUpScreen({super.key, this.onSignInTap}); @override State createState() => _SignUpScreenState(); @@ -30,18 +33,26 @@ class _SignUpScreenState extends State { @override Widget build(BuildContext context) { - return BlocListener( + return BlocListener( listener: (context, state) { - if (state is SignUpSuccess) { - setState(() { - signUpRequired = false; - }); - } else if (state is SignUpProcess) { + if (state is signUp.SignUpProcess) { setState(() { signUpRequired = true; }); - } else if (state is SignUpFailure) { - return; + } else if (state is signUp.SignUpFailure) { + setState(() { + signUpRequired = false; // Matikan loading! + }); + // Tampilkan pesan error lewat Snackbar biar user tahu kenapa gagal + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + content: Text(state.message ?? 'An error ocurred'), + backgroundColor: Colors.red), + ); + } else if (state is signUp.SignUpSuccess) { + setState(() { + signUpRequired = false; + }); } }, child: Form( @@ -181,41 +192,48 @@ class _SignUpScreenState extends State { const SizedBox(height: 18), + /// == Sign Up == /// // Button !signUpRequired - ? SizedBox( - width: MediaQuery.of(context).size.width * 0.92, - child: ElevatedButton( - onPressed: () { - if (_formKey.currentState!.validate()) { - MyUser myUser = MyUser.empty; - myUser.email = emailController.text; - myUser.name = nameController.text; + ? Center( + child: SizedBox( + width: + MediaQuery.of(context).size.width * 0.5, + child: ElevatedButton( + onPressed: () { + if (_formKey.currentState!.validate()) { + MyUser myUser = MyUser.empty; + myUser.email = emailController.text; + myUser.name = nameController.text; - setState(() { - context.read().add( - SignUpRequired( - myUser, - passwordController.text, - ), - ); - }); - } - }, - style: ElevatedButton.styleFrom( - backgroundColor: Colors.black87, - foregroundColor: Colors.white, - padding: const EdgeInsets.symmetric( - vertical: 16), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), + setState(() { + context.read().add( + signUp.SignUpRequired( + myUser, + passwordController.text, + ), + ); + }); + } + }, + style: TextButton.styleFrom( + backgroundColor: + Theme.of(context).colorScheme.primary, + foregroundColor: Colors.white, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(60), + ), + ), + child: Padding( + padding: EdgeInsets.symmetric( + horizontal: 25, vertical: 5), + child: const Text( + 'Sign Up', + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600), + ), ), - ), - child: const Text( - 'Daftar', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600), ), ), ) @@ -225,39 +243,7 @@ class _SignUpScreenState extends State { Center( child: Text('Atau'), ), - const SizedBox(height: 12), - SizedBox( - width: MediaQuery.of(context).size.width * 0.92, - child: TextButton.icon( - onPressed: () { - context - .read() - .add(GoogleSignInRequired()); - }, - icon: SizedBox( - height: 20, - width: 20, - child: Image.asset( - 'images/google-icon-logo.png', - fit: BoxFit.contain, - ), - ), - label: const Text( - 'Sign In With Google', - style: TextStyle( - color: Colors.black, - fontSize: 16, - fontWeight: FontWeight.w600), - ), - style: TextButton.styleFrom( - backgroundColor: Colors.white, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(8), - side: const BorderSide(color: Colors.grey)), - padding: const EdgeInsets.symmetric(vertical: 16), - ), - ), - ), + const SizedBox(height: 12), Center( child: Row( @@ -266,9 +252,12 @@ class _SignUpScreenState extends State { const Text('Sudah punya akun? '), TextButton( onPressed: () { - Navigator.of(context).pop(); + widget.onSignInTap?.call(); }, - child: const Text('Login di sini'), + child: const Text( + 'Login di sini', + style: TextStyle(fontWeight: FontWeight.bold), + ), ) ], ), diff --git a/lib/screens/auth/views/welcome_screen.dart b/lib/screens/auth/views/welcome_screen.dart index 4ec3d63..2a5444c 100644 --- a/lib/screens/auth/views/welcome_screen.dart +++ b/lib/screens/auth/views/welcome_screen.dart @@ -13,90 +13,92 @@ class WelcomeScreen extends StatefulWidget { State createState() => _WelcomeScreenState(); } -class _WelcomeScreenState extends State with TickerProviderStateMixin { - late TabController tabController; +class _WelcomeScreenState extends State + with TickerProviderStateMixin { + late TabController tabController; - @override + @override void initState() { - tabController = TabController( - initialIndex: 0, - length: 2, - vsync: this - ); + tabController = TabController(initialIndex: 0, length: 2, vsync: this); super.initState(); } - @override Widget build(BuildContext context) { - return Scaffold( - backgroundColor: Colors.white, - body: SingleChildScrollView( - child: SizedBox( - height: MediaQuery.of(context).size.height, - child: Stack( - children: [ - Align( - alignment: Alignment.center, - child: SizedBox( - height: MediaQuery.of(context).size.height / 1.8, - child: Column( - children: [ - Padding( - padding: const EdgeInsets.symmetric(horizontal: 50.0), - child: TabBar( - controller: tabController, - unselectedLabelColor: Theme.of(context).colorScheme.onBackground.withOpacity(0.5), - labelColor: Theme.of(context).colorScheme.onBackground, - tabs: const [ - Padding( - padding: EdgeInsets.all(12.0), - child: Text( - 'Sign In', - style: TextStyle( - fontSize: 18, - ), - ), - ), - Padding( - padding: EdgeInsets.all(12.0), - child: Text( - 'Sign Up', - style: TextStyle( - fontSize: 18, - ), - ), - ), - ], - ), - ), - Expanded( - child: TabBarView( - controller: tabController, - children: [ - BlocProvider( - create: (context) => SignInBloc( - context.read().userRepository - ), - child: const SignInScreen(), - ), - BlocProvider( - create: (context) => SignUpBloc( - context.read().userRepository - ), - child: const SignUpScreen(), - ), - ], - ) - ) - ], - ), - ), - ) - ], - ), - ), - ), - ); + return Scaffold( + backgroundColor: Colors.white, + body: SingleChildScrollView( + child: SizedBox( + height: MediaQuery.of(context).size.height, + child: Stack( + children: [ + Align( + alignment: Alignment.center, + child: SizedBox( + height: MediaQuery.of(context).size.height / 1.8, + child: Column( + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 50.0), + child: TabBar( + controller: tabController, + unselectedLabelColor: Theme.of(context) + .colorScheme + .onBackground + .withOpacity(0.5), + labelColor: + Theme.of(context).colorScheme.onBackground, + tabs: const [ + Padding( + padding: EdgeInsets.all(12.0), + child: Text( + 'Sign In', + style: TextStyle( + fontSize: 18, + ), + ), + ), + Padding( + padding: EdgeInsets.all(12.0), + child: Text( + 'Sign Up', + style: TextStyle( + fontSize: 18, + ), + ), + ), + ], + ), + ), + Expanded( + child: TabBarView( + controller: tabController, + children: [ + BlocProvider( + create: (context) => SignInBloc(context + .read() + .userRepository), + child: const SignInScreen(), + ), + BlocProvider( + create: (context) => SignUpBloc(context + .read() + .userRepository), + child: SignUpScreen(onSignInTap: () { + tabController.animateTo( + 0); // Ini yang bikin dia pindah ke tab Login + }), + ), + ], + )) + ], + ), + ), + ) + ], + ), + ), + ), + ); } -} \ No newline at end of file +} diff --git a/lib/screens/home/views/main_drawer.dart b/lib/screens/home/views/main_drawer.dart index 4f50ed7..cc90626 100644 --- a/lib/screens/home/views/main_drawer.dart +++ b/lib/screens/home/views/main_drawer.dart @@ -35,7 +35,11 @@ class MainDrawer extends StatelessWidget { // Daftar Menu ListTile( - leading: const Icon(Icons.speed), + leading: Image.asset( + 'images/windy.png', + height: 20, + width: 20, + ), title: const Text("Wind Speed"), onTap: () { // Navigasi ke Wind Speed @@ -52,7 +56,7 @@ class MainDrawer extends StatelessWidget { height: 20, width: 20, ), - title: const Text("Udara"), + title: const Text("Tekanan Udara"), onTap: () {}, ), const Spacer(), // Dorong menu logout ke paling bawah diff --git a/lib/screens/monitoring/evaporasi/blocs/evaporasi_bloc.dart b/lib/screens/monitoring/evaporasi/blocs/evaporasi_bloc.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/screens/monitoring/evaporasi/blocs/evaporasi_event.dart b/lib/screens/monitoring/evaporasi/blocs/evaporasi_event.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/screens/monitoring/evaporasi/blocs/evaporasi_state.dart b/lib/screens/monitoring/evaporasi/blocs/evaporasi_state.dart new file mode 100644 index 0000000..e69de29 diff --git a/lib/screens/monitoring/evaporasi_monitoring_screen.dart b/lib/screens/monitoring/evaporasi/views/evaporasi.dart similarity index 99% rename from lib/screens/monitoring/evaporasi_monitoring_screen.dart rename to lib/screens/monitoring/evaporasi/views/evaporasi.dart index 3e67031..f31a02c 100644 --- a/lib/screens/monitoring/evaporasi_monitoring_screen.dart +++ b/lib/screens/monitoring/evaporasi/views/evaporasi.dart @@ -3,7 +3,7 @@ import 'package:fl_chart/fl_chart.dart'; import 'package:firebase_database/firebase_database.dart'; import 'dart:async'; import 'package:intl/intl.dart'; -import 'shared/widgets/monitoring_shared.dart'; +import '../../shared/widgets/monitoring_shared.dart'; /// EVAPORASI MONITORING SCREEN class EvaporasiMonitoringScreen extends StatefulWidget { diff --git a/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart b/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart index e5b929f..1ce90e6 100644 --- a/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart +++ b/lib/screens/monitoring/wind_speed/blocs/wind_speed_bloc.dart @@ -2,34 +2,44 @@ import 'dart:async'; import 'package:bloc/bloc.dart'; import 'package:equatable/equatable.dart'; import 'package:monitoring_repository/monitoring_repository.dart'; - +import 'package:bloc_concurrency/bloc_concurrency.dart'; part 'wind_speed_event.dart'; part 'wind_speed_state.dart'; class WindSpeedBloc extends Bloc { final MonitoringRepository _repository; - StreamSubscription? _subscription; WindSpeedBloc({required MonitoringRepository repository}) : _repository = repository, super(const WindSpeedState()) { // Handler saat aplikasi minta mulai monitoring - on((event, emit) { - _subscription?.cancel(); - _subscription = _repository - .getSensorStream( - 'anemometer/realtime', (json) => MyWindSpeed.fromJson(json)) - .listen((data) => add(_WindSpeedUpdated(data))); - }); + on( + (event, emit) async { + emit(state.copyWith(isLoading: true)); - // Handler saat ada data baru masuk (Pindahan logika dari Screen) - on<_WindSpeedUpdated>((event, emit) { - // Di sini kamu bisa tambahkan logika hitung rata-rata/grafik harian - emit(state.copyWith( - currentSpeed: event.data.speed, - isLoading: false, - )); - }); + await emit.forEach( + _repository.getSensorStream( + 'anemometer/realtime', (json) => MyWindSpeed.fromJson(json)), + onData: (data) { + // Mengambil list lama dan menambah data baru untuk grafik + final updatedSpeeds = List.from(state.dailySpeeds) + ..add(data.speed); + // Batasi jumlah data di grafik (misal cuma simpan 20 data terakhir agar tidak berat) + if (updatedSpeeds.length > 20) { + updatedSpeeds.removeAt(0); + } + + return state.copyWith( + currentSpeed: data.speed, + dailySpeeds: updatedSpeeds, // Update list grafik + isLoading: false, + ); + }, + onError: (error, stackTrace) => state.copyWith(isLoading: false), + ); // emit forEach + }, + transformer: restartable(), + ); on((event, emit) { emit(state.copyWith(selectedPeriod: event.period)); @@ -38,7 +48,6 @@ class WindSpeedBloc extends Bloc { @override Future close() { - _subscription?.cancel(); // Supaya tidak bocor memorinya return super.close(); } } diff --git a/lib/screens/monitoring/wind_speed/views/wind_speed.dart b/lib/screens/monitoring/wind_speed/views/wind_speed.dart deleted file mode 100644 index 8b13789..0000000 --- a/lib/screens/monitoring/wind_speed/views/wind_speed.dart +++ /dev/null @@ -1 +0,0 @@ - diff --git a/lib/screens/monitoring/wind_speed/views/wind_speed_screen.dart b/lib/screens/monitoring/wind_speed/views/wind_speed_screen.dart new file mode 100644 index 0000000..930d4d8 --- /dev/null +++ b/lib/screens/monitoring/wind_speed/views/wind_speed_screen.dart @@ -0,0 +1,10 @@ +import 'package:flutter/material.dart'; + +class WindSpeedScreen extends StatelessWidget { + const WindSpeedScreen({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold(); + } +} diff --git a/packages/module_repository/pubspec.lock b/packages/module_repository/pubspec.lock deleted file mode 100644 index 58d28ea..0000000 --- a/packages/module_repository/pubspec.lock +++ /dev/null @@ -1,205 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - sha256: "758e6d74e971c3e5aceb4110bfd6698efc7f501675bcfe0c775459a8140750eb" - url: "https://pub.dev" - source: hosted - version: "2.13.0" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - sha256: "8aab1771e1243a5063b8b0ff68042d67334e3feab9e95b9490f9a6ebf73b42ea" - url: "https://pub.dev" - source: hosted - version: "2.1.2" - characters: - dependency: transitive - description: - name: characters - sha256: f71061c654a3380576a52b451dd5532377954cf9dbd272a78fc8479606670803 - url: "https://pub.dev" - source: hosted - version: "1.4.0" - clock: - dependency: transitive - description: - name: clock - sha256: fddb70d9b5277016c77a80201021d40a2247104d9f4aa7bab7157b7e3f05b84b - url: "https://pub.dev" - source: hosted - version: "1.1.2" - collection: - dependency: transitive - description: - name: collection - sha256: "2f5709ae4d3d59dd8f7cd309b4e023046b57d8a6c82130785d2b0e5868084e76" - url: "https://pub.dev" - source: hosted - version: "1.19.1" - fake_async: - dependency: transitive - description: - name: fake_async - sha256: "5368f224a74523e8d2e7399ea1638b37aecfca824a3cc4dfdf77bf1fa905ac44" - url: "https://pub.dev" - source: hosted - version: "1.3.3" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_lints: - dependency: "direct dev" - description: - name: flutter_lints - sha256: a25a15ebbdfc33ab1cd26c63a6ee519df92338a9c10f122adda92938253bef04 - url: "https://pub.dev" - source: hosted - version: "2.0.3" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - leak_tracker: - dependency: transitive - description: - name: leak_tracker - sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" - url: "https://pub.dev" - source: hosted - version: "11.0.2" - leak_tracker_flutter_testing: - dependency: transitive - description: - name: leak_tracker_flutter_testing - sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" - url: "https://pub.dev" - source: hosted - version: "3.0.10" - leak_tracker_testing: - dependency: transitive - description: - name: leak_tracker_testing - sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" - url: "https://pub.dev" - source: hosted - version: "3.0.2" - lints: - dependency: transitive - description: - name: lints - sha256: "0a217c6c989d21039f1498c3ed9f3ed71b354e69873f13a8dfc3c9fe76f1b452" - url: "https://pub.dev" - source: hosted - version: "2.1.1" - matcher: - dependency: transitive - description: - name: matcher - sha256: dc58c723c3c24bf8d3e2d3ad3f2f9d7bd9cf43ec6feaa64181775e60190153f2 - url: "https://pub.dev" - source: hosted - version: "0.12.17" - material_color_utilities: - dependency: transitive - description: - name: material_color_utilities - sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec - url: "https://pub.dev" - source: hosted - version: "0.11.1" - meta: - dependency: transitive - description: - name: meta - sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" - url: "https://pub.dev" - source: hosted - version: "1.17.0" - path: - dependency: transitive - description: - name: path - sha256: "75cca69d1490965be98c73ceaea117e8a04dd21217b37b292c9ddbec0d955bc5" - url: "https://pub.dev" - source: hosted - version: "1.9.1" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.0" - source_span: - dependency: transitive - description: - name: source_span - sha256: "254ee5351d6cb365c859e20ee823c3bb479bf4a293c22d17a9f1bf144ce86f7c" - url: "https://pub.dev" - source: hosted - version: "1.10.1" - stack_trace: - dependency: transitive - description: - name: stack_trace - sha256: "8b27215b45d22309b5cddda1aa2b19bdfec9df0e765f2de506401c071d38d1b1" - url: "https://pub.dev" - source: hosted - version: "1.12.1" - stream_channel: - dependency: transitive - description: - name: stream_channel - sha256: "969e04c80b8bcdf826f8f16579c7b14d780458bd97f56d107d3950fdbeef059d" - url: "https://pub.dev" - source: hosted - version: "2.1.4" - string_scanner: - dependency: transitive - description: - name: string_scanner - sha256: "921cd31725b72fe181906c6a94d987c78e3b98c2e205b397ea399d4054872b43" - url: "https://pub.dev" - source: hosted - version: "1.4.1" - term_glyph: - dependency: transitive - description: - name: term_glyph - sha256: "7f554798625ea768a7518313e58f83891c7f5024f88e46e7182a4558850a4b8e" - url: "https://pub.dev" - source: hosted - version: "1.2.2" - test_api: - dependency: transitive - description: - name: test_api - sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55 - url: "https://pub.dev" - source: hosted - version: "0.7.7" - vector_math: - dependency: transitive - description: - name: vector_math - sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b - url: "https://pub.dev" - source: hosted - version: "2.2.0" - vm_service: - dependency: transitive - description: - name: vm_service - sha256: "45caa6c5917fa127b5dbcfbd1fa60b14e583afdc08bfc96dda38886ca252eb60" - url: "https://pub.dev" - source: hosted - version: "15.0.2" -sdks: - dart: ">=3.8.0-0 <4.0.0" - flutter: ">=3.18.0-18.0.pre.54" diff --git a/packages/module_repository/pubspec.yaml b/packages/module_repository/pubspec.yaml deleted file mode 100644 index 66996a7..0000000 --- a/packages/module_repository/pubspec.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: module_repository -description: The Repo that handles modules -publish_to: 'none' -version: 0.0.1 - -environment: - sdk: '>=3.1.0 <4.0.0' - -dependencies: - flutter: - sdk: flutter - - # equatable: ^2.0.5 - # firebase_auth: ^4.16.0 - # cloud_firestore: ^4.9.2 - # firebase_storage: ^11.6.0 - # rxdart: ^0.27.7 - # path: ^1.8.3 - -dev_dependencies: - flutter_test: - sdk: flutter - flutter_lints: ^2.0.0 - -flutter: - uses-material-design: true \ No newline at end of file diff --git a/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart b/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart index b5da549..5d19c33 100644 --- a/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart +++ b/packages/monitoring_repository/lib/src/firebase_monitoring_repo.dart @@ -17,11 +17,14 @@ class FirebaseMonitoringRepo implements MonitoringRepository { ) { /// === ambil data mentah dari firebase === /// return _db.ref(path).onValue.map((event) { - /// == ambil value-nya dan pastikan tipenya map == /// - final data = event.snapshot.value as Map? ?? {}; + final Object? value = event.snapshot.value; - /// == masukan ke dalam "pabrik" (mapper) agar jadi objek == /// - return mapper(data); + if (value is Map) { + return mapper(value); + } else { + // Jika data kosong atau bukan Map, berikan Map kosong agar mapper tidak crash + return mapper({}); + } }); } diff --git a/packages/user_repository/lib/src/firebase_user_repo.dart b/packages/user_repository/lib/src/firebase_user_repo.dart index b1b428f..62890c7 100644 --- a/packages/user_repository/lib/src/firebase_user_repo.dart +++ b/packages/user_repository/lib/src/firebase_user_repo.dart @@ -12,6 +12,7 @@ class FirebaseUserRepo implements UserRepository { FirebaseAuth? firebaseAuth, }) : _firebaseAuth = firebaseAuth ?? FirebaseAuth.instance; + /// == Melakukan Implement User == /// @override Stream get user { return _firebaseAuth.authStateChanges().flatMap((firebaseUser) async* { @@ -42,6 +43,7 @@ class FirebaseUserRepo implements UserRepository { }); } + /// == Melakukan Implement Sign in == /// @override Future signIn(String email, String password) async { try { @@ -53,6 +55,7 @@ class FirebaseUserRepo implements UserRepository { } } + /// == Melakukan Implement Sign Up == /// @override Future signUp(MyUser myUser, String password) async { try { @@ -66,6 +69,7 @@ class FirebaseUserRepo implements UserRepository { } } + /// == Melakukan Implement Log Out == /// @override Future logOut() async { await _firebaseAuth.signOut(); @@ -85,6 +89,7 @@ class FirebaseUserRepo implements UserRepository { } } + /// == Sign in with Google == /// @override Future signInWithGoogle() async { try { diff --git a/pubspec.lock b/pubspec.lock index a88d640..99e4d46 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -33,6 +33,14 @@ packages: url: "https://pub.dev" source: hosted version: "8.1.4" + bloc_concurrency: + dependency: "direct main" + description: + name: bloc_concurrency + sha256: "456b7a3616a7c1ceb975c14441b3f198bf57d81cb95b7c6de5cb0c60201afcd8" + url: "https://pub.dev" + source: hosted + version: "0.2.5" boolean_selector: dependency: transitive description: @@ -596,6 +604,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.4" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: ad47125e588cfd37a9a7f86c7d6356dde8dfe89d071d293f80ca9e9273a33871 + url: "https://pub.dev" + source: hosted + version: "2.1.1" string_scanner: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 15b45a0..378b697 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -6,6 +6,7 @@ environment: sdk: ^3.1.0 dependencies: bloc: ^8.1.0 + bloc_concurrency: ^0.2.5 cloud_firestore: ^6.1.1 cupertino_icons: ^1.0.8 equatable: ^2.0.5 @@ -19,11 +20,11 @@ dependencies: google_fonts: ^8.0.2 google_sign_in: ^7.2.0 intl: ^0.20.2 + monitoring_repository: + path: packages/monitoring_repository rxdart: ^0.27.7 user_repository: path: packages/user_repository - monitoring_repository: - path: packages/monitoring_repository dev_dependencies: flutter_lints: ^3.0.0 diff --git a/web/index.html b/web/index.html index 6438574..bc4b833 100644 --- a/web/index.html +++ b/web/index.html @@ -1,7 +1,7 @@ - + - - - + - - - + + + - - - - - + + + + + - - + + - klimatologiot - - - - - + klimatologiot + + + + + + + + From 7f5c50fa2404dedd71e37f84362370b5a6c614a2 Mon Sep 17 00:00:00 2001 From: kleponijo <158453666+kleponijo@users.noreply.github.com> Date: Tue, 14 Apr 2026 14:52:39 +0700 Subject: [PATCH 28/28] mantap --- lib/app.dart | 17 ++++- lib/screens/home/views/main_drawer.dart | 20 +++++ .../wind_speed/views/wind_speed_screen.dart | 75 ++++++++++++++++++- 3 files changed, 107 insertions(+), 5 deletions(-) diff --git a/lib/app.dart b/lib/app.dart index ddd5e93..7393d3e 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -12,9 +12,18 @@ class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { - return RepositoryProvider( - create: (context) => AuthenticationBloc(userRepository: userRepository), - child: const MyAppView(), - ); + return MultiRepositoryProvider( + providers: [ + // 1. Daftarkan UserRepository + RepositoryProvider.value(value: userRepository), + RepositoryProvider.value( + value: monitoringRepository), + ], + child: BlocProvider( + create: (context) => AuthenticationBloc( + userRepository: userRepository, + ), + child: const MyAppView(), + )); } } diff --git a/lib/screens/home/views/main_drawer.dart b/lib/screens/home/views/main_drawer.dart index cc90626..9c6b4a7 100644 --- a/lib/screens/home/views/main_drawer.dart +++ b/lib/screens/home/views/main_drawer.dart @@ -1,6 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:monitoring_repository/monitoring_repository.dart'; import '../../../blocs/authentication_bloc/authentication_bloc.dart'; +import '../../monitoring/wind_speed/views/wind_speed_screen.dart'; +import '../../monitoring/wind_speed/blocs/wind_speed_bloc.dart'; class MainDrawer extends StatelessWidget { const MainDrawer({super.key}); @@ -43,6 +46,23 @@ class MainDrawer extends StatelessWidget { title: const Text("Wind Speed"), onTap: () { // Navigasi ke Wind Speed + // 1. Tutup Drawer dulu supaya tidak menghalangi transisi + Navigator.pop(context); + + // 2. Pindah ke halaman WindSpeedScreen sambil membawa Bloc + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => BlocProvider( + create: (context) => WindSpeedBloc( + // AMBIL MonitoringRepository + repository: context.read(), + )..add( + WatchWindSpeedStarted()), // Langsung mulai monitoring + child: const WindSpeedScreen(), + ), + ), + ); }, ), ListTile( diff --git a/lib/screens/monitoring/wind_speed/views/wind_speed_screen.dart b/lib/screens/monitoring/wind_speed/views/wind_speed_screen.dart index 930d4d8..25785df 100644 --- a/lib/screens/monitoring/wind_speed/views/wind_speed_screen.dart +++ b/lib/screens/monitoring/wind_speed/views/wind_speed_screen.dart @@ -1,10 +1,83 @@ import 'package:flutter/material.dart'; +import 'package:fl_chart/fl_chart.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import '../blocs/wind_speed_bloc.dart'; class WindSpeedScreen extends StatelessWidget { const WindSpeedScreen({super.key}); @override Widget build(BuildContext context) { - return Scaffold(); + // Pastikan MonitoringRepository sudah diprovide di atas screen ini + return Scaffold( + appBar: AppBar(title: const Text("Wind Speed Monitoring")), + body: BlocBuilder( + builder: (context, state) { + if (state.isLoading) { + return const Center(child: CircularProgressIndicator()); + } + + return Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + children: [ + // Card Informasi Kecepatan Saat Ini + _buildCurrentSpeedCard(state.currentSpeed), + const SizedBox(height: 30), + + // Area Grafik + const Text("Grafik Kecepatan Angin", + style: + TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), + const SizedBox(height: 20), + + SizedBox( + height: 300, + child: LineChart( + _mainData(state.dailySpeeds), + ), + ), + ], + ), + ); + }, + ), + ); + } + + Widget _buildCurrentSpeedCard(double speed) { + return Card( + elevation: 4, + child: ListTile( + leading: const Icon(Icons.wind_power, color: Colors.blue, size: 40), + title: const Text("Kecepatan Saat Ini"), + trailing: Text("${speed.toStringAsFixed(2)} m/s", + style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold)), + ), + ); + } + + LineChartData _mainData(List speeds) { + return LineChartData( + gridData: const FlGridData(show: true), + titlesData: const FlTitlesData(show: true), // Bisa dikustom nanti + borderData: FlBorderData(show: true), + lineBarsData: [ + LineChartBarData( + // Mengubah List menjadi titik koordinat grafik (x, y) + spots: speeds.asMap().entries.map((e) { + return FlSpot(e.key.toDouble(), e.value); + }).toList(), + isCurved: true, // Biar garisnya melengkung halus + color: Colors.blue, + barWidth: 3, + dotData: const FlDotData(show: false), // Sembunyikan titik per data + belowBarData: BarAreaData( + show: true, + color: Colors.blue.withOpacity(0.2), // Efek bayangan di bawah garis + ), + ), + ], + ); } }