Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

get file size flutter

import 'dart:io';

//Here's the method to get file size:

double getFileSize(File file){      
	int sizeInBytes = file.lengthSync();
	double sizeInMb = sizeInBytes / (1024 * 1024);
    return sizeInMb;
}

//Alternatively for extension:

extension FileUtils on File {
	get size {
    	int sizeInBytes = this.lengthSync();
		double sizeInMb = sizeInBytes / (1024 * 1024);
    	return sizeInMb;
    }
}
 
PREVIOUS NEXT
Tagged: #file #size #flutter
ADD COMMENT
Topic
Name
4+1 =