getNextFrame method Null safety

Future<FrameInfo> getNextFrame()

Fetches the next animation frame.

Wraps back to the first frame after returning the last frame.

The returned future can complete with an error if the decoding has failed.

The caller of this method is responsible for disposing the FrameInfo.image on the returned object.


Future<FrameInfo> getNextFrame() async {
  final Completer<FrameInfo> completer = Completer<FrameInfo>.sync();
  final String? error = _getNextFrame((_Image? image, int durationMilliseconds) {
    if (image == null) {
      completer.completeError(Exception('Codec failed to produce an image, possibly due to invalid image data.'));
    } else {
        image: Image._(image, image.width, image.height),
        duration: Duration(milliseconds: durationMilliseconds),
  if (error != null) {
    throw Exception(error);
  return completer.future;