update method

Future<void> update({
  1. String? label,
  2. String? avatar,
})

Updates multiple properties of this in a single request.

When you need to update more than 2 fields, we advise you to use this method to reduce the number of outgoing requests.

Example :

await webhook.update(label: 'My webhook name', avatar: 'assets/images/my_picture.png');

Implementation

Future<void> update ({ String? label, String? avatar }) async {
  String? path = avatar != null
    ?  await Helper.getPicture(avatar)
    : this.label;

  Response response = await ioc.use<HttpService>().patch(url: "/webhooks/$id", payload: {
    'label': label ?? this.label,
    'avatar': path,
  });

  if (response.statusCode == 200) {
    if (label != null) _label = label;
    if (avatar != null) _avatar = path;
  }
}