oke
This commit is contained in:
parent
7f5c50fa24
commit
410c51722b
|
|
@ -0,0 +1 @@
|
|||
/// === Tombol Filter Jam/Hari/Minggu === ///
|
||||
|
|
@ -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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,41 +2,51 @@ 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';
|
||||
import './widgets/wind_speed_chart_widget.dart';
|
||||
|
||||
class WindSpeedScreen extends StatelessWidget {
|
||||
const WindSpeedScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Pastikan MonitoringRepository sudah diprovide di atas screen ini
|
||||
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>(
|
||||
builder: (context, state) {
|
||||
if (state.isLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
return SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
children: [
|
||||
// Card Informasi Kecepatan Saat Ini
|
||||
_buildCurrentSpeedCard(state.currentSpeed),
|
||||
/// ==== 1. Tampilan Angka Utama kecepatan angin (Hero Widget look) ==== ///
|
||||
_buildMainSpeedDisplay(state.currentSpeed),
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// Area Grafik
|
||||
const Text("Grafik Kecepatan Angin",
|
||||
const Text("Tren Real-time",
|
||||
style:
|
||||
TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
|
||||
const SizedBox(height: 20),
|
||||
const SizedBox(height: 15),
|
||||
WindSpeedChartWidget(dailySpeeds: state.dailySpeeds),
|
||||
|
||||
SizedBox(
|
||||
height: 300,
|
||||
child: LineChart(
|
||||
_mainData(state.dailySpeeds),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 30),
|
||||
|
||||
// 3. Info Tambahan (Status/Periode)
|
||||
_buildDetailRow(state.selectedPeriod),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
|
@ -45,39 +55,75 @@ class WindSpeedScreen extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
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)),
|
||||
Widget _buildMainSpeedDisplay(double speed) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 40),
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.blue.shade400, Colors.blue.shade800],
|
||||
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) {
|
||||
return LineChartData(
|
||||
gridData: const FlGridData(show: true),
|
||||
titlesData: const FlTitlesData(show: true), // Bisa dikustom nanti
|
||||
borderData: FlBorderData(show: true),
|
||||
lineBarsData: [
|
||||
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 _buildDetailRow(String period) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_miniInfoCard("Status", "Normal", Icons.check_circle, Colors.green),
|
||||
_miniInfoCard("Periode", period, Icons.timer, Colors.orange),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
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)),
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue