getSize method Null safety

String? getSize(
  1. String distroName
)

Get distro size

Implementation

String? getSize(String distroName) {
  String? distroLocation = prefs.getString('Path_$distroName');
  if (distroLocation == null) {
    return null;
  }
  distroLocation += '\\ext4.vhdx';
  distroLocation = distroLocation.replaceAll('/', '\\');
  // Get size of distro
  try {
    File file = File(distroLocation);
    int byteSize = file.lengthSync();
    if (byteSize == 0) {
      file = File(defaultPath + distroLocation);
      byteSize = file.lengthSync();
    }
    double size = byteSize / 1024 / 1024 / 1024; // Convert to GB
    return '${'size-text'.i18n()}: ${size.toStringAsFixed(2)} GB';
  } catch (e) {
    return null;
  }
}