getTripDetails method

Future<SingleTripResponse?> getTripDetails(
  1. String appTripId
)

Retrieves detailed information for a specific trip using its app trip ID.

Fetches comprehensive trip details including route information, driving behavior analysis, duration, distance, and safety metrics.

Parameters:

  • appTripId: Unique identifier for the trip

Returns:

  • SingleTripResponse?: Detailed trip information, or null if not found

Usage:

try {
  final tripDetails = await communicator.getTripDetails('trip-123');
  if (tripDetails != null) {
    print('Trip date: ${tripDetails.startTime}');
    print('Distance: ${tripDetails.distance} km');
    print('Duration: ${tripDetails.duration} minutes');
    print('Safety score: ${tripDetails.safetyScore}');
  }
} catch (e) {
  print('Failed to fetch trip details: $e');
}

Throws:

  • Future.error("Unable to get trip details"): When retrieval fails

Use Cases:

  • Trip history viewing
  • Detailed trip analysis
  • Trip sharing and reporting

Implementation

Future<SingleTripResponse?> getTripDetails(
    String appTripId,
    ) async {
  try {
    SingleTripResponse? singleTripResponse = await kruzr_comm
        .getTripDetailsById(appTripId);
    return singleTripResponse;
  } on PlatformException catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in getTripDetails");
      print(stackTrace);
      print(e);
    }
    return Future.error({"code": e.code, "message": e.message, "details": e.details});
  } on Exception catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in getTripDetails");
      print(stackTrace);
      print(e);
    }
    return Future.error(PlatformException(code: "PLUGIN_ERROR", message: e.toString()));
  }
}