Files
gps-speedo/lib/widgets/speed_unit_selector.dart
T
Mikkeli Matlock 71b7611a48 Implement v1.1 enhancements: auto-rotate, interactive gauge, and extended units
Features added:
- Auto-rotate support for portrait/landscape orientations
- Interactive gauge: tap to switch between digital and analog modes
- Extended speed units: added knots with quick selector buttons
- New SpeedUnitSelector widget for convenient unit switching

Known issues identified:
- 10 package dependencies need updates to latest compatible versions
- Orientation switching needs to override system auto-rotate toggle
- Background color customization moved back to TODO (build issues)

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-21 01:58:46 +09:00

57 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../providers/settings_provider.dart';
class SpeedUnitSelector extends StatelessWidget {
const SpeedUnitSelector({super.key});
@override
Widget build(BuildContext context) {
return Consumer<SettingsProvider>(
builder: (context, settings, child) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: SpeedUnit.values.map((unit) {
final isSelected = settings.speedUnit == unit;
return Expanded(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: ElevatedButton(
onPressed: () => settings.setSpeedUnit(unit),
style: ElevatedButton.styleFrom(
backgroundColor: isSelected
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.surface,
foregroundColor: isSelected
? Theme.of(context).colorScheme.onPrimary
: Theme.of(context).colorScheme.onSurface,
elevation: isSelected ? 4 : 1,
padding: const EdgeInsets.symmetric(vertical: 8),
),
child: Text(
_getUnitDisplayText(unit),
style: TextStyle(
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
fontSize: 12,
),
),
),
),
);
}).toList(),
);
},
);
}
String _getUnitDisplayText(SpeedUnit unit) {
switch (unit) {
case SpeedUnit.kmh:
return 'km/h';
case SpeedUnit.mph:
return 'mph';
case SpeedUnit.knots:
return 'knots';
}
}
}