formatSize static method
格式化大小
Implementation
static String formatSize(dynamic size) {
if (size == null || size == '' || size == 0) {
return '0KB';
}
const unitArr = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
int index;
var $size = safeDouble(size);
index = (math.log($size) / math.log(1024)).floor();
return '${($size / math.pow(1024, index)).toStringAsFixed(2)}${unitArr[index]}';
}