toStringWithByteSuffix method

String toStringWithByteSuffix()

Implementation

String toStringWithByteSuffix() {
  if (this == null) return '0 B';

  if (value < 1024) return '$value B';
  if (value < 1024 * 1024) return '${(value / 1024).toStringAsFixed(1)} kB';
  if (value < 1024 * 1024 * 1024)
    return '${(value / (1024 * 1024)).toStringAsFixed(1)} MB';

  return '${(value / (1024 * 1024 * 1024)).toStringAsFixed(1)} GB';
}