Check image size( kb, mb…) in flutter?

Issue

I know how to check image width and height:

import 'dart:io';

File image = new File('image.png'); // Or any other way to get a File instance.
var decodedImage = await decodeImageFromList(image.readAsBytesSync());
print(decodedImage.width);
print(decodedImage.height)

But I want to check the image size like 100kb, 200kb, or something like that is there any way, please help me.

Solution

Use lengthInBytes.

final bytes = image.readAsBytesSync().lengthInBytes;
final kb = bytes / 1024;
final mb = kb / 1024;

If you want to async-await, use

final bytes = (await image.readAsBytes()).lengthInBytes;

Answered By – iDecode

Answer Checked By – Robin (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.