Dart Future toString()
Syntax & Examples
Future.toString() method
The `toString` method in Dart returns a string representation of this object.
Syntax of Future.toString()
The syntax of Future.toString() method is:
String toString()
This toString() method of Future returns a string representation of this object.
Return Type
Future.toString() returns value of type String
.
✐ Example
1 Converting a Future object to a string
In this example,
- We create a Future object
future
containing the value 42. - We use the
toString()
method to obtain its string representation. - We then print the string representation to standard output.
Dart Program
void main() {
Future<int> future = Future<int>.value(42);
String futureString = future.toString();
print('String representation of Future object: $futureString');
}
Output
String representation of Future object: Instance of 'Future<int>'
Summary
In this Dart tutorial, we learned about toString() method of Future: the syntax and few working examples with output and detailed explanation for each example.