Skip to content
RED SAG Skills
hardStudy question · answer published in Flutter interview questions, so no pointscross-platform-mobiledartdart-async

Turning a callback API into a Future

An old SDK reports results through onSuccess and onError callbacks. What does this Dart code use to expose it as a Future?

Future<String> scan() {
  final c = Completer<String>();
  sdk.scan(onSuccess: c.complete, onError: c.completeError);
  return c.future;
}
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions