Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Synchronous and asynchronous file operation in Flutter

On working with Files and directory in my Flutter application, i come through asynchronous and synchronous methods such as createSync() and create or list() and listSync() but i can't understand the main difference between them and scenarios where i can use one of two different version of same function.

The flutter document says:-

Most methods in this class occur in synchronous and asynchronous pairs, for example, create and 
createSync. Unless you have a specific reason for using the synchronous version of a method, prefer 
the asynchronous version to avoid blocking your program.
like image 512
Avnish Nishad Avatar asked Oct 15 '25 04:10

Avnish Nishad


1 Answers

Dart and Flutter has great support for Asynchronous Operations. Check out the explanation below: It helps.

Key terms:

1)Synchronous operation: A synchronous operation blocks other operations from executing until it completes.

2)synchronous function: A synchronous function only performs synchronous operations.

3)Asynchronous operation: Once initiated, an asynchronous operation allows other operations to execute before it completes.

4)Asynchronous function: An asynchronous function performs at least one asynchronous operation and can also perform synchronous operations.

Why use Asynchrnous operations and functions ?

Asynchronous operations let your program complete work while waiting for another operation to finish. Here are some common asynchronous operations:

Fetching data over a network.

Writing to a database.

Reading data from a file.

To perform asynchronous operations in Dart, you can use the Future class and the async and await keywords.

For more detailed explanation. Try the link below, it leads to the official documentation:

Documentation

like image 155
V.N Avatar answered Oct 16 '25 21:10

V.N