removeSavedVehicle function
Removes a specific saved vehicle from native platform storage.
This method deletes a single vehicle device from the saved vehicles list while preserving other saved vehicles. This provides granular vehicle management compared to removeAllSavedVehicles which removes all vehicles.
Parameters:
nearbyDevice: The specific vehicle device to remove from saved list. Must match an existing saved vehicle by MAC address for successful removal.
Behavior:
- Removes only the specified device from native storage
- Other saved vehicles remain unaffected
- Device matching is typically done by MAC address
- Converts device to JSON for native platform communication
Platform Communication:
- Method Channel: 'removeSavedVehicle'
- Data Format: JSON representation of NearbyDevice to remove
- Matching Logic: Native platform handles device identification
Usage Example:
// Get current saved vehicles
final savedVehicles = await getAllSavedVehicles();
// Find specific vehicle to remove
final vehicleToRemove = savedVehicles.firstWhere(
(vehicle) => vehicle.name == 'Old Car Bluetooth',
orElse: () => null,
);
if (vehicleToRemove != null) {
removeSavedVehicle(vehicleToRemove);
print('Removed: ${vehicleToRemove.name}');
}
Use Cases:
- Removing sold or replaced vehicles
- Managing multi-vehicle households
- Cleaning up unused vehicle associations
- Fleet management scenarios
- Resolving duplicate or problematic vehicle entries
Important Notes:
- Device must exist in saved vehicles list to be removed
- If removing the only saved vehicle, automatic trip detection may be disabled
- Device can be re-added later through normal scanning and saving process
- More targeted than removeAllSavedVehicles which removes all vehicles
Comparison:
removeSavedVehicle(): Removes one specific vehicleremoveAllSavedVehicles(): Removes ALL saved vehicles
Implementation
void removeSavedVehicle(NearbyDevice nearbyDevice) {
platform.invokeMethod('removeSavedVehicle', nearbyDevice.toJson());
}