mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Extracted lines data into a helper method for ease of readability.
This commit is contained in:
@ -16,6 +16,12 @@ class RangeOfAqiChart extends StatelessWidget {
|
||||
required this.maxValues,
|
||||
});
|
||||
|
||||
List<(List<double> values, Color color, Color? dotColor)> _lines() => [
|
||||
(maxValues, const Color(0xFF962DFF), const Color(0xFF5F00BD)),
|
||||
(avgValues, Colors.white, null),
|
||||
(minValues, const Color(0xFF93AAFD), const Color(0xFF023DFE)),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
@ -41,23 +47,10 @@ class RangeOfAqiChart extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
],
|
||||
lineBarsData: [
|
||||
_buildLine(
|
||||
values: maxValues,
|
||||
color: const Color(0xFF962DFF),
|
||||
dotColor: const Color(0xFF5F00BD),
|
||||
),
|
||||
_buildLine(
|
||||
values: avgValues,
|
||||
color: Colors.white,
|
||||
dotColor: null,
|
||||
),
|
||||
_buildLine(
|
||||
values: minValues,
|
||||
color: const Color(0xFF93AAFD),
|
||||
dotColor: const Color(0xFF023DFE),
|
||||
),
|
||||
],
|
||||
lineBarsData: _lines().map((e) {
|
||||
final (values, color, dotColor) = e;
|
||||
return _buildLine(values: values, color: color, dotColor: dotColor);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -67,7 +60,7 @@ class RangeOfAqiChart extends StatelessWidget {
|
||||
FlDotData _buildDotData(Color color) {
|
||||
return FlDotData(
|
||||
show: true,
|
||||
getDotPainter: (spot, percent, bar, index) => FlDotCirclePainter(
|
||||
getDotPainter: (_, __, ___, ____) => FlDotCirclePainter(
|
||||
radius: 2,
|
||||
color: ColorsManager.whiteColors,
|
||||
strokeWidth: 2,
|
||||
@ -81,17 +74,14 @@ class RangeOfAqiChart extends StatelessWidget {
|
||||
required Color color,
|
||||
Color? dotColor,
|
||||
}) {
|
||||
const invisibleDot = FlDotData(show: false);
|
||||
return LineChartBarData(
|
||||
spots: List.generate(
|
||||
values.length,
|
||||
(i) => FlSpot(i.toDouble(), values[i]),
|
||||
),
|
||||
spots: List.generate(values.length, (i) => FlSpot(i.toDouble(), values[i])),
|
||||
isCurved: true,
|
||||
color: color,
|
||||
barWidth: 4,
|
||||
isStrokeCapRound: true,
|
||||
dotData:
|
||||
dotColor != null ? _buildDotData(dotColor) : const FlDotData(show: false),
|
||||
dotData: dotColor != null ? _buildDotData(dotColor) : invisibleDot,
|
||||
belowBarData: BarAreaData(show: false),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user