saveVehicle function

void saveVehicle(
  1. NearbyDevice nearbyDevice
)

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

This method stores a discovered Bluetooth device in the user's saved vehicle list on the native platform. The saved vehicle will be used for automatic trip detection when the device is connected, enabling seamless trip monitoring without manual intervention.

Parameters:

  • nearbyDevice: The Bluetooth device to save as a vehicle. This device should represent the user's actual vehicle Bluetooth system (e.g., car stereo, infotainment system)

Implementation Details:

  • Converts the device to JSON format for native platform communication
  • Stores device information persistently on the native side
  • Enables automatic trip start/end detection for this device
  • Logs the saved device information for debugging purposes

Usage Example:

// After discovering devices through Bluetooth scan
final myCarDevice = NearbyDevice(
  name: "Honda CR-V",
  address: "AA:BB:CC:DD:EE:FF",
  rssi: -50,
);

saveVehicle(myCarDevice);

Platform Communication:

  • Method Channel: 'saveVehicle'
  • Data Format: JSON representation of NearbyDevice
  • Platform Storage: Device information stored in native preferences/database

Important Notes:

  • Device must have been discovered through Bluetooth scanning first
  • Multiple vehicles can be saved for households with multiple cars
  • Saved vehicles persist across app restarts
  • Device name and MAC address are used for future identification

Implementation

void saveVehicle(NearbyDevice nearbyDevice) {
  if (kDebugMode) {
    print("Saving vehicle: ${nearbyDevice.toJson()}");
  }
  platform.invokeMethod('saveVehicle', nearbyDevice.toJson());
}