save method
Creates or updates the bed, then saves its photos. Returns true when the dialog can close.
Implementation
Future<bool> save() async {
final String? roomId = formRoom?.id ?? editing?.roomId;
if (roomId == null) {
UToast.error(message: U.s.pleaseSelectAItem(U.s.room));
return false;
}
final UDormBedUpdateParams p = UDormBedUpdateParams(
id: editing?.id ?? "",
tags: tags,
title: titleController.text.trim(),
deposit: numOf(depositController),
monthlyRent: numOf(rentController),
roomId: roomId,
description: descriptionController.text.nullIfEmpty(),
);
final Object? ok = await send(
editing == null ? UServices.hotel.createDormBed(p: UDormBedCreateParams.fromMap(p.toMap()..remove("id"))) : UServices.hotel.updateDormBed(p: p),
() {},
);
if (ok == null) return false;
await UServices.media.syncGallery(photos, existing: media, dormBedId: editing?.id ?? (ok as UResponse<String>).result);
unawaited(read());
return true;
}