calculateSize static method
Implementation
static String calculateSize(double limit) {
var size = '';
if (limit < 0.1 * 1024) {
size = limit.toStringAsFixed(2) + ' B';
} else if (limit < 0.1 * 1024 * 1024) {
size = (limit / 1024).toStringAsFixed(2) + ' KB';
} else if (limit < 0.1 * 1024 * 1024 * 1024) {
size = (limit / (1024 * 1024)).toStringAsFixed(2) + ' MB';
} else {
size = (limit / (1024 * 1024 * 1024)).toStringAsFixed(2) + ' GB';
}
var sizeStr = size + '';
var index = sizeStr.indexOf('.');
String dou = sizeStr.substring(index + 1, index + 1 + 2);
if (dou == '00') {
return sizeStr.substring(0, index) +
sizeStr.substring(index + 3, index + 3 + 2);
}
return size;
}