deleteData method

Future<bool> deleteData(
  1. String path
)

Deletes data from the specified path in the RTDB.

  • path: The database path to delete data from.

Returns true if the operation is successful, false otherwise.

Implementation

Future<bool> deleteData(String path) async {
  _startRateLimitResetTimer();
  final authToken = await _getAuthToken();
  if (authToken == null) return false;

  final url = Uri.parse('$_baseUrl$path.json?auth=$authToken');

  if (!_canProceedWithRequest(0, isWrite: true)) {
    debugPrint('Rate limit exceeded for delete operation.');
    return false;
  }

  // Manage connection limit
  if (_currentHttpConnections >= maxConnections) {
    String oldestConnection = _connectionOrder.removeAt(0);
    _runningStreams[oldestConnection]?.close();
    _runningStreams.remove(oldestConnection);
  }

  try {
    _currentHttpConnections++;
    _connectionOrder.add(path);
    final response = await _client.delete(url);
    _currentHttpConnections--;

    if (response.statusCode == 200) {
      _currentWrites++;
      debugPrint('Document deleted successfully at $path.');
      return true;
    } else {
      debugPrint('Error deleting data. Status code: ${response.statusCode}');
      return false;
    }
  } catch (e) {
    _currentHttpConnections--;
    debugPrint('Error deleting data: $e');
    return false;
  }
}