Lesson4 - Asynchronous in Dart
Lesson4 - Asynchronous in Dart
PROGRAMMING
FLUTTER
• Dart is a single-threaded language, meaning it
executes code sequentially. However, to keep
applications responsive (especially Flutter apps), we
use asynchronous programming to handle tasks
ASYNCHRONOUS
like:
• Fetching data from a server
PROGRAMMING
• Reading files
• Waiting for user input
FUTURES IN DART
• A Future represents a value that might not be available yet but will be in the future.
Future.delayed(Duration(seconds: 2), ()
=> "Data loaded") → This simulates a
delayed operation (e.g., fetching data
from a network or database).
Future.delayed(Duration(seconds: 1)) → Simulates asynchronous delay before emitting the next value.
.listen((value) {...}) → Subscribes to the stream and receives each emitted value.
HANDLING STREAM ERRORS
RYAN FERMO