shouldEventSyncRealTime method
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:trueto enable real-time sync,falsefor batch sync
Usage:
try {
// Enable real-time synchronization
await communicator.shouldEventSyncRealTime(true);
print('Real-time sync enabled - events sync immediately');
// Disable real-time sync (batch mode)
await communicator.shouldEventSyncRealTime(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> shouldEventSyncRealTime(bool allowEventSyncRealTime) async {
try {
await kruzr_comm.shouldEventSyncRealTime(allowEventSyncRealTime);
} on Exception catch (e, stackTrace) {
if (kDebugMode) {
print("Error in shouldEventSyncRealTime");
print(stackTrace);
print(e);
}
return Future.error("Unable to change event sync real time pref");
}
return;
}