Remember these two basic guidelines when using async and await:
To define an async function, add async before the function body
The await keyword works only in async functions.
An async function runs synchronously until the first await keyword. This means that within an async function
body, all synchronous code before the first await keyword executes immediately.
Consider an example:
import 'dart:async';
class Employee { int id; String firstName; String lastName;
Employee(this.id, this.firstName, this.lastName); }
void main() async { print("getting employee..."); var x = await getEmployee(33); print("Got back
{x.lastName} with id# ${x.id}"); }
Future getEmployee(int id) async { //Simluate what a real service call delay may look like by delaying 2 seconds
await Future.delayed(const Duration(seconds: 2)); //and then return an employee - lets pretend we grabbed this
out of a database var e = new Employee(id, "Joe", "Coder"); return e; }
Q22: How does Dart AOT work?
GET START
Senior Top 68 Flutter Interview Questions Flutter 68
Answer
Dart source code will be translated into assembly files, then assembly files will
be compiled into binary code for different architectures by the assembler.
For mobile applications the source code is compiled for multiple processors ARM, AR
M64, x64 and for both platforms - Android and iOS. This means there are multiple re
sulting binary files for each supported processor and platform combination.
x
.firstName
Q23: What are the similarities and differences of Future and Stream?
GET START
Senior Top 68 Flutter Interview Questions Flutter 68
Do'stlaringiz bilan baham: |