feat: new shifter types and better gear ratio editor

This commit is contained in:
2026-02-23 11:45:25 +01:00
parent dcb1e6596e
commit 575ccaae42
4 changed files with 551 additions and 106 deletions

View File

@ -62,6 +62,7 @@ class _DeviceDetailsPageState extends ConsumerState<DeviceDetailsPage> {
bool _hasLoadedGearRatios = false;
String? _gearRatiosError;
List<double> _gearRatios = const [];
int _defaultGearIndex = 0;
@override
void initState() {
@ -245,20 +246,28 @@ class _DeviceDetailsPageState extends ConsumerState<DeviceDetailsPage> {
}
setState(() {
_gearRatios = result.unwrap();
final data = result.unwrap();
_gearRatios = data.ratios;
_defaultGearIndex = data.defaultGearIndex;
_isGearRatiosLoading = false;
_hasLoadedGearRatios = true;
_gearRatiosError = null;
});
}
Future<String?> _saveGearRatios(List<double> ratios) async {
Future<String?> _saveGearRatios(
List<double> ratios, int defaultGearIndex) async {
final shifter = _shifterService;
if (shifter == null) {
return 'Status channel is not ready yet.';
}
final result = await shifter.writeGearRatios(ratios);
final result = await shifter.writeGearRatios(
GearRatiosData(
ratios: ratios,
defaultGearIndex: defaultGearIndex,
),
);
if (result.isErr()) {
return 'Could not save gear ratios: ${result.unwrapErr()}';
}
@ -269,6 +278,9 @@ class _DeviceDetailsPageState extends ConsumerState<DeviceDetailsPage> {
setState(() {
_gearRatios = List<double>.from(ratios);
_defaultGearIndex = ratios.isEmpty
? 0
: defaultGearIndex.clamp(0, ratios.length - 1).toInt();
_hasLoadedGearRatios = true;
_gearRatiosError = null;
});
@ -495,6 +507,7 @@ class _DeviceDetailsPageState extends ConsumerState<DeviceDetailsPage> {
const SizedBox(height: 16),
GearRatioEditorCard(
ratios: _gearRatios,
defaultGearIndex: _defaultGearIndex,
isLoading: _isGearRatiosLoading,
errorText: _gearRatiosError,
onRetry: _loadGearRatios,