forked from fossasia/pslab-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccelerometer_card.dart
More file actions
184 lines (178 loc) · 6.64 KB
/
Copy pathaccelerometer_card.dart
File metadata and controls
184 lines (178 loc) · 6.64 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import 'package:flutter/material.dart';
import 'package:pslab/constants.dart';
import 'package:pslab/providers/accelerometer_state_provider.dart';
import 'package:fl_chart/fl_chart.dart';
import 'package:provider/provider.dart';
class AccelerometerCard extends StatefulWidget {
final String axis;
final Color color;
const AccelerometerCard({required this.axis, required this.color, super.key});
@override
State<StatefulWidget> createState() => _AccelerometerCardState();
}
class _AccelerometerCardState extends State<AccelerometerCard> {
Widget sideTitleWidgets(double value, TitleMeta meta) {
const style = TextStyle(
color: Colors.white,
fontSize: 9,
);
return SideTitleWidget(
meta: meta,
child: Text(
maxLines: 1,
meta.formattedValue,
style: style,
),
);
}
@override
Widget build(BuildContext context) {
AccelerometerStateProvider provider =
Provider.of<AccelerometerStateProvider>(context);
List<FlSpot> spots = provider.getAxisData(widget.axis);
double currVal = provider.getCurrent(widget.axis);
double minVal = provider.getMin(widget.axis);
double maxVal = provider.getMax(widget.axis);
int dataLength = provider.getDataLength(widget.axis);
String axisImage = 'assets/images/phone_${widget.axis}_axis.png';
return Card(
margin: const EdgeInsets.symmetric(vertical: 8, horizontal: 8),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(5),
),
elevation: 2,
child: Container(
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(5)),
child: Row(
children: [
Expanded(
flex: 30,
child: Column(children: [
Container(
margin: const EdgeInsets.all(15),
child: Image.asset(
axisImage,
width: 50,
height: 50,
),
),
Container(
margin: const EdgeInsets.only(top: 8, bottom: 12),
child: Text(
"${currVal.toStringAsFixed(1)} $accelerationAxisLabel",
style: const TextStyle(color: Colors.black, fontSize: 14),
),
),
Container(
alignment: Alignment.topLeft,
margin: const EdgeInsets.only(left: 8, top: 4),
child: Text(
"$minValue ${minVal.toStringAsFixed(1)} $accelerationAxisLabel",
style: const TextStyle(color: Colors.black, fontSize: 10),
),
),
Container(
alignment: Alignment.topLeft,
margin: const EdgeInsets.only(left: 8, top: 2),
child: Text(
"$maxValue ${maxVal.toStringAsFixed(1)} $accelerationAxisLabel",
style: const TextStyle(color: Colors.black, fontSize: 10),
),
),
]),
),
Expanded(
flex: 70,
child: Container(
padding: const EdgeInsets.only(bottom: 20, top: 10, right: 25),
color: Colors.black,
child: LineChart(
LineChartData(
backgroundColor: Colors.black,
titlesData: FlTitlesData(
show: true,
topTitles: AxisTitles(
axisNameWidget: Padding(
padding: const EdgeInsets.only(left: 25),
child: Text(
timeAxisLabel,
style: const TextStyle(
fontSize: 10,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
axisNameSize: 20,
),
bottomTitles: const AxisTitles(
sideTitles: SideTitles(showTitles: false)),
leftTitles: AxisTitles(
axisNameWidget: Text(
accelerationAxisLabel,
style: const TextStyle(
fontSize: 10,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
sideTitles: SideTitles(
reservedSize: 30,
showTitles: true,
getTitlesWidget: sideTitleWidgets,
interval: 10,
),
),
rightTitles: const AxisTitles(
sideTitles: SideTitles(showTitles: false)),
),
gridData: const FlGridData(
show: true,
drawHorizontalLine: true,
drawVerticalLine: true,
horizontalInterval: 10,
),
borderData: FlBorderData(
show: true,
border: const Border(
bottom: BorderSide(
color: Colors.white38,
),
left: BorderSide(
color: Colors.white38,
),
top: BorderSide(
color: Colors.white38,
),
right: BorderSide(
color: Colors.white38,
),
),
),
minY: -20,
maxY: 20,
maxX: dataLength > 50 ? 50 : dataLength.toDouble(),
minX: 0,
clipData: const FlClipData.all(),
lineBarsData: [
LineChartBarData(
spots: spots,
isCurved: true,
color: widget.color,
barWidth: 2,
isStrokeCapRound: true,
dotData: const FlDotData(show: false),
belowBarData: BarAreaData(show: false),
),
],
),
),
),
),
],
),
),
);
}
}