mantap
This commit is contained in:
parent
adaeff826f
commit
7f5c50fa24
17
lib/app.dart
17
lib/app.dart
|
|
@ -12,9 +12,18 @@ class MyApp extends StatelessWidget {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return RepositoryProvider<AuthenticationBloc>(
|
||||
create: (context) => AuthenticationBloc(userRepository: userRepository),
|
||||
child: const MyAppView(),
|
||||
);
|
||||
return MultiRepositoryProvider(
|
||||
providers: [
|
||||
// 1. Daftarkan UserRepository
|
||||
RepositoryProvider<UserRepository>.value(value: userRepository),
|
||||
RepositoryProvider<MonitoringRepository>.value(
|
||||
value: monitoringRepository),
|
||||
],
|
||||
child: BlocProvider<AuthenticationBloc>(
|
||||
create: (context) => AuthenticationBloc(
|
||||
userRepository: userRepository,
|
||||
),
|
||||
child: const MyAppView(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<WindSpeedBloc>(
|
||||
create: (context) => WindSpeedBloc(
|
||||
// AMBIL MonitoringRepository
|
||||
repository: context.read<MonitoringRepository>(),
|
||||
)..add(
|
||||
WatchWindSpeedStarted()), // Langsung mulai monitoring
|
||||
child: const WindSpeedScreen(),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
|
|
|
|||
|
|
@ -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<WindSpeedBloc, WindSpeedState>(
|
||||
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<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
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue