2

A previous question on stack overflow discussed obtaining an image's size to which someone posted an answer

    Future<ui.Image> _getImage() {
        Completer<ui.Image> completer = new Completer<ui.Image>();
        new NetworkImage('https://i.stack.imgur.com/lkd0a.png')
          .resolve(new ImageConfiguration())
          .addListener((ImageInfo info, bool _) => completer.complete(info.image));
        return completer.future;
  }

Unfortunately the above code will not compile due to complete.complete(info.image) having an error in Android Studio which says:

the argument type 'image' can't be assigned to the parameter type 'FutureOr'

Could someone suggest how to correct the code so that the Completer object will work properly?

I would ask the original poster of the accepted answer but I don't have enough reputation to comment yet. So I am asking the question here.

The link to the original post is here:

How do I determine the width and height of an image in Flutter?

E.Bradford
  • 783
  • 7
  • 21

1 Answers1

1

It means that the types do not match up.

Looking at your code, it should work since ImageInfo.image should return ui.Image.

First of all, you can omit the type in the constructor, like this:

Completer<Image> completer = Completer();

If you are still having issues, it would be helpful to see more of the stack trace.

creativecreatorormaybenot
  • 114,516
  • 58
  • 291
  • 402