calculateMaxSizeToReadableFormat method

String calculateMaxSizeToReadableFormat(
  1. double maxSize
)

Calculate the maximum size to a readable format The maxSize is the maximum size in bytes

Implementation

String calculateMaxSizeToReadableFormat(double maxSize) {
  double size = maxSize;
  if (size < 1024) {
    return "${size}b";
  }
  if (size < 1024 * 1024) {
    return "${(size / 1024).toStringAsFixed(2)}kb";
  }
  if (size < 1024 * 1024 * 1024) {
    return "${(size / 1024 / 1024).toStringAsFixed(2)}mb";
  }
  return "${(size / 1024 / 1024 / 1024).toStringAsFixed(2)}gb";
}