getFileSize method

Future<String> getFileSize(
  1. String filepath
)

Implementation

Future<String> getFileSize(String filepath) async {
  var file = File(filepath);
  int bytes = await file.length();
  if (bytes <= 0) return "0 B";
  const suffixes = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
  var i = (log(bytes) / log(1024)).floor();
  return ('${(bytes / pow(1024, i)).toStringAsFixed(2)} ${suffixes[i]}')
      .toString();
}