saveVehicle method

void saveVehicle(
  1. NearbyDevice nearbyDevice
)

Saves a nearby Bluetooth device as a known vehicle for future automatic detection.

Stores a discovered device in the user's saved vehicle list, enabling automatic trip detection when the device is connected. This is typically used to associate a user's smartphone with their vehicle's Bluetooth system for seamless trip monitoring.

Parameters:

  • nearbyDevice: The Bluetooth device to save as a vehicle

Usage:

try {
  // First scan for devices
  final devices = await communicator.scanForNearbyDevices();

  // Let user select their vehicle from discovered devices
  final selectedDevice = devices.first; // User selection logic here

  // Save the selected device as a vehicle
  communicator.saveVehicle(selectedDevice);
  print('Vehicle saved: ${selectedDevice.name}');

  // Device will now be used for automatic trip detection
} catch (e) {
  print('Failed to save vehicle: $e');
}

Important Notes:

  • Device information is stored locally on the device
  • Saved vehicles enable automatic trip start/end detection
  • Multiple vehicles can be saved for multi-vehicle households
  • Device must be discoverable during the initial save process

Use Cases:

  • Initial vehicle setup during onboarding
  • Adding secondary vehicles (family cars, rental cars)
  • Fleet vehicle assignment for commercial users
  • Replacing or updating vehicle information

Prerequisites:

  • Device must have been discovered through Bluetooth scanning
  • Bluetooth permissions must be granted
  • Device should be the user's actual vehicle Bluetooth system

Implementation

void saveVehicle(NearbyDevice nearbyDevice) {
  try {
    kruzr_comm.saveVehicle(nearbyDevice);
  } on Exception catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in saveVehicle");
      print(stackTrace);
      print(e);
    }
  }
}