W11 - Asynchronous Programming
W11 - Asynchronous Programming
Week 12
Chapter 7
These lecture slides have been prepared using the content available on the official websites of
Dart, Flutter, and other online resources.
Chapter 7 of the textbook titled, “Flutter Cookbook Over 100 proven techniques and solutions for
app development with Flutter 2.2 and Dart” by Harrington
Two video tutorials shared by the official channel of Flutter on Youtube:
https://www.youtube.com/watch?v=OTS-ap9_aXc
https://www.youtube.com/watch?v=SmTCmDMi4BY
All the copyrights are reserved with the original content creators.
2
Outline
3
Asynchronous Programming - Future
Gift box
When closed => uncompleted
When opened i.e. completed , you get either
A value, or
An error
4
Asynchronous Programming - Future
5
Future
6
Future
7
How to get an Instance of a Future
8
Future - Methods
9
Future
10
then may return a Future of its Own
11
What if Future Completes with an Error?
12
whenComplete() Method
13
FutureBuilder
14
FutureBuilder
Advantage:
Handling when
Future completes
with an error
16
FutureBuilder
17
FutureBuilder
Handling uncompleted
Future.
18
Asynchronous Programming with
Async and Await
19
Example
Asynchronous Operations:
How?
20
Option 1: Implementation using Future
We want to write a single method that put these pieces together.
21
Option 2: Async and Await
The good thing with Async and Await
Code looks like synchronous code, and
Uses Futures
22
Comparison: Futures API vs Async and Await
23
Comparison: Futures API vs Async and Await
24
Comparison: Futures API vs Async and Await
25
Error Handling with Async and Await
26
Let us See a Few Examples
Reference: Chapter 7 of the book
27
Using a Future
28
Using Async and Await to Remove Callbacks
29