formatSize static method

String formatSize(
  1. int sizeInBytes
)

Implementation

static String formatSize(int sizeInBytes) {
  final double kb = sizeInBytes / 1024.0;
  final double mb = kb / 1024.0;
  final double gb = mb / 1024.0;

  if (gb >= 1) {
    return '${gb.toStringAsFixed(2)} GB';
  } else if (mb >= 1) {
    return '${mb.toStringAsFixed(2)} MB';
  } else if (kb >= 1) {
    return '${kb.toStringAsFixed(2)} KB';
  } else {
    return '$sizeInBytes bytes';
  }
}