mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Implemented new gauge design.
This commit is contained in:
@ -1,18 +1,25 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_gauge.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_gauge.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_humidity_and_temperature.dart';
|
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/aqi_humidity_and_temperature.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
|
||||||
|
|
||||||
class AirQualityEndSideGaugeAndInfo extends StatelessWidget {
|
class AirQualityEndSideGaugeAndInfo extends StatelessWidget {
|
||||||
const AirQualityEndSideGaugeAndInfo({
|
const AirQualityEndSideGaugeAndInfo({
|
||||||
super.key,
|
super.key,
|
||||||
required this.temperature,
|
required this.temperature,
|
||||||
required this.humidity,
|
required this.humidity,
|
||||||
|
required this.aqiLevel,
|
||||||
});
|
});
|
||||||
|
|
||||||
final int temperature;
|
final int temperature;
|
||||||
final int humidity;
|
final int humidity;
|
||||||
|
final String aqiLevel;
|
||||||
|
|
||||||
|
double get aqi => switch (aqiLevel) {
|
||||||
|
'level_1' => 25.0,
|
||||||
|
'level_2' => 75.0,
|
||||||
|
'level_3' => 125.0,
|
||||||
|
_ => 0.0,
|
||||||
|
};
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -20,12 +27,12 @@ class AirQualityEndSideGaugeAndInfo extends StatelessWidget {
|
|||||||
flex: 2,
|
flex: 2,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
const Expanded(
|
Expanded(
|
||||||
flex: 2,
|
flex: 2,
|
||||||
child: Row(
|
child: Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [Expanded(child: AqiGauge(aqi: 200))],
|
children: [Expanded(child: AqiGauge(aqi: aqi))],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
@ -33,34 +40,10 @@ class AirQualityEndSideGaugeAndInfo extends StatelessWidget {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsetsDirectional.only(end: 20),
|
padding: const EdgeInsetsDirectional.only(end: 20),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
// crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
const Spacer(),
|
|
||||||
FittedBox(
|
|
||||||
fit: BoxFit.contain,
|
|
||||||
alignment: AlignmentDirectional.centerStart,
|
|
||||||
child: Text(
|
|
||||||
'Air Quality:',
|
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
|
||||||
color: ColorsManager.textPrimaryColor,
|
|
||||||
fontWeight: FontWeight.w400,
|
|
||||||
fontSize: 14,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
FittedBox(
|
|
||||||
fit: BoxFit.contain,
|
|
||||||
alignment: AlignmentDirectional.centerStart,
|
|
||||||
child: Text(
|
|
||||||
'Perfect',
|
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
|
||||||
color: ColorsManager.green,
|
|
||||||
fontWeight: FontWeight.w400,
|
|
||||||
fontSize: 30,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Spacer(),
|
|
||||||
AqiHumidityAndTemperature(
|
AqiHumidityAndTemperature(
|
||||||
temperature: temperature,
|
temperature: temperature,
|
||||||
humidity: humidity,
|
humidity: humidity,
|
||||||
|
@ -41,7 +41,7 @@ class AqiDeviceInfo extends StatelessWidget {
|
|||||||
final tempValue = _getValueForStatus(
|
final tempValue = _getValueForStatus(
|
||||||
status,
|
status,
|
||||||
'temp_current',
|
'temp_current',
|
||||||
formatter: (value) => value.toStringAsFixed(0),
|
formatter: (value) => (value / 10).toStringAsFixed(0),
|
||||||
);
|
);
|
||||||
final pm25Value = _getValueForStatus(
|
final pm25Value = _getValueForStatus(
|
||||||
status,
|
status,
|
||||||
@ -78,6 +78,13 @@ class AqiDeviceInfo extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
const AirQualityEndSideLiveIndicator(),
|
const AirQualityEndSideLiveIndicator(),
|
||||||
AirQualityEndSideGaugeAndInfo(
|
AirQualityEndSideGaugeAndInfo(
|
||||||
|
aqiLevel: status
|
||||||
|
.firstWhere(
|
||||||
|
(e) => e.code == 'air_quality_index',
|
||||||
|
orElse: () => Status(code: 'air_quality_index', value: ''),
|
||||||
|
)
|
||||||
|
.value
|
||||||
|
.toString(),
|
||||||
temperature: int.parse(tempValue),
|
temperature: int.parse(tempValue),
|
||||||
humidity: int.parse(humidityValue),
|
humidity: int.parse(humidityValue),
|
||||||
),
|
),
|
||||||
|
@ -10,41 +10,32 @@ class AqiGauge extends StatelessWidget {
|
|||||||
static const _minRange = 0.0;
|
static const _minRange = 0.0;
|
||||||
static const _goodRange = 50.0;
|
static const _goodRange = 50.0;
|
||||||
static const _moderateRange = 100.0;
|
static const _moderateRange = 100.0;
|
||||||
static const _poorRange = 150.0;
|
static const _maxRange = 150.0;
|
||||||
static const _unhealthyToSevereRange = 225.0;
|
|
||||||
static const _maxRange = 300.0;
|
|
||||||
|
|
||||||
Color _getPointerColor(double value) {
|
String _getStatusText(double value) {
|
||||||
if (value <= _goodRange) {
|
return switch (value) {
|
||||||
return ColorsManager.goodGreen;
|
<= _goodRange => 'Good',
|
||||||
} else if (value <= _moderateRange) {
|
<= _moderateRange => 'Moderate',
|
||||||
return ColorsManager.moderateYellow;
|
_ => 'Poor',
|
||||||
} else if (value <= _poorRange) {
|
};
|
||||||
return ColorsManager.poorOrange;
|
|
||||||
} else {
|
|
||||||
const unhealthyStart = _poorRange + 1;
|
|
||||||
if (value <= _unhealthyToSevereRange) {
|
|
||||||
final t =
|
|
||||||
(value - unhealthyStart) / (_unhealthyToSevereRange - unhealthyStart);
|
|
||||||
return Color.lerp(
|
|
||||||
ColorsManager.unhealthyRed,
|
|
||||||
ColorsManager.severePink,
|
|
||||||
t,
|
|
||||||
)!;
|
|
||||||
} else {
|
|
||||||
const severeStart = _unhealthyToSevereRange + 1;
|
|
||||||
final t = (value - severeStart) / (_maxRange - severeStart);
|
|
||||||
return Color.lerp(
|
|
||||||
ColorsManager.severePink,
|
|
||||||
ColorsManager.hazardousPurple,
|
|
||||||
t,
|
|
||||||
)!;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final status = _getStatusText(aqi);
|
||||||
|
final statusColor = _getStatusColor(aqi);
|
||||||
return AnimatedRadialGauge(
|
return AnimatedRadialGauge(
|
||||||
value: aqi,
|
value: aqi,
|
||||||
debug: false,
|
debug: false,
|
||||||
@ -60,24 +51,23 @@ class AqiGauge extends StatelessWidget {
|
|||||||
alignment: AlignmentDirectional.bottomCenter,
|
alignment: AlignmentDirectional.bottomCenter,
|
||||||
child: Text.rich(
|
child: Text.rich(
|
||||||
TextSpan(
|
TextSpan(
|
||||||
text: value.toStringAsFixed(0),
|
text: 'Air Quality\n',
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
color: ColorsManager.textPrimaryColor,
|
color: ColorsManager.textPrimaryColor,
|
||||||
fontWeight: FontWeight.w700,
|
fontWeight: FontWeight.w400,
|
||||||
fontSize: 30,
|
fontSize: 12,
|
||||||
),
|
),
|
||||||
children: [
|
children: [
|
||||||
const TextSpan(
|
TextSpan(
|
||||||
text: 'AQI',
|
text: status,
|
||||||
style: TextStyle(
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
color: ColorsManager.textPrimaryColor,
|
color: _darkenColor(statusColor),
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
fontSize: 12,
|
fontSize: 30,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -98,7 +88,7 @@ class AqiGauge extends StatelessWidget {
|
|||||||
color: ColorsManager.whiteColors,
|
color: ColorsManager.whiteColors,
|
||||||
border: GaugePointerBorder(
|
border: GaugePointerBorder(
|
||||||
width: 6,
|
width: 6,
|
||||||
color: _getPointerColor(aqi),
|
color: statusColor,
|
||||||
),
|
),
|
||||||
shadow: const BoxShadow(
|
shadow: const BoxShadow(
|
||||||
color: ColorsManager.blackColor,
|
color: ColorsManager.blackColor,
|
||||||
@ -106,41 +96,24 @@ class AqiGauge extends StatelessWidget {
|
|||||||
offset: Offset(0, 2),
|
offset: Offset(0, 2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
transformer: const GaugeAxisTransformer.colorFadeIn(
|
segments: const [
|
||||||
background: ColorsManager.transparentColor,
|
GaugeSegment(
|
||||||
interval: Interval(0, 0),
|
|
||||||
),
|
|
||||||
segments: [
|
|
||||||
const GaugeSegment(
|
|
||||||
from: _minRange,
|
from: _minRange,
|
||||||
to: _goodRange,
|
to: _goodRange,
|
||||||
cornerRadius: Radius.circular(16),
|
cornerRadius: Radius.circular(16),
|
||||||
color: ColorsManager.goodGreen,
|
color: ColorsManager.goodGreen,
|
||||||
),
|
),
|
||||||
const GaugeSegment(
|
GaugeSegment(
|
||||||
from: _goodRange + 1,
|
from: _goodRange + 1,
|
||||||
to: _moderateRange,
|
to: _moderateRange,
|
||||||
cornerRadius: Radius.circular(16),
|
cornerRadius: Radius.circular(16),
|
||||||
color: ColorsManager.moderateYellow,
|
color: ColorsManager.moderateYellow,
|
||||||
),
|
),
|
||||||
const GaugeSegment(
|
GaugeSegment(
|
||||||
from: _moderateRange + 1,
|
from: _moderateRange + 1,
|
||||||
to: _poorRange,
|
|
||||||
cornerRadius: Radius.circular(16),
|
|
||||||
color: ColorsManager.poorOrange,
|
|
||||||
),
|
|
||||||
const GaugeSegment(
|
|
||||||
from: _poorRange + 1,
|
|
||||||
to: _maxRange,
|
to: _maxRange,
|
||||||
cornerRadius: Radius.circular(16),
|
cornerRadius: Radius.circular(16),
|
||||||
gradient: GaugeAxisGradient(
|
color: ColorsManager.poorOrange,
|
||||||
colorStops: [0.0, 0.5, 1.0],
|
|
||||||
colors: [
|
|
||||||
ColorsManager.unhealthyRed,
|
|
||||||
ColorsManager.severePink,
|
|
||||||
ColorsManager.hazardousPurple,
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -19,7 +19,6 @@ class AqiHumidityAndTemperature extends StatelessWidget {
|
|||||||
BlendMode.srcIn,
|
BlendMode.srcIn,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return FittedBox(
|
return FittedBox(
|
||||||
@ -29,30 +28,32 @@ class AqiHumidityAndTemperature extends StatelessWidget {
|
|||||||
style: context.textTheme.bodySmall!.copyWith(
|
style: context.textTheme.bodySmall!.copyWith(
|
||||||
color: ColorsManager.textPrimaryColor,
|
color: ColorsManager.textPrimaryColor,
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
fontSize: 12,
|
fontSize: 16,
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
SvgPicture.asset(
|
_buildIconAndValue(Assets.temperatureAqiSidebar, '$temperature°C'),
|
||||||
Assets.temperatureAqiSidebar,
|
const SizedBox(height: 10),
|
||||||
height: iconSize,
|
_buildIconAndValue(Assets.humidityAqiSidebar, '$humidity%'),
|
||||||
width: iconSize,
|
|
||||||
colorFilter: colorFilter,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text('$temperature°C'),
|
|
||||||
const SizedBox(width: 10),
|
|
||||||
SvgPicture.asset(
|
|
||||||
Assets.humidityAqiSidebar,
|
|
||||||
height: iconSize,
|
|
||||||
width: iconSize,
|
|
||||||
colorFilter: colorFilter,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text('$humidity%'),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildIconAndValue(String icon, String value) {
|
||||||
|
return Row(
|
||||||
|
children: [
|
||||||
|
SvgPicture.asset(
|
||||||
|
icon,
|
||||||
|
height: iconSize,
|
||||||
|
width: iconSize,
|
||||||
|
colorFilter: colorFilter,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
Text(value),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user