Skip to main content

avoid-nested-streams-and-futures

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* {
...
}

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

✅ Good:

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

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