Contents
Contents

Future results in async function bodies must be awaited or marked unawaited using dart:async.

This rule is available as of Dart 2.0.0.

This rule has a quick fix available.

Details

#

DO await functions that return a Future inside of an async function body.

It's easy to forget await in async methods as naming conventions usually don't tell us if a method is sync or async (except for some in dart:io).

When you really do want to start a fire-and-forget Future, the recommended way is to use unawaited from dart:async. The // ignore and // ignore_for_file comments also work.

BAD:

dart
void main() async {
  doSomething(); // Likely a bug.
}

GOOD:

dart
Future doSomething() => ...;

void main() async {
  await doSomething();

  unawaited(doSomething()); // Explicitly-ignored fire-and-forget.
}

Usage

#

To enable the unawaited_futures rule, add unawaited_futures under linter > rules in your analysis_options.yaml file:

analysis_options.yaml
yaml
linter:
  rules:
    - unawaited_futures