Skip to main content

avoid-stream-tostring

effort: 2m
teams+

Warns when a Stream is the target of the toString() invocation or is used in an interpolation.

The result of calling toString() on a Stream is Instance of '_ControllerStream<List<String>>' and is usually not expected.

Example

❌ Bad:

void fn() {
final myStream = Stream.value([1, 2, 3]);

// LINT: Avoid calling 'toString' on 'Stream'.
print(myStream.toString());

// LINT: Avoid calling 'toString' on 'Stream'.
print('hello $myStream');
}

✅ Good:

void fn() {
final myStream = Stream.value([1, 2, 3]);

myStream.listen((value) => print(value));
}

Additional Resources