Skip to main content

avoid-nested-streams-and-futures

added in: 1.7.0
Pro+

Warns when a Stream type contains a Future or vice versa.

Usually, nested Streams and Futures highlight a problem in code design. Consider rewriting the code instead of nesting Streams and Futures.

Example

❌ Bad:

// LINT: Avoid nested 'Streams' and 'Futures'. Try rewriting the code to remove nesting.
Stream<Future<int>> function() async* {
...
}

Future<Stream<int>> function() async => ...; // LINT: Avoid nested 'Streams' and 'Futures'. Try rewriting the code to remove nesting.

✅ Good:

Stream<int> function() async* {
...
}

Future<int> function() async => ...;