flush method

Future<void> flush()

Flush all data to persistent storage (IndexedDB)

Implementation

Future<void> flush() async {
  if (!_isInitialized) {
    ObslyLogger.warn('Storage not initialized, cannot flush');
    return;
  }

  try {
    if (_useHive) {
      // Force Hive to write to IndexedDB
      ObslyLogger.debug('πŸ”„ Flushing data to IndexedDB...');

      if (_eventsBox != null) {
        await _eventsBox!.flush();
        ObslyLogger.debug('βœ… Events box flushed to IndexedDB');
      }

      if (_internalStateBox != null) {
        await _internalStateBox!.flush();
        ObslyLogger.debug('βœ… Internal state box flushed to IndexedDB');
      }

      if (_performanceBox != null) {
        await _performanceBox!.flush();
        ObslyLogger.debug('βœ… Performance box flushed to IndexedDB');
      }

      ObslyLogger.log('πŸ’Ύ All data flushed to IndexedDB successfully');
    } else {
      // SharedPreferences should auto-persist, but we can call commit if available
      ObslyLogger.debug('πŸ’Ύ SharedPreferences doesn\'t need manual flush');
    }
  } catch (e) {
    ObslyLogger.error('Error flushing data: $e');
  }
}