feat: basic trainer support
This commit is contained in:
@ -10,6 +10,7 @@ import 'package:abawo_bt_app/util/bluetooth_settings.dart';
|
||||
import 'package:abawo_bt_app/widgets/bike_scan_dialog.dart';
|
||||
import 'package:abawo_bt_app/widgets/firmware_update_fullscreen.dart';
|
||||
import 'package:abawo_bt_app/widgets/gear_ratio_editor_card.dart';
|
||||
import 'package:abawo_bt_app/widgets/simulation_card.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
@ -494,27 +495,43 @@ class _DeviceDetailsPageState extends ConsumerState<DeviceDetailsPage> {
|
||||
}
|
||||
|
||||
_isAssignTrainerDialogOpen = true;
|
||||
final TrainerScanResult? selectedTrainer;
|
||||
final TrainerAssignment? assignment;
|
||||
try {
|
||||
selectedTrainer = await BikeScanDialog.show(
|
||||
assignment = await BikeScanDialog.show(
|
||||
context,
|
||||
shifter: shifter,
|
||||
);
|
||||
} finally {
|
||||
_isAssignTrainerDialogOpen = false;
|
||||
}
|
||||
if (selectedTrainer == null || !mounted) {
|
||||
if (assignment == null || !mounted) {
|
||||
return;
|
||||
}
|
||||
final selectedTrainer = assignment.trainer;
|
||||
|
||||
final result =
|
||||
await shifter.connectButtonToTrainer(selectedTrainer.address);
|
||||
final result = await shifter.connectButtonToTrainer(selectedTrainer.address,
|
||||
protocol: assignment.protocol);
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.isErr()) {
|
||||
final err = result.unwrapErr();
|
||||
if (err.toString().contains('Firmware update required')) {
|
||||
await showDialog<void>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Firmware update required'),
|
||||
content: const Text(
|
||||
'This trainer model is not available in the installed firmware. Choose Automatic detection if your trainer supports FTMS, or contact abawo support for compatible firmware. Automatic firmware downloads are not available yet.'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Close'))
|
||||
],
|
||||
));
|
||||
return;
|
||||
}
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Connect request failed: $err')),
|
||||
);
|
||||
@ -1124,6 +1141,13 @@ class _DeviceDetailsPageState extends ConsumerState<DeviceDetailsPage> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (_shifterService != null)
|
||||
SimulationCard(
|
||||
key: ObjectKey(_shifterService),
|
||||
shifter: _shifterService!,
|
||||
enabled: !_isFirmwareUpdateBusy,
|
||||
),
|
||||
] else if (isCurrentConnected) ...[
|
||||
_PairingRequiredCard(
|
||||
isChecking: _isPairingCheckRunning,
|
||||
|
||||
Reference in New Issue
Block a user