To perform a PUT 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: Put Pizza
- Verb: PUT
- Address: /pizza
- Status: 200
- Body: {"message": "Pizza was updated"}:
- In the Flutter project, add a putPizza method to the HttpHelper class in the http_helper.dart file:
Future<String> putPizza(Pizza pizza) async {
String put = json.encode(pizza.toJson());
Uri url = Uri.https(authority, putPath);
http.Response r = await http.put(
url,
body: put,
);
return r.body;
}
- In the PizzaDetail class in the pizza_detail.dart file, add two properties, a Pizza and a boolean, and a constructor that sets the two properties:
final Pizza pizza;
final bool isNew;
PizzaDetail(this.pizza, this.isNew);
- In the PizzaDetailState class, override the initState method. When the...