getFileNaturalSize static method

Size? getFileNaturalSize(
  1. String? path
)

Implementation

static ui.Size? getFileNaturalSize(String? path) {
  if (kIsWeb || path == null || path.isEmpty) {
    return null;
  }
  final normalizedPath = _normalizeFilePath(path);
  if (normalizedPath == null || normalizedPath.isEmpty) {
    return null;
  }
  final cached = _fileSizeCache.remove(normalizedPath);
  if (cached != null) {
    _fileSizeCache[normalizedPath] = cached;
    return cached;
  }
  try {
    final file = File(normalizedPath);
    if (!file.existsSync()) {
      return null;
    }
    final result = image_size_getter.ImageSizeGetter.getSizeResult(
      FileInput(file),
    );
    final size = ui.Size(
      result.size.width.toDouble(),
      result.size.height.toDouble(),
    );
    _fileSizeCache[normalizedPath] = size;
    _trimCache(_fileSizeCache, _maxSizeCacheEntries);
    return size;
  } catch (_) {
    return null;
  }
}