6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit b573c1b0

AuthorEdmir Suljic<esu@dwarf.dk>
Date2025-04-15 12:45:29 +0200
Updated booking object to Iterable of Guest instead of List of Guest

Changed files

.../lib/booking_details/components/share_button.dart   |  5 ++---
 comwell_key_app/lib/overview/models/booking.dart       | 18 ++++++++----------
 2 files changed, 10 insertions(+), 13 deletions(-)

Diff

diff --git a/comwell_key_app/lib/booking_details/components/share_button.dart b/comwell_key_app/lib/booking_details/components/share_button.dart
index dead2a72..845c42c3 100644
--- a/comwell_key_app/lib/booking_details/components/share_button.dart
+++ b/comwell_key_app/lib/booking_details/components/share_button.dart
@@ -72,7 +72,7 @@ class ShareButton extends StatelessWidget {
final results = await _showGuestList(
context, index, guests, booking.booker);
- if (results is List<String>) {
+ if (results is Iterable<String>) {
final updatedBooking =
booking.updateGuests(results);
bloc.add(UpdateBookingEvent(updatedBooking));
@@ -157,8 +157,7 @@ class ShareButton extends StatelessWidget {
child: GuestList(
guests: guests
.where((guest) => guest.name != booker)
- .map((guest) => guest.name)
- .toList(),
+ .map((guest) => guest.name),
selectedGuests: state.selectedGuests,
onGuestSelected: (Iterable<String> newSelection) {
cubit.updateSelectedGuests(newSelection);
diff --git a/comwell_key_app/lib/overview/models/booking.dart b/comwell_key_app/lib/overview/models/booking.dart
index 16d29397..57c13a77 100644
--- a/comwell_key_app/lib/overview/models/booking.dart
+++ b/comwell_key_app/lib/overview/models/booking.dart
@@ -24,7 +24,7 @@ class Booking extends Equatable {
final DateTime bookingDate;
final PaymentDetails paymentDetails;
final String confirmationId;
- final List<Guest> guests;
+ final Iterable<Guest> guests;
Booking({
required this.id,
@@ -43,11 +43,11 @@ class Booking extends Equatable {
required this.booker,
required this.bookingDate,
required this.paymentDetails,
- List<Guest>? guests,
+ Iterable<Guest>? guests,
}) : guests = _ensureBookerInGuestList(booker, userId, guests ?? []);
- static List<Guest> _ensureBookerInGuestList(
- String booker, String userId, List<Guest> guests) {
+ static Iterable<Guest> _ensureBookerInGuestList(
+ String booker, String userId, Iterable<Guest> guests) {
final bookerExists = guests.any((guest) => guest.name == booker);
if (!bookerExists) {
return [
@@ -99,7 +99,7 @@ class Booking extends Equatable {
DateTime? bookingDate,
PaymentDetails? paymentDetails,
String? confirmationId,
- List<Guest>? guests,
+ Iterable<Guest>? guests,
}) {
return Booking(
id: id ?? this.id,
@@ -122,11 +122,9 @@ class Booking extends Equatable {
);
}
- Booking updateGuests(List<String> guestNames) {
- final updatedGuests = guests
- .where(
- (guest) => guest.name == booker || !guestNames.contains(guest.name))
- .toList();
+ Booking updateGuests(Iterable<String> guestNames) {
+ final updatedGuests = guests.where(
+ (guest) => guest.name == booker || !guestNames.contains(guest.name));
return copyWith(guests: updatedGuests);
}