To perform a DELETE action on a web service, follow these steps:
- Log into the Mock Lab service at https://app.mocklab.io/ and click on the Stubs section of the example API. Then, create a new Stub.
- Complete the request, as follows:
- Name: Delete Pizza
- Verb: DELETE
- Address: /pizza
- Status: 200
- Body: {"message": "Pizza was deleted"}:
- In the Flutter project, add a deletePizza method to the HttpHelper class in the http_helper.dart file:
Future<String> deletePizza(int id) async {
Uri url = Uri.https(authority, deletePath);
http.Response r = await http.delete(
url,
);
return r.body;
}
- In the main.dart file, in the build method of the _MyHomePageState class, refactor itemBuilder of ListView.builder so that ListTile is contained in a Dismissible widget, as follows:
return ListView.builder(
itemCount: (pizzas.data == null) ? 0 : pizzas.data.length,
itemBuilder: (BuildContext context, int position) {
return Dismissible...