Future

  • Steps

    let's write up a simple function that gets data from the internet and returns this value as a String.

    The line of code that gets the data will operate for a few seconds before it returns the result. This will cause the app to block until the work is complete.

    Futures

    If a function takes a long time to complete, then it is preferred to use Futures.

    A Future can execute operations without blocking. Once the data is ready, a callback will be executed with the data ready to be used.

    Let's use the http library as an example to get data from the internet. The http package has an API to make a GET request, which returns a Future of data type Response.

    
    
    Future<void> login(String email, String password) async {
    
    }