This commit is contained in:
kleponijo 2026-04-15 00:18:44 +07:00
parent 7f5c50fa24
commit 410c51722b
3 changed files with 148 additions and 43 deletions

View File

@ -0,0 +1 @@
/// === Tombol Filter Jam/Hari/Minggu === ///

View File

@ -0,0 +1,58 @@
/// === File ini khusus untuk urusan Grafik === ///
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
class WindSpeedChartWidget extends StatelessWidget {
final List<double> dailySpeeds;
const WindSpeedChartWidget({super.key, required this.dailySpeeds});
@override
Widget build(BuildContext context) {
return Container(
height: 250,
padding: const EdgeInsets.fromLTRB(10, 20, 20, 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(25),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 5),
)
],
),
child: LineChart(
LineChartData(
gridData: const FlGridData(show: false),
titlesData: const FlTitlesData(show: false),
borderData: FlBorderData(show: false),
lineBarsData: [
LineChartBarData(
spots: dailySpeeds.asMap().entries.map((e) {
return FlSpot(e.key.toDouble(), e.value);
}).toList(),
isCurved: true,
color: Colors.blue.shade700,
barWidth: 4,
isStrokeCapRound: true,
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(
show: true,
gradient: LinearGradient(
colors: [
Colors.blue.withOpacity(0.3),
Colors.blue.withOpacity(0.0)
],
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
),
),
),
],
),
),
);
}
}

View File

@ -2,41 +2,51 @@ import 'package:flutter/material.dart';
import 'package:fl_chart/fl_chart.dart'; import 'package:fl_chart/fl_chart.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import '../blocs/wind_speed_bloc.dart'; import '../blocs/wind_speed_bloc.dart';
import './widgets/wind_speed_chart_widget.dart';
class WindSpeedScreen extends StatelessWidget { class WindSpeedScreen extends StatelessWidget {
const WindSpeedScreen({super.key}); const WindSpeedScreen({super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Pastikan MonitoringRepository sudah diprovide di atas screen ini
return Scaffold( return Scaffold(
appBar: AppBar(title: const Text("Wind Speed Monitoring")), backgroundColor: Colors.grey.shade100,
appBar: AppBar(
title: const Text(
"Kecepatan Angin",
style: TextStyle(fontWeight: FontWeight.bold),
),
centerTitle: true,
elevation: 0,
backgroundColor: Colors.transparent,
foregroundColor: Colors.black,
),
/// === Body area, lokasi dan tata letak Widgets === ///
body: BlocBuilder<WindSpeedBloc, WindSpeedState>( body: BlocBuilder<WindSpeedBloc, WindSpeedState>(
builder: (context, state) { builder: (context, state) {
if (state.isLoading) { if (state.isLoading) {
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
} }
return Padding( return SingleChildScrollView(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(20.0),
child: Column( child: Column(
children: [ children: [
// Card Informasi Kecepatan Saat Ini /// ==== 1. Tampilan Angka Utama kecepatan angin (Hero Widget look) ==== ///
_buildCurrentSpeedCard(state.currentSpeed), _buildMainSpeedDisplay(state.currentSpeed),
const SizedBox(height: 30), const SizedBox(height: 30),
// Area Grafik const Text("Tren Real-time",
const Text("Grafik Kecepatan Angin",
style: style:
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 20), const SizedBox(height: 15),
WindSpeedChartWidget(dailySpeeds: state.dailySpeeds),
SizedBox( const SizedBox(height: 30),
height: 300,
child: LineChart( // 3. Info Tambahan (Status/Periode)
_mainData(state.dailySpeeds), _buildDetailRow(state.selectedPeriod),
),
),
], ],
), ),
); );
@ -45,39 +55,75 @@ class WindSpeedScreen extends StatelessWidget {
); );
} }
Widget _buildCurrentSpeedCard(double speed) { Widget _buildMainSpeedDisplay(double speed) {
return Card( return Container(
elevation: 4, width: double.infinity,
child: ListTile( padding: const EdgeInsets.symmetric(vertical: 40),
leading: const Icon(Icons.wind_power, color: Colors.blue, size: 40), decoration: BoxDecoration(
title: const Text("Kecepatan Saat Ini"), gradient: LinearGradient(
trailing: Text("${speed.toStringAsFixed(2)} m/s", colors: [Colors.blue.shade400, Colors.blue.shade800],
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold)), begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(30),
boxShadow: [
BoxShadow(
color: Colors.blue.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 10),
)
],
),
child: Column(
children: [
const Icon(Icons.air, color: Colors.white, size: 50),
const SizedBox(
height: 10,
),
Text(
"${speed.toStringAsFixed(1)}",
style: const TextStyle(
fontSize: 80, fontWeight: FontWeight.bold, color: Colors.white),
),
const Text("m/s",
style: TextStyle(fontSize: 20, color: Colors.white70))
],
), ),
); );
} }
LineChartData _mainData(List<double> speeds) { Widget _buildDetailRow(String period) {
return LineChartData( return Row(
gridData: const FlGridData(show: true), mainAxisAlignment: MainAxisAlignment.spaceBetween,
titlesData: const FlTitlesData(show: true), // Bisa dikustom nanti children: [
borderData: FlBorderData(show: true), _miniInfoCard("Status", "Normal", Icons.check_circle, Colors.green),
lineBarsData: [ _miniInfoCard("Periode", period, Icons.timer, Colors.orange),
LineChartBarData(
// Mengubah List<double> 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
),
),
], ],
); );
} }
Widget _miniInfoCard(String label, String value, IconData icon, Color color) {
return Container(
width: 160,
padding: const EdgeInsets.all(15),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
child: Row(
children: [
Icon(icon, color: color, size: 30),
const SizedBox(width: 10),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label,
style: const TextStyle(color: Colors.grey, fontSize: 12)),
Text(value, style: const TextStyle(fontWeight: FontWeight.bold)),
],
)
],
),
);
}
} }