2026-02-08 00:26:59 +09:00
|
|
|
import 'dart:math' as math;
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import '../theme/app_theme.dart';
|
|
|
|
|
|
|
|
|
|
class GpsCompass extends StatelessWidget {
|
|
|
|
|
final double? heading;
|
|
|
|
|
|
|
|
|
|
const GpsCompass({super.key, this.heading});
|
|
|
|
|
|
|
|
|
|
bool get _hasSignal => heading != null && !heading!.isNaN && heading! >= 0 && heading! < 360;
|
|
|
|
|
|
|
|
|
|
String get _displayHeading {
|
2026-02-08 02:27:21 +09:00
|
|
|
if (!_hasSignal) return '—-'; // Intentional double dash
|
2026-02-08 00:26:59 +09:00
|
|
|
return '${heading!.round()}°';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final theme = AppTheme.of(context);
|
|
|
|
|
|
|
|
|
|
// No signal = subdued color, valid = foreground
|
|
|
|
|
final color = _hasSignal ? theme.foreground : theme.subdued;
|
|
|
|
|
|
|
|
|
|
// Convert to radians, 0 = no rotation when no signal
|
|
|
|
|
final angle = _hasSignal ? (heading! * math.pi / 180.0) : 0.0;
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
children: [
|
|
|
|
|
Flexible(
|
|
|
|
|
flex: 3,
|
|
|
|
|
child: Transform.rotate(
|
2026-02-08 02:27:21 +09:00
|
|
|
angle: _hasSignal ? angle : 0,
|
2026-02-08 00:26:59 +09:00
|
|
|
child: FittedBox(
|
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
|
child: Icon(
|
2026-02-08 02:27:21 +09:00
|
|
|
_hasSignal ? Icons.navigation : Icons.navigation_outlined,
|
|
|
|
|
size: 80,
|
2026-02-08 00:26:59 +09:00
|
|
|
color: color,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Flexible(
|
|
|
|
|
flex: 1,
|
|
|
|
|
child: FittedBox(
|
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
|
child: Text(
|
|
|
|
|
_displayHeading,
|
|
|
|
|
style: TextStyle(
|
2026-02-08 02:27:21 +09:00
|
|
|
fontSize: 60,
|
2026-02-08 00:26:59 +09:00
|
|
|
color: color,
|
|
|
|
|
fontFamily: 'DIN1451',
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|