1
1
import 'package:flutter/material.dart' ;
2
2
import 'package:provider/provider.dart' ;
3
3
import 'package:pslab/view/widgets/common_scaffold_widget.dart' ;
4
-
4
+ import 'package:pslab/constants.dart' ;
5
5
import '../providers/compass_provider.dart' ;
6
6
7
7
class CompassScreen extends StatelessWidget {
@@ -24,6 +24,7 @@ class CompassScreenContent extends StatefulWidget {
24
24
}
25
25
26
26
class _CompassScreenContentState extends State <CompassScreenContent > {
27
+ static const String compassIcon = 'assets/icons/compass_icon.png' ;
27
28
@override
28
29
void initState () {
29
30
super .initState ();
@@ -41,98 +42,97 @@ class _CompassScreenContentState extends State<CompassScreenContent> {
41
42
@override
42
43
Widget build (BuildContext context) {
43
44
return Consumer <CompassProvider >(
44
- builder: (context, compassProvider, child) {
45
- return CommonScaffold (
46
- title: 'Compass' ,
47
- body: SafeArea (
48
- child: Container (
49
- padding: const EdgeInsets .all (16.0 ),
50
- child: Column (
51
- children: [
52
- Expanded (
53
- flex: 3 ,
54
- child: Center (
55
- child: Transform .rotate (
56
- angle: compassProvider.currentDegree,
57
- child: Container (
58
- width: 300 ,
59
- height: 300 ,
60
- decoration: const BoxDecoration (
61
- shape: BoxShape .circle,
62
- ),
63
- child: Image .asset (
64
- 'assets/icons/compass_icon.png' ,
65
- fit: BoxFit .contain,
66
- ),
45
+ builder: (context, compassProvider, child) {
46
+ return CommonScaffold (
47
+ title: compassTitle,
48
+ body: SafeArea (
49
+ child: Container (
50
+ padding: const EdgeInsets .all (16.0 ),
51
+ child: Column (
52
+ children: [
53
+ Expanded (
54
+ flex: 3 ,
55
+ child: Center (
56
+ child: Transform .rotate (
57
+ angle: compassProvider.currentDegree,
58
+ child: Container (
59
+ width: 300 ,
60
+ height: 300 ,
61
+ decoration: const BoxDecoration (
62
+ shape: BoxShape .circle,
63
+ ),
64
+ child: Image .asset (
65
+ compassIcon,
66
+ fit: BoxFit .contain,
67
67
),
68
68
),
69
69
),
70
70
),
71
- Container (
72
- padding : const EdgeInsets . symmetric (vertical : 16 ),
73
- child : Column (
74
- children : [
75
- Text (
76
- compassProvider
77
- . getDegreeForAxis ( compassProvider.selectedAxis)
78
- . round ( )
79
- . toStringAsFixed ( 1 ),
80
- style : const TextStyle (
81
- fontSize : 32 ,
82
- fontWeight : FontWeight .bold ,
83
- ) ,
71
+ ),
72
+ Container (
73
+ padding : const EdgeInsets . symmetric (vertical : 16 ),
74
+ child : Column (
75
+ children : [
76
+ Text (
77
+ compassProvider
78
+ . getDegreeForAxis (compassProvider.selectedAxis )
79
+ . round ()
80
+ . toStringAsFixed ( 1 ),
81
+ style : const TextStyle (
82
+ fontSize : 32 ,
83
+ fontWeight : FontWeight .bold ,
84
84
),
85
- ] ,
86
- ) ,
85
+ ) ,
86
+ ] ,
87
87
),
88
- const SizedBox (height: 24 ),
89
- Container (
90
- padding: const EdgeInsets .all (16 ),
91
- decoration: BoxDecoration (
92
- color: Colors .grey[100 ],
93
- borderRadius: BorderRadius .circular (12 ),
94
- ),
95
- child: Column (
96
- children: [
97
- Row (
98
- mainAxisAlignment: MainAxisAlignment .spaceEvenly,
99
- children: [
100
- _buildAxisColumn (
101
- 'Bx' , compassProvider.magnetometerEvent.x),
102
- _buildAxisColumn (
103
- 'By' , compassProvider.magnetometerEvent.y),
104
- _buildAxisColumn (
105
- 'Bz' , compassProvider.magnetometerEvent.z),
106
- ],
107
- ),
108
- const SizedBox (height: 24 ),
109
- const Text (
110
- 'Select axes parallel to ground' ,
111
- style: TextStyle (
112
- fontSize: 16 ,
113
- fontWeight: FontWeight .w500,
114
- ),
115
- ),
116
- const SizedBox (height: 16 ),
117
- Row (
118
- mainAxisAlignment: MainAxisAlignment .spaceEvenly,
119
- children: [
120
- _buildAxisSelector (context, 'X' , 'X axis' ),
121
- _buildAxisSelector (context, 'Y' , 'Y axis' ),
122
- _buildAxisSelector (context, 'Z' , 'Z axis' ),
123
- ],
88
+ ),
89
+ const SizedBox (height: 24 ),
90
+ Container (
91
+ padding: const EdgeInsets .all (16 ),
92
+ decoration: BoxDecoration (
93
+ color: Colors .grey[100 ],
94
+ borderRadius: BorderRadius .circular (12 ),
95
+ ),
96
+ child: Column (
97
+ children: [
98
+ Row (
99
+ mainAxisAlignment: MainAxisAlignment .spaceEvenly,
100
+ children: [
101
+ _buildAxisColumn (
102
+ 'Bx' , compassProvider.magnetometerEvent.x),
103
+ _buildAxisColumn (
104
+ 'By' , compassProvider.magnetometerEvent.y),
105
+ _buildAxisColumn (
106
+ 'Bz' , compassProvider.magnetometerEvent.z),
107
+ ],
108
+ ),
109
+ const SizedBox (height: 24 ),
110
+ Text (
111
+ parallelToGround,
112
+ style: const TextStyle (
113
+ fontSize: 16 ,
114
+ fontWeight: FontWeight .w500,
124
115
),
125
- ],
126
- ),
116
+ ),
117
+ const SizedBox (height: 16 ),
118
+ Row (
119
+ mainAxisAlignment: MainAxisAlignment .spaceEvenly,
120
+ children: [
121
+ _buildAxisSelector (context, 'X' , 'X axis' ),
122
+ _buildAxisSelector (context, 'Y' , 'Y axis' ),
123
+ _buildAxisSelector (context, 'Z' , 'Z axis' ),
124
+ ],
125
+ ),
126
+ ],
127
127
),
128
- const SizedBox (height : 16 ),
129
- ] ,
130
- ) ,
128
+ ),
129
+ const SizedBox (height : 16 ) ,
130
+ ] ,
131
131
),
132
132
),
133
- );
134
- },
135
- );
133
+ ),
134
+ );
135
+ } );
136
136
}
137
137
138
138
Widget _buildAxisColumn (String label, double value) {
@@ -168,46 +168,45 @@ class _CompassScreenContentState extends State<CompassScreenContent> {
168
168
169
169
Widget _buildAxisSelector (BuildContext context, String axis, String label) {
170
170
return Consumer <CompassProvider >(
171
- builder: (context, compassProvider, child) {
172
- bool isSelected = compassProvider.selectedAxis == axis;
171
+ builder: (context, compassProvider, child) {
172
+ bool isSelected = compassProvider.selectedAxis == axis;
173
173
174
- return GestureDetector (
175
- onTap: () => compassProvider.onAxisSelected (axis),
176
- child: Row (
177
- mainAxisSize: MainAxisSize .min,
178
- children: [
179
- Container (
180
- width: 20 ,
181
- height: 20 ,
182
- decoration: BoxDecoration (
183
- shape: BoxShape .circle,
184
- border: Border .all (
185
- color: isSelected ? Colors .red : Colors .grey,
186
- width: 2 ,
187
- ),
188
- color: isSelected ? Colors .red : Colors .transparent,
174
+ return GestureDetector (
175
+ onTap: () => compassProvider.onAxisSelected (axis),
176
+ child: Row (
177
+ mainAxisSize: MainAxisSize .min,
178
+ children: [
179
+ Container (
180
+ width: 20 ,
181
+ height: 20 ,
182
+ decoration: BoxDecoration (
183
+ shape: BoxShape .circle,
184
+ border: Border .all (
185
+ color: isSelected ? Colors .red : Colors .grey,
186
+ width: 2 ,
189
187
),
190
- child: isSelected
191
- ? const Icon (
192
- Icons .circle,
193
- size: 10 ,
194
- color: Colors .white,
195
- )
196
- : null ,
188
+ color: isSelected ? Colors .red : Colors .transparent,
197
189
),
198
- const SizedBox (width: 8 ),
199
- Text (
200
- label,
201
- style: TextStyle (
202
- fontSize: 14 ,
203
- color: isSelected ? Colors .red : Colors .grey[600 ],
204
- fontWeight: isSelected ? FontWeight .w500 : FontWeight .normal,
205
- ),
190
+ child: isSelected
191
+ ? const Icon (
192
+ Icons .circle,
193
+ size: 10 ,
194
+ color: Colors .white,
195
+ )
196
+ : null ,
197
+ ),
198
+ const SizedBox (width: 8 ),
199
+ Text (
200
+ label,
201
+ style: TextStyle (
202
+ fontSize: 14 ,
203
+ color: isSelected ? Colors .red : Colors .grey[600 ],
204
+ fontWeight: isSelected ? FontWeight .w500 : FontWeight .normal,
206
205
),
207
- ] ,
208
- ) ,
209
- );
210
- },
211
- );
206
+ ) ,
207
+ ] ,
208
+ ),
209
+ );
210
+ } );
212
211
}
213
- }
212
+ }
0 commit comments