videoSizeHelper static method

String videoSizeHelper(
  1. String path
)

Implementation

static String videoSizeHelper(String path) {
  // Get the video file size
  int size = File(path).lengthSync();

  // Define a list of size notations (e.g., bytes, KB, MB, GB)
  List<String> sizeNotations = ['bytes', 'KB', 'MB', 'GB'];

  // Initialize loop counter
  int i = 0;

  // Convert size to human-readable format by dividing by 1024
  // until it is less than 1024 and incrementing the size notation index
  while (size > 1024) {
    size = size ~/ 1024;
    i++;
  }

  // Format the final size string with the appropriate notation
  return "$size ${sizeNotations[i]}";
}