Câu hỏi phỏng vấn Flutter
Câu hỏi

What is Future ...

Câu trả lời

A Future in Flutter/Dart represents an asynchronous operation that will complete at some point in the future and return a value[1][2]. It is commonly used for operations that may take some time to complete, such as fetching data from an API, reading from a file, or performing a computation[1][2].

To use a Future, you typically define it as the return type of an asynchronous function and use the async and await keywords[1][2][3]. The async keyword marks a function as asynchronous, allowing it to use await to wait for the Future to complete[1][2][3]. The await keyword is used inside an async function to pause the execution of the function until the Future completes and returns its value[1][2][3].

Here's an example of using a Future to fetch data from an API[1]:

dart Copy
Future<String> fetchData() async {
  final response = await http.get(Uri.parse('https://example.com/api/data'));
  return response.body;
}

In this example, the fetchData function returns a Future<String>. Inside the fu...

senior

senior

Gợi ý câu hỏi phỏng vấn

middle

Why is the build() method on State and not Stateful Widget?

senior

How do you convert a List into a Map in Dart?

middle

What are keys in Flutter and when to use it?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào