fetchTripStatsByAppTripId method

Future<TripStatsResponse?> fetchTripStatsByAppTripId(
  1. String appTripId
)

Retrieves statistical analysis for a specific trip.

Provides detailed statistical breakdown of driving behavior during the trip including acceleration patterns, braking events, cornering behavior, and speed analysis.

Parameters:

  • appTripId: Unique identifier for the trip

Returns:

  • TripStatsResponse?: Statistical trip analysis, or null if not available

Usage:

try {
  final tripStats = await communicator.fetchTripStatsByAppTripId('trip-123');
  if (tripStats != null) {
    print('Hard braking events: ${tripStats.hardBrakingCount}');
    print('Rapid acceleration events: ${tripStats.rapidAccelerationCount}');
    print('Average speed: ${tripStats.averageSpeed} km/h');
    print('Max speed: ${tripStats.maxSpeed} km/h');
  }
} catch (e) {
  print('Failed to fetch trip stats: $e');
}

Throws:

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

Use Cases:

  • Detailed driving behavior analysis
  • Performance coaching and feedback
  • Insurance reporting and risk assessment

Implementation

Future<TripStatsResponse?> fetchTripStatsByAppTripId(String appTripId) async {
  try {
    TripStatsResponse? tripStatsResponse = await kruzr_comm
        .fetchTripStatsByAppTripId(appTripId);
    return tripStatsResponse;
  } on Exception catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in fetchTripStatsByAppTripId");
      print(stackTrace);
      print(e);
    }
    return Future.error("Unable to get trip stats");
  }
}