save method
Creates or updates the dorm, then saves its photos. Returns true when the dialog can close.
Implementation
Future<bool> save() async {
final bool isNew = editing == null;
// On edit an empty text is sent as "" so a field can be cleared; on create it is simply left out.
String? t(TextEditingController c) => isNew ? c.text.trim().nullIfEmpty() : c.text.trim();
final UDormUpdateParams p = UDormUpdateParams(
id: editing?.id ?? "",
tags: tags,
title: titleController.text.trim(),
cityCode: cityCode,
address: t(addressController),
phoneNumber: phoneController.text.nullIfEmpty(),
description: t(descriptionController),
nearbyUniversity: t(nearbyUniversityController),
universityWalkMinutes: intOf(universityWalkMinutesController),
visitingHours: t(visitingHoursController),
curfewTime: t(curfewTimeController),
minimumStayMonths: intOf(minimumStayMonthsController),
policies: t(policiesController),
rules: splitList(rulesController.text),
requiredDocuments: splitList(requiredDocumentsController.text),
latitude: numOf(latitudeController),
longitude: numOf(longitudeController),
adminUserIds: admins.map((UUserResponse u) => u.id).toList(),
highlights: highlights,
website: t(websiteController),
whatsapp: t(whatsappController),
instagram: t(instagramController),
telegram: t(telegramController),
howToGetThere: t(howToGetThereController),
nearby: nearby,
faqs: faqs,
);
final Object? ok = await send(
isNew ? UServices.hotel.createDorm(p: UDormCreateParams.fromMap(p.toMap()..remove("id"))) : UServices.hotel.updateDorm(p: p),
() {},
);
if (ok == null) return false;
await UServices.media.syncGallery(photos, existing: media, dormId: editing?.id ?? (ok as UResponse<String>).result);
unawaited(read());
return true;
}