xxxxxxxxxx
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;
}
}
xxxxxxxxxx
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;
}
}
xxxxxxxxxx
Future<int> getFileSize(String filePath) async {
try {
final file = File(filePath);
final fileStat = await file.stat();
return fileStat.size;
} catch (e) {
print('Error: $e');
return -1;
}
}