loadForm method
Fills the form: empty for item == null, otherwise with the full dorm (photos and admins included).
Implementation
Future<void> loadForm(UDormResponse? item) async {
final UDormResponse? h = item == null
? null
: (await UServices.hotel.readDormById(
p: UIdParams(
id: item.id,
selectorArgs: const UDormSelectorArgs(media: UMediaSelectorArgs()),
),
)).$1?.result ??
item;
final UDormJson? d = h?.jsonData;
editing = h;
titleController.text = h?.title ?? "";
descriptionController.text = d?.description ?? "";
addressController.text = h?.address ?? "";
phoneController.text = h?.phoneNumber ?? "";
nearbyUniversityController.text = d?.nearbyUniversity ?? "";
universityWalkMinutesController.text = d?.universityWalkMinutes?.toString() ?? "";
visitingHoursController.text = d?.visitingHours ?? "";
curfewTimeController.text = d?.curfewTime ?? "";
minimumStayMonthsController.text = d?.minimumStayMonths?.toString() ?? "";
policiesController.text = d?.policies ?? "";
rulesController.text = d?.rules.join("، ") ?? "";
requiredDocumentsController.text = d?.requiredDocuments.join("، ") ?? "";
latitudeController.text = d?.latitude?.toString() ?? "";
longitudeController.text = d?.longitude?.toString() ?? "";
websiteController.text = d?.website ?? "";
whatsappController.text = d?.whatsapp ?? "";
instagramController.text = d?.instagram ?? "";
telegramController.text = d?.telegram ?? "";
howToGetThereController.text = d?.howToGetThere ?? "";
cityCode = h?.cityCode ?? UCountries.iran().provinces.first.cities.firstOrNull?.code ?? "";
tags = List<int>.from(h?.tags ?? <int>[TagDorm.girls.number, TagDorm.active.number]);
highlights = List<String>.from(d?.highlights ?? <String>[]);
nearby = List<UPlaceNearby>.from(d?.nearby ?? <UPlaceNearby>[]);
faqs = List<UPlaceFaq>.from(d?.faqs ?? <UPlaceFaq>[]);
media = (h?.media ?? <UMediaResponse>[]).sortedForGallery();
photos.dispose();
photos = UFilePickerController.fromMedia(media);
admins = await readUsersById(h?.adminUserIds ?? <String>[]);
}