setRealTimeEventSync method

Future<void> setRealTimeEventSync(
  1. bool allowEventSyncRealTime
)

Enables or disables real-time event synchronization.

Controls whether driving events and trip data should be synchronized with Kruzr servers immediately as they occur, or batched for later synchronization. Real-time sync provides immediate data availability but may impact battery life and data usage.

Parameters:

  • allowEventSyncRealTime: true to enable real-time sync, false for batch sync

Usage:

try {
  // Enable real-time synchronization
  await communicator.setRealTimeEventSync(true);
  print('Real-time sync enabled - events sync immediately');

  // Disable real-time sync (batch mode)
  await communicator.setRealTimeEventSync(false);
  print('Batch sync enabled - events sync periodically');
} catch (e) {
  print('Failed to change sync setting: $e');
}

Throws:

  • Future.error("Unable to change event sync real time pref"): When setting update fails

Important Notes:

  • Setting persists across app sessions
  • Real-time sync requires active internet connection
  • Overrides the initial configuration from Kruzr360InitConfig
  • Affects battery life and data usage patterns
  • May be subject to network conditions and server availability

Performance Considerations:

  • Real-time enabled: Immediate data availability, higher battery/data usage
  • Real-time disabled: Better battery life, periodic data updates

Use Cases:

  • Fleet monitoring requiring immediate updates
  • Battery optimization for extended trips
  • Network-constrained environments
  • User preference settings

Implementation

Future<void> setRealTimeEventSync(bool allowEventSyncRealTime) async {
  try {
    await kruzr_comm.setRealTimeEventSync(allowEventSyncRealTime);
  } on PlatformException catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in setRealTimeEventSync");
      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 setRealTimeEventSync");
      print(stackTrace);
      print(e);
    }
    return Future.error(PlatformException(code: "PLUGIN_ERROR", message: e.toString()));
  }
  return;
}