looooo
This commit is contained in:
parent
d19c5fcaf8
commit
47fc79455b
|
|
@ -104,7 +104,7 @@ class SensorCard extends StatelessWidget {
|
|||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
color: Colors.black.withValues(alpha: 0.05),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -50,15 +50,8 @@ class WindSpeedBloc extends Bloc<WindSpeedEvent, WindSpeedState> {
|
|||
(json) => MyWindSpeed.fromJson(json),
|
||||
);
|
||||
|
||||
/// 2. Mapping default (harian)
|
||||
final raw = TimeSeriesMapper.toDaily(
|
||||
data: history,
|
||||
getTime: (e) => e.timestamp,
|
||||
getValue: (e) => e.speed,
|
||||
);
|
||||
final dailyGraph = TimeSeriesMapper.smooth(raw);
|
||||
|
||||
final daily = TimeSeriesMapper.smooth(
|
||||
// ✅ Ini saja yang benar
|
||||
final dailyGraph = TimeSeriesMapper.smooth(
|
||||
TimeSeriesMapper.toDaily(
|
||||
data: history,
|
||||
getTime: (e) => e.timestamp,
|
||||
|
|
@ -93,6 +86,9 @@ class WindSpeedBloc extends Bloc<WindSpeedEvent, WindSpeedState> {
|
|||
weeklySpeeds: weekly,
|
||||
monthlySpeeds: monthly,
|
||||
isLoading: false,
|
||||
alertLevel: history.isNotEmpty // ← tambah ini
|
||||
? _getAlertLevel(history.last.speed)
|
||||
: "Normal",
|
||||
));
|
||||
|
||||
/// 3. Start realtime stream (manual subscription)
|
||||
|
|
@ -138,6 +134,7 @@ class WindSpeedBloc extends Bloc<WindSpeedEvent, WindSpeedState> {
|
|||
emit(state.copyWith(
|
||||
currentSpeed: newValue,
|
||||
dailySpeeds: updated,
|
||||
alertLevel: _getAlertLevel(newValue),
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -194,6 +191,12 @@ class WindSpeedBloc extends Bloc<WindSpeedEvent, WindSpeedState> {
|
|||
return super.close();
|
||||
}
|
||||
|
||||
String _getAlertLevel(double speed) {
|
||||
if (speed >= _kWindDanger) return "Bahaya";
|
||||
if (speed >= _kWindWarning) return "Waspada";
|
||||
return "Normal";
|
||||
}
|
||||
|
||||
// =========================
|
||||
// HELPER: kirim alert ke NotificationBloc
|
||||
// =========================
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ class WindSpeedState extends Equatable {
|
|||
final List<double> monthlySpeeds;
|
||||
final bool isLoading;
|
||||
final List<MyWindSpeed> history;
|
||||
final String alertLevel; // "Normal" | "Waspada" | "Bahaya"
|
||||
|
||||
const WindSpeedState({
|
||||
this.currentSpeed = 0.0,
|
||||
|
|
@ -17,6 +18,7 @@ class WindSpeedState extends Equatable {
|
|||
this.history = const [],
|
||||
this.monthlySpeeds = const [],
|
||||
this.weeklySpeeds = const [],
|
||||
this.alertLevel = "Normal",
|
||||
});
|
||||
|
||||
WindSpeedState copyWith({
|
||||
|
|
@ -27,6 +29,7 @@ class WindSpeedState extends Equatable {
|
|||
List<double>? monthlySpeeds,
|
||||
bool? isLoading,
|
||||
List<MyWindSpeed>? history,
|
||||
String? alertLevel,
|
||||
}) {
|
||||
return WindSpeedState(
|
||||
currentSpeed: currentSpeed ?? this.currentSpeed,
|
||||
|
|
@ -36,10 +39,18 @@ class WindSpeedState extends Equatable {
|
|||
monthlySpeeds: monthlySpeeds ?? this.monthlySpeeds,
|
||||
isLoading: isLoading ?? this.isLoading,
|
||||
history: history ?? this.history,
|
||||
alertLevel: alertLevel ?? this.alertLevel,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object> get props =>
|
||||
[currentSpeed, selectedPeriod, dailySpeeds, isLoading, history];
|
||||
List<Object> get props => [
|
||||
currentSpeed,
|
||||
selectedPeriod,
|
||||
dailySpeeds,
|
||||
weeklySpeeds,
|
||||
monthlySpeeds,
|
||||
isLoading,
|
||||
history
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ class WindSpeedScreen extends StatelessWidget {
|
|||
const SizedBox(height: 30),
|
||||
|
||||
// 3. Info Tambahan (Status/Periode)
|
||||
_buildDetailRow(state.selectedPeriod),
|
||||
_buildDetailRow(state.selectedPeriod, state.alertLevel),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// ← Tombol Export PDF
|
||||
|
|
@ -143,11 +143,16 @@ class WindSpeedScreen extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _buildDetailRow(String period) {
|
||||
Widget _buildDetailRow(String period, String alertLevel) {
|
||||
final (icon, color) = switch (alertLevel) {
|
||||
"Bahaya" => (Icons.warning_rounded, Colors.red),
|
||||
"Waspada" => (Icons.info_outline, Colors.orange),
|
||||
_ => (Icons.check_circle, Colors.green),
|
||||
};
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_miniInfoCard("Status", "Normal", Icons.check_circle, Colors.green),
|
||||
_miniInfoCard("Status", alertLevel, icon, color),
|
||||
_miniInfoCard("Periode", period, Icons.timer, Colors.orange),
|
||||
],
|
||||
);
|
||||
|
|
|
|||
Loading…
Reference in New Issue