Your experience on this site will be improved by allowing cookies
In this article, we will explore the process of deleting data on the internet. To, do so we need to follow 3 crucial steps:
Now, we will explore them in detail.
To install the http package use the below command in your command prompt:
pub get
or, if you are using the flutter cmd use the below command:
flutter pub get
After the installation add the dependency to the pubsec.yml file as shown below:
Now import the http package in the main.dart file as shown below:
import 'package:http/http.dart' as http;
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:
|
Complete Source Code:
|
Output:
0 comments