getImageDimension method

Future<Map<String, dynamic>> getImageDimension(
  1. ImageProvider<Object>? image, {
  2. String? requiredWidth,
  3. String? requiredHeight,
})

IMAGE DIMENSION USAGE

FlutterUtilities().getImageDimension(Image.asset('assets/image.png'),
 requiredWidth : "520", requiredHeight : "200").then((value){
  print(value);
});
[getImage] method

Implementation

/*
 * Generate the width and height dimension from any image
 * (Assets) (Network) (File) (Memory)
 */
///USAGE
/// ```dart
/// FlutterUtilities().getImageDimension(Image.asset('assets/image.png'),
///  requiredWidth : "520", requiredHeight : "200").then((value){
///   print(value);
/// });
/// [getImage] method
Future<Map<String, dynamic>> getImageDimension(ImageProvider? image,
    {String? requiredWidth, String? requiredHeight}) async {
  Completer<ui.Image> completer = Completer<ui.Image>();
  image!
      .resolve(const ImageConfiguration())
      .addListener(ImageStreamListener((ImageInfo image, bool _) {
    completer.complete(image.image);
  }));
  ui.Image info = await completer.future;

  String width = info.width.toString();
  String height = info.height.toString();

  if (width == requiredWidth && height == requiredHeight) {
    ///Required Dimension
    final body = {
      'message': 'Image Dimension is $width x $height',
      'status': true
    };
    return body;
  } else {
    final body = {
      'message': 'Image Dimension is $width x $height',
      'status': false
    };
    return body;
  }
}