getTripStats method

Future<TripStatsResponse?> getTripStats(
  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.getTripStats('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?> getTripStats(String appTripId) async {
  try {
    TripStatsResponse? tripStatsResponse = await kruzr_comm
        .getTripStatsById(appTripId);
    return tripStatsResponse;
  } on PlatformException catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in getTripStats");
      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 getTripStats");
      print(stackTrace);
      print(e);
    }
    return Future.error(PlatformException(code: "PLUGIN_ERROR", message: e.toString()));
  }
}