readableFileSize method
- String size
Implementation
String readableFileSize(String size) {
final int bytes = int.parse(size);
if (bytes < 1024) {
return "$bytes B";
} else if (bytes < 1024 * 1024) {
return "${(bytes / 1024).toStringAsFixed(2)} KB";
} else if (bytes < 1024 * 1024 * 1024) {
return "${(bytes / 1024 / 1024).toStringAsFixed(2)} MB";
} else {
return "${(bytes / 1024 / 1024 / 1024).toStringAsFixed(2)} GB";
}
}