Skip to main content

avoid-future-tostring

added in: 1.6.0

Warns when a Future is the target of the toString method or is used in an interpolation.

Example

❌ Bad:

void main() {
final myFuture = Future.value(1);

print(myFuture.toString()); // LINT
print('hello $myFuture'); // LINT
}

✅ Good:

Future<void> withAwait() async {
final myFuture = Future.value(1);

print((await myFuture).toString());
print('hello ${(await myFuture)}');
}