clearTemp static method

Future<void> clearTemp()

Deletes all files within the temporary directory without deleting the directory itself.

Implementation

static Future<void> clearTemp() async {
  try {
    final dir = await getTemporaryDirectory();
    if (await dir.exists()) {
      final entities = dir.listSync();
      for (final entity in entities) {
        try {
          await entity.delete(recursive: true);
        } catch (e) {
          debugPrint('Failed to delete temp entity: ${entity.path}, error: $e');
        }
      }
    }
  } catch (e) {
    debugPrint('Error clearing temp directory: $e');
  }
}