Delynith
Delynith

Reputation: 114

_Callback<>, _toByteData() and _futurize() not defined

I'm having this issue in Flutter:

Error: The method '_futurize' isn't defined for the class '_MainPage'.

Error: The method '_toByteData' isn't defined for the class '_MainPage'

Error: '_Callback' isn't a type.

This is in the function mentioned at https://api.flutter.dev/flutter/dart-ui/Image/toByteData.html, which is used to obtain the binary value of an image.

Actual code is:

Future<ByteData?> toByteData({ImageByteFormat format = ImageByteFormat.rawRgba}) {
  return _futurize((_Callback<ByteData> callback) {
    return _toByteData(format.index, (Uint8List? encoded) {
      callback(encoded!.buffer.asByteData());
    });
  });
}

Upvotes: 0

Views: 658

Answers (1)

Stefano Amorelli
Stefano Amorelli

Reputation: 4854

The code you've cited represents how the code has been implemented.

For that reason, the _futurize and _toByteData methods are private to the Image class and can't be accessed from the outside, hence the errors.

If you'd like to use the toByteData() function, you could simply use a code like the following:

ByteData byteData = await image.toByteData();

Upvotes: 1

Related Questions