getSize method

String? getSize(
  1. String distroName
)

Get distro size of distroName a string with a GB suffix. Returns null if size is 0. e.g. "2.00 GB"

Implementation

String? getSize(String distroName) {
  String ext4Path = getInstancePath(distroName).file('ext4.vhdx');
  // Get size of distro
  try {
    File file = File(ext4Path);
    int byteSize = file.lengthSync();
    if (byteSize == 0) {
      return null;
    }
    double size = byteSize / 1024 / 1024 / 1024; // Convert to GB
    return '${'size-text'.i18n()}: ${size.toStringAsFixed(2)} GB';
  } catch (error, stack) {
    logDebug(error, stack, null);
    return null;
  }
}