Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e6ffb00b2a | |||
| b3e85983e7 | |||
| 89ce53bb1b | |||
| 56327c00ec | |||
| 20a7691ac2 |
@@ -26,9 +26,9 @@ class ColorThemes {
|
||||
unitText: Color.fromARGB(255, 244, 201, 255),
|
||||
),
|
||||
ColorTheme(
|
||||
name: 'Yuubari',
|
||||
name: 'Yuuparo',
|
||||
background: Color.fromARGB(255, 85, 99, 112),
|
||||
speedText: Color.fromARGB(255, 255, 166, 0),
|
||||
speedText: Color.fromARGB(255, 255, 171, 16),
|
||||
headingText: Color.fromARGB(255, 228, 235, 238),
|
||||
unitText: Color.fromARGB(255, 141, 196, 184),
|
||||
),
|
||||
@@ -39,6 +39,13 @@ class ColorThemes {
|
||||
headingText: Color.fromARGB(255, 140, 94, 151),
|
||||
unitText: Color.fromARGB(255, 114, 85, 109),
|
||||
),
|
||||
ColorTheme(
|
||||
name: 'Yuuparo Light',
|
||||
background: Color.fromARGB(255, 228, 235, 238),
|
||||
speedText: Color.fromARGB(255, 85, 99, 112),
|
||||
headingText: Color.fromARGB(255, 255, 157, 65),
|
||||
unitText: Color.fromARGB(255, 98, 124, 118),
|
||||
),
|
||||
];
|
||||
|
||||
static ColorTheme getTheme(int index) {
|
||||
|
||||
+15
-5
@@ -3,11 +3,13 @@ import 'package:geolocator/geolocator.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
|
||||
class GpsService {
|
||||
static double? _lastValidHeading;
|
||||
|
||||
static Stream<Position> get positionStream {
|
||||
return Geolocator.getPositionStream(
|
||||
locationSettings: const LocationSettings(
|
||||
accuracy: LocationAccuracy.bestForNavigation,
|
||||
distanceFilter: 1,
|
||||
distanceFilter: 0,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -21,16 +23,24 @@ class GpsService {
|
||||
return await Geolocator.isLocationServiceEnabled();
|
||||
}
|
||||
|
||||
static double getCachedHeading(double heading) {
|
||||
if (heading >= 0 && heading <= 360) {
|
||||
_lastValidHeading = heading;
|
||||
return heading;
|
||||
}
|
||||
return _lastValidHeading ?? 0.0;
|
||||
}
|
||||
|
||||
static String getCompassDirection(double heading) {
|
||||
if (heading < 0) return 'N/A';
|
||||
final cachedHeading = getCachedHeading(heading);
|
||||
|
||||
const directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
|
||||
final index = ((heading + 22.5) / 45).floor() % 8;
|
||||
final index = ((cachedHeading + 22.5) / 45).floor() % 8;
|
||||
return directions[index];
|
||||
}
|
||||
|
||||
static String formatHeading(double heading) {
|
||||
if (heading < 0) return 'N/A';
|
||||
return '${heading.round()} ${getCompassDirection(heading)}';
|
||||
final cachedHeading = getCachedHeading(heading);
|
||||
return '${cachedHeading.round()}° ${getCompassDirection(heading)}';
|
||||
}
|
||||
}
|
||||
+25
-8
@@ -5,6 +5,7 @@ import 'package:wakelock_plus/wakelock_plus.dart';
|
||||
import 'speed_units.dart';
|
||||
import 'gps_service.dart';
|
||||
import 'color_themes.dart';
|
||||
import 'dart:math' as math; // Import for math.pi
|
||||
|
||||
void main() {
|
||||
runApp(const SpeedoApp());
|
||||
@@ -91,7 +92,13 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> {
|
||||
|
||||
_positionSubscription = GpsService.positionStream.listen(
|
||||
_onPositionUpdate,
|
||||
onError: (error) => setState(() => _errorMessage = 'GPS error: $error'),
|
||||
onError: (error) {
|
||||
// Only show persistent GPS errors, not temporary signal issues
|
||||
final errorString = error.toString().toLowerCase();
|
||||
if (!errorString.contains('timeout') && !errorString.contains('temporarily')) {
|
||||
setState(() => _errorMessage = 'GPS error: $error');
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
setState(() => _errorMessage = 'Failed to initialize GPS');
|
||||
@@ -118,10 +125,17 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> {
|
||||
});
|
||||
}
|
||||
|
||||
String _getSpeedDisplayText(double displaySpeed) {
|
||||
if (_speed < 1.0 && (_heading < 0.0 || _heading >= 360.0)) {
|
||||
return '--';
|
||||
}
|
||||
return displaySpeed.toStringAsFixed(1);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final displaySpeed = _currentUnit.convert(_speed);
|
||||
final speedText = displaySpeed.toStringAsFixed(0);
|
||||
final speedText = _getSpeedDisplayText(displaySpeed);
|
||||
final currentTheme = ColorThemes.getTheme(_currentThemeIndex);
|
||||
|
||||
return Scaffold(
|
||||
@@ -151,7 +165,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> {
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
color: Colors.transparent,
|
||||
padding: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
@@ -177,7 +191,7 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> {
|
||||
child: Text(
|
||||
speedText,
|
||||
style: TextStyle(
|
||||
fontSize: 200,
|
||||
fontSize: 160,
|
||||
fontWeight: FontWeight.w300,
|
||||
color: currentTheme.speedText,
|
||||
fontFamily: 'DIN1451Alt',
|
||||
@@ -222,10 +236,13 @@ class _SpeedometerScreenState extends State<SpeedometerScreen> {
|
||||
children: [
|
||||
Flexible(
|
||||
flex: 2,
|
||||
child: Icon(
|
||||
Icons.navigation,
|
||||
size: 100,
|
||||
color: currentTheme.headingText,
|
||||
child: Transform.rotate(
|
||||
angle: (_heading >= 0 && _heading < 360) ? (_heading * math.pi / 180.0) : 0,
|
||||
child: Icon(
|
||||
Icons.navigation,
|
||||
size: 100,
|
||||
color: currentTheme.headingText,
|
||||
),
|
||||
),
|
||||
),
|
||||
Flexible(
|
||||
|
||||
@@ -21,6 +21,7 @@ dependencies:
|
||||
# Keep screen awake during navigation
|
||||
wakelock_plus: ^1.2.8
|
||||
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
|
||||
Reference in New Issue
Block a user