Skip to content

Commit 05d2830

Browse files
made suggested changes
1 parent 0c29ce8 commit 05d2830

File tree

4 files changed

+130
-124
lines changed

4 files changed

+130
-124
lines changed

lib/constants.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,7 @@ List<String> connectWithUs = [
133133
'Developers'
134134
];
135135
String softwareLicenses = 'Software Licenses';
136+
String magnetometerError = 'Magnetometer error:';
137+
String accelerometerError = 'Accelerometer error:';
138+
String compassTitle = 'Compass';
139+
String parallelToGround = 'Select axes parallel to ground';

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@ void _preCacheImages(BuildContext context) {
6161
}
6262
precacheImage(
6363
const AssetImage('assets/icons/ic_nav_header_logo.png'), context);
64-
}
64+
}

lib/providers/compass_provider.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import 'dart:math';
33
import 'package:flutter/material.dart';
44
import 'package:sensors_plus/sensors_plus.dart';
55
import 'package:flutter/foundation.dart';
6+
import 'package:pslab/others/logger_service.dart';
7+
8+
import '../constants.dart';
69

710
class CompassProvider extends ChangeNotifier {
811
MagnetometerEvent _magnetometerEvent =
@@ -31,7 +34,7 @@ class CompassProvider extends ChangeNotifier {
3134
notifyListeners();
3235
},
3336
onError: (error) {
34-
debugPrint("Magnetometer error: $error");
37+
logger.e("$magnetometerError: $error");
3538
},
3639
cancelOnError: true,
3740
);
@@ -43,7 +46,7 @@ class CompassProvider extends ChangeNotifier {
4346
notifyListeners();
4447
},
4548
onError: (error) {
46-
debugPrint("Accelerometer error: $error");
49+
logger.e("$accelerometerError: $error");
4750
},
4851
cancelOnError: true,
4952
);

lib/view/compass_screen.dart

Lines changed: 120 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:provider/provider.dart';
33
import 'package:pslab/view/widgets/common_scaffold_widget.dart';
4-
4+
import 'package:pslab/constants.dart';
55
import '../providers/compass_provider.dart';
66

77
class CompassScreen extends StatelessWidget {
@@ -24,6 +24,7 @@ class CompassScreenContent extends StatefulWidget {
2424
}
2525

2626
class _CompassScreenContentState extends State<CompassScreenContent> {
27+
static const String compassIcon = 'assets/icons/compass_icon.png';
2728
@override
2829
void initState() {
2930
super.initState();
@@ -41,98 +42,97 @@ class _CompassScreenContentState extends State<CompassScreenContent> {
4142
@override
4243
Widget build(BuildContext context) {
4344
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,
6767
),
6868
),
6969
),
7070
),
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,
8484
),
85-
],
86-
),
85+
),
86+
],
8787
),
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,
124115
),
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+
],
127127
),
128-
const SizedBox(height: 16),
129-
],
130-
),
128+
),
129+
const SizedBox(height: 16),
130+
],
131131
),
132132
),
133-
);
134-
},
135-
);
133+
),
134+
);
135+
});
136136
}
137137

138138
Widget _buildAxisColumn(String label, double value) {
@@ -168,46 +168,45 @@ class _CompassScreenContentState extends State<CompassScreenContent> {
168168

169169
Widget _buildAxisSelector(BuildContext context, String axis, String label) {
170170
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;
173173

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,
189187
),
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,
197189
),
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,
206205
),
207-
],
208-
),
209-
);
210-
},
211-
);
206+
),
207+
],
208+
),
209+
);
210+
});
212211
}
213-
}
212+
}

0 commit comments

Comments
 (0)