removeSavedVehicle method
Removes a specific saved vehicle from the user's vehicle list.
Deletes a single vehicle device from the saved vehicles list while keeping other saved vehicles intact. This provides granular control over vehicle management compared to removeAllSavedVehicles which removes all vehicles.
Parameters:
nd: The specific NearbyDevice to remove from saved vehicles
Usage:
try {
// Get current saved vehicles
final savedVehicles = await communicator.getAllSavedVehicles();
// Find the vehicle to remove (e.g., user selection)
final vehicleToRemove = savedVehicles.firstWhere(
(vehicle) => vehicle.name == 'Old Car Bluetooth',
);
// Remove the specific vehicle
communicator.removeSavedVehicle(vehicleToRemove);
print('Removed vehicle: ${vehicleToRemove.name}');
// Other saved vehicles remain unaffected
} catch (e) {
print('Failed to remove vehicle: $e');
}
Important Notes:
- Only removes the specified device from the saved list
- Other saved vehicles remain unaffected
- If the removed vehicle was the only saved vehicle, automatic trip detection may be disabled
- Device can be re-added later by scanning and saving again
Use Cases:
- Removing sold or replaced vehicles
- Managing multiple vehicle households
- Cleaning up old or unused vehicle associations
- Fleet management scenarios
- Resolving conflicts with similar device names
Prerequisites:
- The device must exist in the saved vehicles list
- Device parameter should match an existing saved vehicle exactly
Comparison with removeAllSavedVehicles:
removeSavedVehicle: Removes one specific vehicleremoveAllSavedVehicles: Removes ALL saved vehicles
Implementation
void removeSavedVehicle(NearbyDevice nd) {
try {
kruzr_comm.removeSavedVehicle(nd);
} on Exception catch (e, stackTrace) {
if (kDebugMode) {
print("Error in removeAllSavedVehicles");
print(stackTrace);
print(e);
}
}
}