getCurrentTripData method
Retrieves data for the currently active trip.
Returns real-time information about an ongoing trip including distance, duration, current location, and driving behavior metrics.
Returns:
CurrentTripDataResponse?: Current trip data, ornullif no active trip
Usage:
try {
final currentTrip = await communicator.getCurrentTripData();
if (currentTrip != null) {
print('Distance: ${currentTrip.distance} km');
print('Duration: ${currentTrip.duration} minutes');
print('Current speed: ${currentTrip.currentSpeed} km/h');
} else {
print('No active trip');
}
} catch (e) {
print('Failed to get current trip data: $e');
}
Throws:
Future.error("Unable to get current trip data"): When retrieval fails
Use Cases:
- Real-time trip monitoring dashboards
- Live trip statistics display
- Progress tracking during ongoing trips
Implementation
Future<CurrentTripDataResponse?> getCurrentTripData() async {
try {
CurrentTripDataResponse? currentTripDataResponse = await kruzr_comm
.getCurrentTripData();
return currentTripDataResponse;
} on Exception catch (e, stackTrace) {
if (kDebugMode) {
print("Error in getCurrentTripData");
print(stackTrace);
print(e);
}
return Future.error("Unable to get current trip data");
}
}