nested_future
Reports a written type of a future of a future, such as Future<Future<int>>. Return or await the inner future instead.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- strict
- Fix
- none
What it reports
Section titled “What it reports”A Future<Future<…>>, or a FutureOr of a Future, nullable or not, wherever a type is written: a return type, a parameter, a variable or a type argument. A type nested deeper is reported once, at the outermost future. A type alias that hides the nesting is reported only where its target is written as a future.
It does not report:
- an inferred type;
- a future of another type that holds futures, such as
Future<List<Future<int>>>; - a stream of futures.
One await gives the inner future, not its value. A caller that awaits once believes the work is done when it has only started, and no one catches the inner future’s failure.
Example
Section titled “Example”Future<Future<User>> start() async => api.fetchUser();Future<User> start() => api.fetchUser();Rule parameters
Section titled “Rule parameters”Set under the assay: key of the project’s root analysis_options.yaml.
| Rule parameter | Default | Effect |
|---|---|---|
enabled |
true |
false switches the rule off for the whole project. |
exclude |
[] |
Path globs where the rule is silent. |
Suppressing it
Section titled “Suppressing it”Write why on the line directly above the suppression:
// The scheduler gives the job, which starts when it is awaited.// ignore: nested_futureFuture<Future<int>>? job;// ignore_for_file: assay/nested_future silences it in a whole file, and the prefixed // ignore: assay/nested_future works too. See Suppressions.