forked from fossasia/pslab-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgauge_widget.dart
More file actions
121 lines (117 loc) · 3.63 KB
/
Copy pathgauge_widget.dart
File metadata and controls
121 lines (117 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import 'package:flutter/material.dart';
import 'package:gx_gauge/gx_gauge.dart';
import 'package:pslab/theme/colors.dart';
class InstrumentGauge extends StatelessWidget {
final double currentValue;
final double minValue;
final double maxValue;
final int interval;
final String unit;
final double size;
final int decimalPlaces;
const InstrumentGauge({
super.key,
required this.currentValue,
required this.maxValue,
required this.unit,
required this.size,
this.minValue = 0.0,
this.interval = 20,
this.decimalPlaces = 1,
});
@override
Widget build(BuildContext context) {
double clampedValue = currentValue.clamp(minValue, maxValue);
return Stack(
alignment: Alignment.center,
children: [
GxRadialGauge(
value: GxGaugeValue(
value: clampedValue.toDouble(),
min: minValue.toDouble(),
max: maxValue.toDouble()),
diameter: size.toDouble(),
startAngleInDegree: 140.0,
sweepAngleInDegree: 260.0,
showValueAtCenter: false,
showMajorTicks: true,
showLabels: true,
interval: interval.toDouble(),
labelTickStyle: const GxRadialTickLabelStyle(
padding: 22,
position: GxRadialElementPosition.outside,
style: TextStyle(
fontSize: 8,
color: Colors.black87,
fontWeight: FontWeight.w500,
),
),
majorTickStyle: GxRadialTickStyle(
color: Colors.blueGrey.shade300,
thickness: 2,
length: 12,
position: GxRadialElementPosition.outside,
alignment: GxRadialElementAlignment.start,
),
style: const GxRadialGaugeStyle(
color: Color(0xFFEEEEEE),
thickness: 15,
gradient: LinearGradient(
colors: [
gaugeGradientStart,
gaugeGradientCenter,
gaugeGradientEnd
],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
),
showNeedle: true,
needle: const GxRadialNeedle(
color: Color(0xFF424242),
shape: GxRadialNeedleShape.taperedLine,
thickness: 8,
alignment: GxRadialElementAlignment.end,
cap: GxNeedleCap(
radius: 8,
innerColor: Colors.black87,
paintingStyle: PaintingStyle.fill,
),
),
),
Positioned(
bottom: size * 0.12,
child: Column(
children: [
Text(
clampedValue.toStringAsFixed(decimalPlaces),
style: TextStyle(
fontSize: (size * 0.08).clamp(12.0, 24.0),
fontWeight: FontWeight.w800,
color: Colors.black87,
),
),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 2),
decoration: BoxDecoration(
color: Colors.grey.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(10),
),
child: Text(
unit.toUpperCase(),
style: TextStyle(
fontSize: (size * 0.045).clamp(8.0, 12.0),
fontWeight: FontWeight.w800,
color: Colors.blueGrey,
letterSpacing: 1.5,
),
),
),
],
),
),
],
);
}
}