Completer in Dart/Flutter

A way to generate and handle your own Future

flying high
Photo by Ralph Mayhew on Unsplash

What is Completer?

When to use Completer?

  • New asynchronous primitive which means you can use it with Timer, scheduleMicrotask, and Zone.
  • Asynchronous code that doesn’t use futures

Another case to use Completer

  • Callback-based API or Database query
    When their return is not a Future, instead of passing the callback using Future value, you can just use the Completer.
  • Complex async codes
    Don’t use Completer for a simple case, in a way that you can just simply return a Future.

Examples

Completer with Timer example
Completer with database query example

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jessica Jimantoro

Software Engineer & Flutter Developer 👩‍💻, Amateur anime-style sculptor 🧸, Tarot Reader 🔮