6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit fa8c1141
Changed files
.../bloc/booking_details_state.dart | 6 ++-- .../lib/booking_details/components/guest_list.dart | 8 +++--- .../booking_details/components/share_button.dart | 13 +++++---- comwell_key_app/lib/routing/app_router.dart | 32 ++-------------------- .../lib/share/cubit/share_booking_cubit.dart | 2 +- .../lib/share/cubit/share_booking_state.dart | 6 ++-- comwell_key_app/lib/utils/share_button_utils.dart | 2 +- 7 files changed, 21 insertions(+), 48 deletions(-)
Diff
diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
index 6d8d3b55..d56f5c15 100644
--- a/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
@@ -5,7 +5,7 @@ class BookingDetailsState extends Equatable {
final BookingDetailsStatus status;
final MobileKeysKey? key;
final List<MobileKeysKey> keys;
- final List<Guest> guests;
+ final Iterable<Guest> guests;
const BookingDetailsState._(
{required this.status,
@@ -28,7 +28,7 @@ class BookingDetailsState extends Equatable {
BookingDetailsState houseKeepingOrdered() => copyWith(
status: BookingDetailsStatus.houseKeepingOrdered,
isHouseKeepingOrdered: true);
- BookingDetailsState updateGuests(List<Guest> guests) =>
+ BookingDetailsState updateGuests(Iterable<Guest> guests) =>
copyWith(status: BookingDetailsStatus.guestsUpdated, guests: guests);
BookingDetailsState main() => copyWith(status: BookingDetailsStatus.main);
@@ -41,7 +41,7 @@ class BookingDetailsState extends Equatable {
MobileKeysKey? key,
List<MobileKeysKey>? keys,
bool? isHouseKeepingOrdered,
- List<Guest>? guests,
+ Iterable<Guest>? guests,
}) {
return BookingDetailsState._(
status: status ?? this.status,
diff --git a/comwell_key_app/lib/booking_details/components/guest_list.dart b/comwell_key_app/lib/booking_details/components/guest_list.dart
index 565b0582..20deb809 100644
--- a/comwell_key_app/lib/booking_details/components/guest_list.dart
+++ b/comwell_key_app/lib/booking_details/components/guest_list.dart
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
class GuestList extends StatelessWidget {
- final List<String> guests;
- final List<String> selectedGuests;
- final Function(List<String>) onGuestSelected;
+ final Iterable<String> guests;
+ final Iterable<String> selectedGuests;
+ final void Function(Iterable<String>) onGuestSelected;
const GuestList({
super.key,
@@ -24,7 +24,7 @@ class GuestList extends StatelessWidget {
shrinkWrap: true,
itemCount: guests.length,
itemBuilder: (context, index) {
- final guest = guests[index];
+ final guest = guests.elementAt(index);
final initials = guest.split(' ').map((name) => name[0]).join('');
return Padding(
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 3722cdbf..dead2a72 100644
--- a/comwell_key_app/lib/booking_details/components/share_button.dart
+++ b/comwell_key_app/lib/booking_details/components/share_button.dart
@@ -12,7 +12,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
class ShareButton extends StatelessWidget {
- final List<Guest> guests;
+ final Iterable<Guest> guests;
const ShareButton({super.key, required this.guests});
@override
@@ -87,7 +87,7 @@ class ShareButton extends StatelessWidget {
),
child: Center(
child: Text(
- allInitials[index],
+ allInitials.elementAt(index),
style: const TextStyle(
color: Colors.white,
fontWeight: FontWeight.w400,
@@ -108,7 +108,7 @@ class ShareButton extends StatelessWidget {
}
Future<dynamic> _showGuestList(BuildContext context, int index,
- List<Guest> guests, String booker) async {
+ Iterable<Guest> guests, String booker) async {
final theme = Theme.of(context);
return showModalBottomSheet<dynamic>(
@@ -160,7 +160,7 @@ class ShareButton extends StatelessWidget {
.map((guest) => guest.name)
.toList(),
selectedGuests: state.selectedGuests,
- onGuestSelected: (List<String> newSelection) {
+ onGuestSelected: (Iterable<String> newSelection) {
cubit.updateSelectedGuests(newSelection);
},
),
@@ -190,7 +190,8 @@ class ShareButton extends StatelessWidget {
),
);
- if (shouldRemove == true) {
+ if (shouldRemove == true &&
+ context.mounted) {
context.pop(state.selectedGuests);
}
}
@@ -229,7 +230,7 @@ class ShareButton extends StatelessWidget {
BuildContext context,
ShareBookingCubit cubit,
BuildContext bottomSheetContext,
- List<String> selectedGuests,
+ Iterable<String> selectedGuests,
) {
return AlertDialog(
shape: RoundedRectangleBorder(
diff --git a/comwell_key_app/lib/routing/app_router.dart b/comwell_key_app/lib/routing/app_router.dart
index 5b31d687..600763fd 100644
--- a/comwell_key_app/lib/routing/app_router.dart
+++ b/comwell_key_app/lib/routing/app_router.dart
@@ -155,7 +155,7 @@ GoRouter goRouter(AuthenticationBloc authBloc) {
},
),
GoRoute(
- path: "/booking/:id",
+ path: "/${AppRoutes.bookingDetails.name}/:id",
name: "booking_deep_link",
builder: (context, state) {
final bookingId = state.pathParameters['id']!;
@@ -164,35 +164,7 @@ GoRouter goRouter(AuthenticationBloc authBloc) {
..findBookingById(bookingId),
child: BlocListener<OverviewCubit, OverviewState>(
listener: (context, state) {
- if (state is OverviewLoaded) {
- Booking? booking;
- try {
- booking = state.bookings.current.firstWhere(
- (b) => b.id == bookingId,
- orElse: () => state.bookings.past.firstWhere(
- (b) => b.id == bookingId,
- orElse: () => state.bookings.cancelled.firstWhere(
- (b) => b.id == bookingId,
- orElse: () => throw Exception('Booking not found'),
- ),
- ),
- );
- } catch (e) {
- if (context.mounted) {
- context.pushNamed(AppRoutes.findBooking.name);
- return;
- }
- }
-
- if (booking != null && context.mounted) {
- context.pushNamed(AppRoutes.bookingDetails.name,
- extra: booking);
- }
- } else if (state is OverviewError) {
- if (context.mounted) {
- context.pushNamed(AppRoutes.findBooking.name);
- }
- }
+ // TODO: Implement listener
},
child: const LoadingPage(),
),
diff --git a/comwell_key_app/lib/share/cubit/share_booking_cubit.dart b/comwell_key_app/lib/share/cubit/share_booking_cubit.dart
index adede48a..46f76b5d 100644
--- a/comwell_key_app/lib/share/cubit/share_booking_cubit.dart
+++ b/comwell_key_app/lib/share/cubit/share_booking_cubit.dart
@@ -9,7 +9,7 @@ part 'share_booking_state.dart';
class ShareBookingCubit extends Cubit<ShareBookingState> {
ShareBookingCubit() : super(const ShareBookingState.initial());
- void updateSelectedGuests(List<String> guests) {
+ void updateSelectedGuests(Iterable<String> guests) {
emit(state.updateSelectedGuests(guests));
}
diff --git a/comwell_key_app/lib/share/cubit/share_booking_state.dart b/comwell_key_app/lib/share/cubit/share_booking_state.dart
index 86052ef3..c1c2daf2 100644
--- a/comwell_key_app/lib/share/cubit/share_booking_state.dart
+++ b/comwell_key_app/lib/share/cubit/share_booking_state.dart
@@ -1,7 +1,7 @@
part of 'share_booking_cubit.dart';
class ShareBookingState extends Equatable {
- final List<String> selectedGuests;
+ final Iterable<String> selectedGuests;
const ShareBookingState._({
required this.selectedGuests,
@@ -9,10 +9,10 @@ class ShareBookingState extends Equatable {
const ShareBookingState.initial() : this._(selectedGuests: const []);
- ShareBookingState updateSelectedGuests(List<String> guests) =>
+ ShareBookingState updateSelectedGuests(Iterable<String> guests) =>
_copyWith(selectedGuests: guests);
- ShareBookingState _copyWith({List<String>? selectedGuests}) {
+ ShareBookingState _copyWith({Iterable<String>? selectedGuests}) {
return ShareBookingState._(
selectedGuests: selectedGuests ?? this.selectedGuests);
}
diff --git a/comwell_key_app/lib/utils/share_button_utils.dart b/comwell_key_app/lib/utils/share_button_utils.dart
index 8cf35682..ecf82875 100644
--- a/comwell_key_app/lib/utils/share_button_utils.dart
+++ b/comwell_key_app/lib/utils/share_button_utils.dart
@@ -1,6 +1,6 @@
import 'package:comwell_key_app/overview/models/guest.dart';
-List<String> generateInitials(List<Guest> guests) {
+Iterable<String> generateInitials(Iterable<Guest> guests) {
final guestInitials = guests
.map((guest) => guest.name.split(' ').map((name) => name[0]).join(''))
.toList();