Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

flutter file size

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;
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #flutter #file #size
ADD COMMENT
Topic
Name
7+7 =