Image 检查颤振中的图像大小(kb,mb…)?

Image 检查颤振中的图像大小(kb,mb…)?,image,flutter,dart,Image,Flutter,Dart,我知道如何检查图像宽度和高度: 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) 但我想检查图像大小

我知道如何检查图像宽度和高度:

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)

但我想检查图像大小,如100kb、200kb或类似的大小。请帮助我。

使用
lengthInBytes

final bytes = image.readAsBytesSync().lengthInBytes;
final kb = bytes / 1024;
final mb = kb / 1024;
如果要
异步等待
,请使用

final bytes = (await image.readAsBytes()).lengthInBytes;
var file = File('the_path_to_the_image.jpg');
print(file.lengthSync());