September 2019
Beginner
512 pages
12h 52m
English
The Future<T> object in Dart represents a value that will be provided sometime in the future. It can be used to mark a method, for example, with a future result; that is, a method returning a Future<T> object will not have the proper result value immediately, but instead after some computation at a later point in time.
Consider the following code, where we have the main function that calls a long-running operation:
import 'dart:io';void longRunningOperation() { for (int i = 0; i < 5; i++) { sleep(Duration(seconds: 1)); print("index: $i"); }}main() { print("start of long running operation"); longRunningOperation(); print("continuing main body"); for (int i = 10; i < 15; i++) { sleep(Duration(seconds: 1)); print("index from main: ...Read now
Unlock full access