![]() |
VOOZH | about |
In this article, we will explore the process of deleting data on the internet. Before deleting data on the internet, we will fetch the data first and then will delete the data.
Create a new Flutter application using the command Prompt. To create a new app, write the below command and run it.
flutter create app_nameTo know more about it refer this article: Creating a Simple Application in Flutter
To add the dependency to the pubspec.yaml file, add http as a dependency in the dependencies part of the pubspec.yaml file, as shown below:
Now run the below command in the terminal.
flutter pub getUse the below line of code in the main.dart file, to import the shimmer dependency :
import 'package:http/http.dart' as http;-
Before deleting data on the internet, we need to fetch data from internet
so, follow this article to know more about fetching data from the internet : Flutter - Fetching Data From the Internet
-
Now use the http.delete() method on the JSONPlaceHolder, to delete the Album with id=1 with as shown below:
-
Here we will create a delete data button that can verify if a data has been deleted from the server by calling the http.get() method as shown below:
Now, when you click on the Delete Data button, the deleteAlbum() method is called and the id you are passing is the id of the data that you retrieved from the internet. This means you are going to delete the same data that you fetched from the internet.
-
After the data is deleted we will be needing to send a success or failure response. To do so look at the below response implementation:
Output: