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

AuthorEdmir Suljic<esu@dwarf.dk>
Date2025-06-02 11:08:20 +0200
Mid fix

Changed files

.../booking_details/bloc/booking_details_bloc.dart |  28 +++-
 .../lib/booking_details/booking_details_page.dart  |   8 +-
 .../components/check_in_button_timer.dart          | 172 +++++++++++----------
 comwell_key_app/lib/overview/models/booking.dart   |   3 +-
 4 files changed, 114 insertions(+), 97 deletions(-)

Diff

diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
index 441db6a8..6b1c2a4b 100644
--- a/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
@@ -19,12 +19,10 @@ part 'booking_details_state.dart';
class BookingDetailsBloc
extends Bloc<BookingDetailsEvent, BookingDetailsState> {
late Booking booking;
-
+ Timer? _timer;
final BookingDetailsRepository bookingDetailsRepository;
final ProfileRepository profileRepository;
final SeosRepository seosRepository = locator<SeosRepository>();
- late final Timer timer = Timer.periodic(
- const Duration(seconds: 1), (_) => add(UpdateRemainingEvent(getCheckInTime().difference(DateTime.now()))));
Duration _remainingTime = Duration.zero;
@@ -36,11 +34,11 @@ class BookingDetailsBloc
on<InitialEvent>((event, emit) async {
try {
emit(state.loading());
+ _startTimer();
add(CheckIfHouseKeepingOrdered());
add(CheckMobileKeys());
add(GetBookingDetailsEvent(booking.confirmationId));
add(UpdateRemainingEvent(getCheckInTime().difference(DateTime.now())));
-
} catch (e, st) {
if (kDebugMode) print("err=$e, $st");
emit(state.setupError());
@@ -115,15 +113,31 @@ class BookingDetailsBloc
}
}
+ void _startTimer() {
+ _timer?.cancel();
+ _timer = Timer.periodic(
+ const Duration(seconds: 1),
+ (_) => add(UpdateRemainingEvent(getCheckInTime().difference(DateTime.now()))),
+ );
+ }
+
+ @override
+ Future<void> close() {
+ _timer?.cancel();
+ return super.close();
+ }
+
Future<void> updateRemainingTime(Emitter<BookingDetailsState> emit) async {
final now = DateTime.now();
_remainingTime = getCheckInTime().difference(now);
- if (_remainingTime.isNegative) {
- timer?.cancel();
- }
emit(state.updateRemainingTime(_remainingTime));
+
+ if (_remainingTime.isNegative) {
+ _timer?.cancel();
+ emit(state.updateRemainingTime(_remainingTime));
+ }
}
//TODO add checkin time from backend when we have it
diff --git a/comwell_key_app/lib/booking_details/booking_details_page.dart b/comwell_key_app/lib/booking_details/booking_details_page.dart
index d621a440..43d40271 100644
--- a/comwell_key_app/lib/booking_details/booking_details_page.dart
+++ b/comwell_key_app/lib/booking_details/booking_details_page.dart
@@ -99,11 +99,9 @@ class BookingDetailsPage extends StatelessWidget {
const SizedBox(height: 10),
if (state.keys.isNotEmpty && cubit.booking.roomNumber != '')
const UnlockRoomButton()
- else if (cubit.booking.reservationStatus ==
- ReservationStatus.preregistered)
- CheckInButtonTimer(checkInTime: cubit.getCheckInTime()),
- if (cubit.booking.reservationStatus ==
- ReservationStatus.newreservation)
+ else if (cubit.booking.reservationStatus == ReservationStatus.newreservation)
+ const CheckInButtonTimer()
+ else if (cubit.booking.reservationStatus == ReservationStatus.preregistered)
const PreregisterButton(),
const SizedBox(
height: 100,
diff --git a/comwell_key_app/lib/booking_details/components/check_in_button_timer.dart b/comwell_key_app/lib/booking_details/components/check_in_button_timer.dart
index dcc40fc6..4a79ed02 100644
--- a/comwell_key_app/lib/booking_details/components/check_in_button_timer.dart
+++ b/comwell_key_app/lib/booking_details/components/check_in_button_timer.dart
@@ -8,8 +8,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_svg.dart';
class CheckInButtonTimer extends StatefulWidget {
- final DateTime checkInTime;
- const CheckInButtonTimer({super.key, required this.checkInTime});
+ const CheckInButtonTimer({super.key,});
@override
State<CheckInButtonTimer> createState() => _CheckInButtonTimerState();
@@ -19,97 +18,102 @@ class _CheckInButtonTimerState extends State<CheckInButtonTimer> {
@override
Widget build(BuildContext context) {
- final cubit = context.read<BookingDetailsBloc>();
- return AnimatedSwitcher(
- duration: const Duration(milliseconds: 300),
- transitionBuilder: (Widget child, Animation<double> animation) {
- return FadeTransition(
- opacity: animation,
- child: child,
+ return BlocBuilder<BookingDetailsBloc, BookingDetailsState>(
+ builder: (context, state) {
+ return AnimatedSwitcher(
+ duration: const Duration(milliseconds: 300),
+ transitionBuilder: (Widget child, Animation<double> animation) {
+ return FadeTransition(
+ opacity: animation,
+ child: child,
+ );
+ },
+ child: state.remainingTime.isNegative
+ ? const CheckInButton(key: ValueKey('check_in_button'))
+ : getTimerWidget()
);
},
- child: cubit.state.remainingTime.isNegative
- ? const CheckInButton(key: ValueKey('check_in_button'))
- : getTimerWidget()
);
}
Widget getTimerWidget() {
return BlocBuilder<BookingDetailsBloc, BookingDetailsState>(
- key: const ValueKey('timer_view'),
- builder: (context, state) {
- final (days, hours, minutes, seconds) = getDurationInMinutes(state.remainingTime);
- final dateStr =
- DateFormat('d. MMM', 'da').format(widget.checkInTime);
- final theme = Theme.of(context);
- final timeStr = days > 0
- ? "check_in_button_timer_days_hours_minutes".tr(args: [days.toString(), hours.toString(), minutes.toString()])
- : hours > 0
- ? "check_in_button_timer_hours_minutes".tr(args: [hours.toString(), minutes.toString()])
- : minutes > 0
- ? "check_in_button_timer_minutes".tr(args: [minutes.toString()])
- : "check_in_button_timer_seconds".tr(args: [seconds.toString()]);
+ key: const ValueKey('timer_view'),
+ builder: (context, state) {
+ final cubit = context.read<BookingDetailsBloc>();
+ final (days, hours, minutes, seconds) = getDurationInMinutes(state.remainingTime);
+ final checkInTime = cubit.getCheckInTime();
+ final dateStr = DateFormat('d. MMM', 'da').format(checkInTime);
+
+ final theme = Theme.of(context);
+ final timeStr = days > 0
+ ? "check_in_button_timer_days_hours_minutes".tr(args: [days.toString(), hours.toString(), minutes.toString()])
+ : hours > 0
+ ? "check_in_button_timer_hours_minutes".tr(args: [hours.toString(), minutes.toString()])
+ : minutes > 0
+ ? "check_in_button_timer_minutes".tr(args: [minutes.toString()])
+ : "check_in_button_timer_seconds".tr(args: [seconds.toString()]);
- return Container(
- margin: const EdgeInsets.symmetric(horizontal: 10),
- decoration: BoxDecoration(
- color: Colors.grey[900]?.withOpacity(0.8),
- borderRadius: BorderRadius.circular(30),
- ),
- padding:
- const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
- child: Row(
- children: [
- SvgPicture.asset(
- 'assets/icons/ic_locked.svg',
- colorFilter: const ColorFilter.mode(
- Colors.white,
- BlendMode.srcIn,
- ),
- ),
- const SizedBox(width: 16),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- 'Check-in',
- style: theme.textTheme.titleMedium?.copyWith(
- color: Colors.white,
- fontWeight: FontWeight.w600,
- ),
- ),
- Text(
- timeStr,
- style: theme.textTheme.bodyMedium?.copyWith(
- color: Colors.white.withOpacity(0.8)),
- ),
- ],
- ),
- ),
- Column(
- crossAxisAlignment: CrossAxisAlignment.end,
- children: [
- Text(
- dateStr.toUpperCase(),
- style: theme.textTheme.bodySmall?.copyWith(
- color: Colors.white.withOpacity(0.7),
- fontWeight: FontWeight.w600,
- ),
- ),
- Text(
- DateFormat('HH:mm').format(widget.checkInTime),
- style: theme.textTheme.titleMedium?.copyWith(
- color: Colors.white,
- fontWeight: FontWeight.w600,
- ),
- ),
- ],
+ return Container(
+ margin: const EdgeInsets.symmetric(horizontal: 10),
+ decoration: BoxDecoration(
+ color: Colors.grey[900]?.withOpacity(0.8),
+ borderRadius: BorderRadius.circular(30),
+ ),
+ padding:
+ const EdgeInsets.symmetric(horizontal: 20, vertical: 8),
+ child: Row(
+ children: [
+ SvgPicture.asset(
+ 'assets/icons/ic_locked.svg',
+ colorFilter: const ColorFilter.mode(
+ Colors.white,
+ BlendMode.srcIn,
+ ),
+ ),
+ const SizedBox(width: 16),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ 'Check-in',
+ style: theme.textTheme.titleMedium?.copyWith(
+ color: Colors.white,
+ fontWeight: FontWeight.w600,
),
- ],
+ ),
+ Text(
+ timeStr,
+ style: theme.textTheme.bodyMedium?.copyWith(
+ color: Colors.white.withOpacity(0.8)),
+ ),
+ ],
+ ),
+ ),
+ Column(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ Text(
+ dateStr.toUpperCase(),
+ style: theme.textTheme.bodySmall?.copyWith(
+ color: Colors.white.withOpacity(0.7),
+ fontWeight: FontWeight.w600,
+ ),
),
- );
- },
- );
+ Text(
+ DateFormat('HH:mm').format(checkInTime),
+ style: theme.textTheme.titleMedium?.copyWith(
+ color: Colors.white,
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ );
+ },
+ );
}
}
diff --git a/comwell_key_app/lib/overview/models/booking.dart b/comwell_key_app/lib/overview/models/booking.dart
index c6580768..e8070ef8 100644
--- a/comwell_key_app/lib/overview/models/booking.dart
+++ b/comwell_key_app/lib/overview/models/booking.dart
@@ -154,7 +154,8 @@ enum ReservationStatus {
}
final status = ReservationStatus.values.firstWhere(
(status) => status.name.toLowerCase() == value.toLowerCase());
-
+
+ print("status: $status");
return status;
}
}