mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 03:44:56 +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,
|
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
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Stack(
|
return Stack(
|
||||||
@ -41,23 +47,10 @@ class RangeOfAqiChart extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
lineBarsData: [
|
lineBarsData: _lines().map((e) {
|
||||||
_buildLine(
|
final (values, color, dotColor) = e;
|
||||||
values: maxValues,
|
return _buildLine(values: values, color: color, dotColor: dotColor);
|
||||||
color: const Color(0xFF962DFF),
|
}).toList(),
|
||||||
dotColor: const Color(0xFF5F00BD),
|
|
||||||
),
|
|
||||||
_buildLine(
|
|
||||||
values: avgValues,
|
|
||||||
color: Colors.white,
|
|
||||||
dotColor: null,
|
|
||||||
),
|
|
||||||
_buildLine(
|
|
||||||
values: minValues,
|
|
||||||
color: const Color(0xFF93AAFD),
|
|
||||||
dotColor: const Color(0xFF023DFE),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -67,7 +60,7 @@ class RangeOfAqiChart extends StatelessWidget {
|
|||||||
FlDotData _buildDotData(Color color) {
|
FlDotData _buildDotData(Color color) {
|
||||||
return FlDotData(
|
return FlDotData(
|
||||||
show: true,
|
show: true,
|
||||||
getDotPainter: (spot, percent, bar, index) => FlDotCirclePainter(
|
getDotPainter: (_, __, ___, ____) => FlDotCirclePainter(
|
||||||
radius: 2,
|
radius: 2,
|
||||||
color: ColorsManager.whiteColors,
|
color: ColorsManager.whiteColors,
|
||||||
strokeWidth: 2,
|
strokeWidth: 2,
|
||||||
@ -81,17 +74,14 @@ class RangeOfAqiChart extends StatelessWidget {
|
|||||||
required Color color,
|
required Color color,
|
||||||
Color? dotColor,
|
Color? dotColor,
|
||||||
}) {
|
}) {
|
||||||
|
const invisibleDot = FlDotData(show: false);
|
||||||
return LineChartBarData(
|
return LineChartBarData(
|
||||||
spots: List.generate(
|
spots: List.generate(values.length, (i) => FlSpot(i.toDouble(), values[i])),
|
||||||
values.length,
|
|
||||||
(i) => FlSpot(i.toDouble(), values[i]),
|
|
||||||
),
|
|
||||||
isCurved: true,
|
isCurved: true,
|
||||||
color: color,
|
color: color,
|
||||||
barWidth: 4,
|
barWidth: 4,
|
||||||
isStrokeCapRound: true,
|
isStrokeCapRound: true,
|
||||||
dotData:
|
dotData: dotColor != null ? _buildDotData(dotColor) : invisibleDot,
|
||||||
dotColor != null ? _buildDotData(dotColor) : const FlDotData(show: false),
|
|
||||||
belowBarData: BarAreaData(show: false),
|
belowBarData: BarAreaData(show: false),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user