formatSize static method

String formatSize(
  1. double value
)

Implementation

static String formatSize(double value) {
  if (null == value) {
    return '0';
  }
  List<String> unitArr = []..add('B')..add('K')..add('M')..add('G');
  int index = 0;
  while (value > 1024) {
    index++;
    value = value / 1024;
  }
  String size = value.toStringAsFixed(2);
  return size + unitArr[index];
}