47 lines
1.4 KiB
Dart
47 lines
1.4 KiB
Dart
import 'package:flutter/foundation.dart';
|
|
|
|
import '../models/scooter_state.dart';
|
|
|
|
/// Result of a local scooter authentication attempt.
|
|
///
|
|
/// A missing response is deliberately NOT a value here: it surfaces as a
|
|
/// [TimeoutException] so callers can tell "wrong PIN" from "no answer".
|
|
enum AuthenticationResult {
|
|
success,
|
|
invalidCredential,
|
|
}
|
|
|
|
/// Base class for every supported scooter.
|
|
///
|
|
/// The current [state] is always available synchronously and the UI rebuilds
|
|
/// through [ListenableBuilder]. There is no replay problem because there is
|
|
/// no stream to miss.
|
|
abstract class Scooter extends ChangeNotifier {
|
|
ScooterState get state;
|
|
|
|
Future<void> connect();
|
|
Future<void> disconnect();
|
|
|
|
Future<AuthenticationResult> authenticate(String credential);
|
|
|
|
Future<void> lock();
|
|
Future<void> unlock();
|
|
|
|
Future<void> setHeadlight(bool enabled);
|
|
|
|
/// True only when the implementation holds enough fresh scooter state to
|
|
/// build a safe control write AND control writes are enabled for this build.
|
|
bool get canWrite;
|
|
|
|
/// Disconnects and releases every resource. The object is unusable after.
|
|
Future<void> disposeScooter();
|
|
}
|
|
|
|
/// Thrown into any pending operation when the BLE link drops underneath it.
|
|
class ScooterConnectionLostException implements Exception {
|
|
const ScooterConnectionLostException([this.message = 'Connection to the scooter was lost']);
|
|
final String message;
|
|
@override
|
|
String toString() => message;
|
|
}
|