getDrivingBehaviourScoreChange method

Future<DrivingBehaviourScoreChange?> getDrivingBehaviourScoreChange(
  1. KruzrPerioicType kruzrPeriodicType
)

Retrieves the change in driving behavior scores over a specified period.

Shows how driving behavior has improved or declined compared to the previous period, useful for tracking progress and trends.

Parameters:

  • kruzrPeriodicType: The period type for comparison (daily, weekly, monthly)

Returns:

  • DrivingBehaviourScoreChange?: Score changes and trends, or null if not available

Usage:

try {
  final scoreChange = await communicator.getDrivingBehaviourScoreChange(
    KruzrPerioicType.weekly,
  );
  if (scoreChange != null) {
    print('Overall change: ${scoreChange.overallChange > 0 ? "+" : ""}${scoreChange.overallChange}');
    print('Acceleration change: ${scoreChange.accelerationChange}');
    print('Braking change: ${scoreChange.brakingChange}');
  }
} catch (e) {
  print('Failed to get score change: $e');
}

Throws:

  • Future.error("Unable to get aggregated driving behaviour score change"): When retrieval fails

Use Cases:

  • Progress tracking dashboards
  • Improvement notifications
  • Trend analysis

Implementation

Future<DrivingBehaviourScoreChange?> getDrivingBehaviourScoreChange(
    KruzrPerioicType kruzrPeriodicType,
    ) async {
  try {
    return await kruzr_comm.getDrivingBehaviourScoreChange(
      kruzrPeriodicType,
    );
  } on PlatformException catch (e) {
    if (kDebugMode) {
      print(e);
      print("PlatformException in getDrivingBehaviourScoreChange");
    }
    return Future.error({"code": e.code, "message": e.message, "details": e.details});
  } on Exception catch (e) {
    if (kDebugMode) {
      print(e);
      print("Exception in getDrivingBehaviourScoreChange");
    }
    return Future.error(PlatformException(code: "PLUGIN_ERROR", message: e.toString()));
  }
}