How to use animationFrame in Dart?

Issue

The following code throws the exception "type '([int]) => void' is not a subtype of type 'RequestAnimationFrameCallback' of 'callback'."

import 'dart:html';

void main() {
  window.animationFrame.then((time) => print("test"));
}

If I change window.animationFrame.then to window.requestAnimationFrame, everything works as expected. Am I misunderstanding how Dart futures work?

Solution

Usage looks right.

Either you are running an older version that doesn’t yet implement the behavior that is specified in the documentation or it is simply a bug. I would go ahead and file an issue on http://dartbug.com/new

Answered By – Florian Loitsch

Answer Checked By – Candace Johnson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *