stringified_async_value
Reports a future or a stream turned into text, which reads “Instance of ‘Future<int>’” instead of the value. Await the future, or build from the stream.
- Tier
- advisory
- Scope
- Dart
- Lowest preset
- recommended
- Fix
- none
What it reports
Section titled “What it reports”A future or a stream turned into text:
- a stream interpolated into a string:
'Counts: $counts'; toString()called on a future or a stream:load().toString();- a future interpolated outside a function body, in the initializer of a field or of a top-level variable.
A nullable future or stream counts, and so does a subtype of either. A dynamic or FutureOr value does not. The violation covers the interpolated value or the call.
A future interpolated inside a function body is left to the SDK lints for unawaited and discarded futures. The presets switch them on, and they report it there.
The text compiles and shows up as a label, a log line or a key that reads “Instance of ‘Future<String>’”. It is a missing await that no type error catches, since everything has a toString.
Example
Section titled “Example”Text('Total: ${totals.stream}')StreamBuilder<int>( stream: totals.stream, builder: (context, snapshot) => Text('Total: ${snapshot.data ?? 0}'),)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 log shows the kind of the stream on purpose.// ignore: assay/stringified_async_valuefinal shown = '$counts';// ignore_for_file: assay/stringified_async_value silences it in a whole file, and // ignore: stringified_async_value without the prefix works too. See Suppressions.