getDrivingSummary method
Future<DrivingSummary?>
getDrivingSummary(
- DateTime startTime,
- DateTime endTime,
- KruzrPerioicType kruzrPerioicType
Retrieves comprehensive driving summary for a specified time period.
Provides an overview of driving behavior including distance, time, safety scores, and other key metrics aggregated over the specified period.
Parameters:
startTime: Beginning of the time rangeendTime: End of the time rangekruzrPerioicType: Aggregation period (daily, weekly, monthly)
Returns:
DrivingSummary?: Comprehensive driving metrics, ornullif not available
Usage:
try {
final summary = await communicator.getDrivingSummary(
DateTime.now().subtract(Duration(days: 30)),
DateTime.now(),
KruzrPerioicType.weekly,
);
if (summary != null) {
print('Distance: ${summary.totalDistance} km');
print('Drive time: ${summary.totalDriveTime} hours');
print('Average score: ${summary.averageScore}');
}
} catch (e) {
print('Failed to get driving summary: $e');
}
Throws:
Future.error("Unable to get driving summary"): When retrieval fails
Implementation
Future<DrivingSummary?> getDrivingSummary(
DateTime startTime,
DateTime endTime,
KruzrPerioicType kruzrPerioicType,
) async {
try {
return await kruzr_comm.getDrivingSummary(
startTime,
endTime,
kruzrPerioicType,
);
} on PlatformException catch (e) {
if (kDebugMode) {
print(e);
print("PlatformException in getDrivingSummary");
}
return Future.error("Unable to get driving summary");
} on Exception catch (e) {
if (kDebugMode) {
print(e);
print("Exception in getDrivingSummary");
}
return Future.error("Unable to get driving summary");
}
}