0

Im trying to resize an image from a URL using the image package from Dart. I keep on getting what seems to be a conflict and I can't figure out how to resolve it to resize the image. Any help is greatly appreciated.

Warning:

The argument type 'image' (where image is defined in .../ui/painting.dart) cant be assigned to the parameter type 'Image' (where image is defined in .... /src/image.dart)

import 'dart:io';
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter/services.dart';
import 'package:esys_flutter_share/esys_flutter_share.dart'; 
import 'package:image/image.dart' as newimage;    

_resizeImage() async{
    var uri = Uri.parse([IMAGE_URL]);
    var httpClient = HttpClient();
    var request = await httpClient.getUrl(uri);
    var response = await request.close();
    var imageData = <int>[];
    await response.forEach((data) async {
      imageData.addAll(data);
    });
    print(imageData.length);
    ui.Image myimage =
        await decodeImageFromList(Uint8List.fromList(imageData));


    //TRYING TO RESIZE IMAGE WHERE CONFLICT OCCURS ON myimage
    newimage.Image thumbnail = newimage.copyResize(myimage, width: 500, height: 500);


}
kelsheikh
  • 1,278
  • 3
  • 17
  • 37

1 Answers1

0

That's because the function copyResize only accepts type Image that's defined in the Image flutter package. You're passing a different completely type to it.

Also, decodeImageFromList returns nothing, and requires a second positional parameter which is a callback that receives the Image

  ui.decodeImageFromList(Uint8List.fromList(imageData), (ui.Image s) {});

You can check this answer which explains the same thing you're trying to do

Sayegh
  • 1,381
  • 9
  • 17