mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Refactored AqiGauge
to consolidate status text and color logic into a single method, improving code readability and maintainability.
This commit is contained in:
@ -7,35 +7,15 @@ class AqiGauge extends StatelessWidget {
|
||||
const AqiGauge({super.key, required this.aqi});
|
||||
|
||||
final double aqi;
|
||||
|
||||
static const _minRange = 0.0;
|
||||
static const _goodRange = 50.0;
|
||||
static const _moderateRange = 100.0;
|
||||
static const _maxRange = 150.0;
|
||||
|
||||
String _getStatusText(double value) {
|
||||
return switch (value) {
|
||||
<= _goodRange => 'Good',
|
||||
<= _moderateRange => 'Moderate',
|
||||
_ => 'Poor',
|
||||
};
|
||||
}
|
||||
|
||||
Color _darkenColor(Color color) => Color.lerp(
|
||||
color,
|
||||
Colors.black.withValues(alpha: 0.8),
|
||||
0.4,
|
||||
)!;
|
||||
|
||||
Color _getStatusColor(double value) => switch (value) {
|
||||
<= _goodRange => ColorsManager.goodGreen,
|
||||
<= _moderateRange => ColorsManager.moderateYellow,
|
||||
_ => ColorsManager.poorOrange,
|
||||
};
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final status = _getStatusText(aqi);
|
||||
final statusColor = _getStatusColor(aqi);
|
||||
final (status, statusColor) = _getStatusData(aqi);
|
||||
return AnimatedRadialGauge(
|
||||
value: aqi,
|
||||
debug: false,
|
||||
@ -119,4 +99,17 @@ class AqiGauge extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
(String status, Color color) _getStatusData(double value) {
|
||||
return switch (value) {
|
||||
<= _goodRange => ('Good', ColorsManager.goodGreen),
|
||||
<= _moderateRange => ('Moderate', ColorsManager.moderateYellow),
|
||||
_ => ('Poor', ColorsManager.poorOrange),
|
||||
};
|
||||
}
|
||||
|
||||
Color _darkenColor(Color color) {
|
||||
final black = Colors.black.withValues(alpha: 0.8);
|
||||
return Color.lerp(color, black, 0.4)!;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user