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

AuthorMikkel Thygesen<mth@dwarf.dk>
Date2025-01-28 12:28:14 +0100
455: Refactored SEOS plugin to start and setup after login

Changed files

comwell_key_app/assets/translations/da-DK.json     |   4 +-
 comwell_key_app/assets/translations/en-US.json     |   4 +-
 .../lib/.generated/overview/models/booking.g.dart  |   1 -
 .../authentication/authentication_repository.dart  |  43 ++--
 .../authentication/bloc/authentication_bloc.dart   |  11 +
 .../booking_details/bloc/booking_details_bloc.dart | 105 ++++++++++
 .../bloc/booking_details_event.dart                |  50 +++++
 .../bloc/booking_details_state.dart                |  62 ++++++
 .../lib/booking_details/booking_details_page.dart  | 233 +++++++++++++++++++++
 .../booking_details_repository.dart                |  26 +++
 .../components/housekeeping_button.dart            |  80 +++++++
 .../components/room_key_widget.dart                |  67 ++++++
 .../lib/check_in/bloc/check_in_cubit.dart          |  13 +-
 .../lib/check_in/check_in_repository.dart          |  47 +++--
 comwell_key_app/lib/comwell_app.dart               |  20 +-
 comwell_key_app/lib/home/bloc/home_bloc.dart       | 112 ----------
 comwell_key_app/lib/home/bloc/home_event.dart      |  50 -----
 comwell_key_app/lib/home/bloc/home_state.dart      |  62 ------
 .../lib/home/components/housekeeping_button.dart   |  80 -------
 .../lib/home/components/room_key_widget.dart       |  67 ------
 comwell_key_app/lib/home/home_page.dart            | 229 --------------------
 comwell_key_app/lib/home/home_repository.dart      | 125 -----------
 comwell_key_app/lib/key/bloc/key_bloc.dart         |  24 +--
 .../lib/key/repository/key_repository.dart         |  10 +-
 .../components/booking_list_item_view.dart         |   3 +-
 .../components/current_booking_list_item_view.dart |   4 +-
 .../lib/overview/cubit/overview_cubit.dart         |   4 +-
 .../overview/repository/overview_repository.dart   |   9 +
 .../lib/profile/profile_repository.dart            |   4 +-
 comwell_key_app/lib/redeem_debug/redeem_page.dart  |   6 +-
 comwell_key_app/lib/routing/app_router.dart        |  34 ++-
 comwell_key_app/lib/routing/app_routes.dart        |   2 +-
 comwell_key_app/lib/services/api.dart              |  16 +-
 comwell_key_app/lib/settings/settings_page.dart    |   4 +-
 comwell_key_app/lib/utils/locator.dart             |  10 +-
 comwell_key_app/lib/utils/seos_repository.dart     |  92 ++++++++
 comwell_key_app/lib/utils/singleton.dart           |  14 --
 .../authentication_bloc_test.dart                  |   1 +
 .../authentication_repository.dart                 |  53 +++++
 .../booking_details_bloc_test.dart                 |  35 ++++
 .../booking_details_repository_test.dart           |  23 ++
 comwell_key_app/test/home_test/home_bloc_test.dart |  38 ----
 .../test/home_test/home_repository_test.dart       |  53 -----
 comwell_key_app/test/key_test/key_bloc_test.dart   |  19 +-
 .../test/key_test/key_repository_test.dart         |   2 +-
 .../test/overview_test/overview_cubic_test.dart    |  14 +-
 .../overview_test/overview_repository_test.dart    |   2 +
 47 files changed, 1021 insertions(+), 946 deletions(-)

Diff

diff --git a/comwell_key_app/assets/translations/da-DK.json b/comwell_key_app/assets/translations/da-DK.json
index 5fa7ebc7..cbd46934 100644
--- a/comwell_key_app/assets/translations/da-DK.json
+++ b/comwell_key_app/assets/translations/da-DK.json
@@ -122,8 +122,8 @@
"housekeeping_page_service_title_soap": "Sæbe/shampoo",
"housekeeping_page_service_cleaning_subtitle": "Der bliver gjort rent mellem 11 og 14",
"housekeeping_page_supplies": "Forsyninger",
- "home_page_housekeeping_button_title": "Bestil housekeeping",
- "home_page_housekeeping_button_subtitle": "Ønsker du ekstra rengøring eller opfyldning på værelset, kan du altid bestille det her - uden omkostninger",
+ "booking_details_page_housekeeping_button_title": "Bestil housekeeping",
+ "booking_details_page_housekeeping_button_subtitle": "Ønsker du ekstra rengøring eller opfyldning på værelset, kan du altid bestille det her - uden omkostninger",
"need_help": "Har du brug for hjælp?",
"call_us": "Ring til os",
"call_us_description": "Har du brug for at komme i kontakt med et af vores hoteller? Benyt knappen nedenfor for at ringe op.",
diff --git a/comwell_key_app/assets/translations/en-US.json b/comwell_key_app/assets/translations/en-US.json
index 5fb92400..6107c34c 100644
--- a/comwell_key_app/assets/translations/en-US.json
+++ b/comwell_key_app/assets/translations/en-US.json
@@ -121,8 +121,8 @@
"housekeeping_page_service_cleaning_subtitle": "Cleaning is between 11 and 14",
"housekeeping_page_supplies": "Supplies",
"housekeeping_page_cleaning": "Cleaning",
- "home_page_housekeeping_button_title": "Order housekeeping",
- "home_page_housekeeping_button_subtitle": "Order here",
+ "booking_details_page_housekeeping_button_title": "Order housekeeping",
+ "booking_details_page_housekeeping_button_subtitle": "Order here",
"need_help": "Need help?",
"call_us": "Call us",
"call_us_description": "Enter your phone number below and we will call you.",
diff --git a/comwell_key_app/lib/.generated/overview/models/booking.g.dart b/comwell_key_app/lib/.generated/overview/models/booking.g.dart
index fd8240fe..aa3195c3 100644
--- a/comwell_key_app/lib/.generated/overview/models/booking.g.dart
+++ b/comwell_key_app/lib/.generated/overview/models/booking.g.dart
@@ -42,7 +42,6 @@ Map<String, dynamic> _$BookingToJson(Booking instance) => <String, dynamic>{
'booker': instance.booker,
'bookingDate': instance.bookingDate.toIso8601String(),
'paymentDetails': instance.paymentDetails.toJson(),
- 'paymentDetails': instance.paymentDetails,
'confirmationId': instance.confirmationId,
};
diff --git a/comwell_key_app/lib/authentication/authentication_repository.dart b/comwell_key_app/lib/authentication/authentication_repository.dart
index cefd4d86..f5a18089 100644
--- a/comwell_key_app/lib/authentication/authentication_repository.dart
+++ b/comwell_key_app/lib/authentication/authentication_repository.dart
@@ -1,28 +1,52 @@
import 'dart:async';
import 'package:comwell_key_app/authentication/enum/authentication_status.dart';
+import 'package:comwell_key_app/services/api.dart';
import 'package:comwell_key_app/utils/secure_storage.dart';
import 'package:comwell_key_app/common/const.dart' as constants;
+import '../utils/seos_repository.dart';
+
class AuthenticationRepository {
late SecureStorage secureStorage;
final _controller = StreamController<AuthenticationStatus>.broadcast();
+ final seos = SeosRepository();
+ final api = Api();
AuthenticationRepository() {
secureStorage = SecureStorage();
}
Stream<AuthenticationStatus> get status async* {
- await Future<void>.delayed(const Duration(seconds: 1));
- //yield AuthenticationStatus.unauthenticated;
- yield* _controller.stream;
+ yield* _controller.stream.map((status) {
+ _onAuthResult(status);
+ return status;
+ });
+ }
+
+ void _onAuthResult(AuthenticationStatus status) async {
+ try {
+ if (status == AuthenticationStatus.authenticated) {
+ final isEndpointSetup = await seos.startMobilePlugin();
+ if (isEndpointSetup) {
+ print("qqq endpoint updated");
+ } else {
+ final invitationCode = await api.createEndpointRegistration();
+ print("qqq invitationCode=$invitationCode");
+ await seos.setupEndpoint(invitationCode);
+ print("qqq endpoint setup");
+ }
+ }
+ } catch (e, st) {
+ print("qqq e=$e");
+ }
}
Future<void> logIn() async {
_controller.sink.add(AuthenticationStatus.authenticated);
}
- Future<void> logOut() async{
+ Future<void> logOut() async {
await secureStorage.deleteAll();
_controller.sink.add(AuthenticationStatus.unauthenticated);
}
@@ -30,13 +54,8 @@ class AuthenticationRepository {
void dispose() => _controller.close();
Future<bool> doesTokenExist() async {
- String? refreshtoken = await secureStorage.read(constants.refreshToken);
- String? accesstoken = await secureStorage.read(constants.accessToken);
-
- if (refreshtoken != null && accesstoken != null) {
- return true;
- } else {
- return false;
- }
+ final refreshToken = await secureStorage.read(constants.refreshToken);
+ final accessToken = await secureStorage.read(constants.accessToken);
+ return refreshToken != null && accessToken != null;
}
}
diff --git a/comwell_key_app/lib/authentication/bloc/authentication_bloc.dart b/comwell_key_app/lib/authentication/bloc/authentication_bloc.dart
index a9b53962..6a24d1fe 100644
--- a/comwell_key_app/lib/authentication/bloc/authentication_bloc.dart
+++ b/comwell_key_app/lib/authentication/bloc/authentication_bloc.dart
@@ -1,18 +1,22 @@
import 'package:bloc/bloc.dart';
import 'package:comwell_key_app/authentication/authentication_repository.dart';
import 'package:comwell_key_app/authentication/enum/authentication_status.dart';
+import 'package:comwell_key_app/utils/seos_repository.dart';
import 'package:equatable/equatable.dart';
import 'package:firebase_analytics/firebase_analytics.dart';
+import 'package:seos_mobile_keys_plugin/seos_mobile_keys_plugin.dart';
part 'authentication_event.dart';
part 'authentication_state.dart';
class AuthenticationBloc
extends Bloc<AuthenticationEvent, AuthenticationState> {
+
AuthenticationBloc({
required AuthenticationRepository authenticationRepository,
}) : _authenticationRepository = authenticationRepository,
super(const AuthenticationState.unknown()) {
+ print("qqq AuthenticationBloc");
on<AuthenticationSubscriptionRequested>(_onSubscriptionRequested);
on<AuthenticationLogoutPressed>(_onLogoutPressed);
on<AuthenticationLoginPressed>(_onLoginPressed);
@@ -21,6 +25,11 @@ class AuthenticationBloc
final AuthenticationRepository _authenticationRepository;
+ void post(){
+ print("qqq add");
+ add(AuthenticationSubscriptionRequested());
+ }
+
void _onLogoutPressed(
AuthenticationLogoutPressed event,
Emitter<AuthenticationState> emit,
@@ -32,9 +41,11 @@ class AuthenticationBloc
AuthenticationSubscriptionRequested event,
Emitter<AuthenticationState> emit,
) {
+ print("qqq _onSubscriptionRequested");
return emit.onEach(
_authenticationRepository.status.asBroadcastStream(),
onData: (status) async {
+ print("qqq ondata $status");
switch (status) {
case AuthenticationStatus.unauthenticated:
await FirebaseAnalytics.instance.setUserProperty(
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
new file mode 100644
index 00000000..199ff650
--- /dev/null
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_bloc.dart
@@ -0,0 +1,105 @@
+
+import 'package:bloc/bloc.dart';
+import 'package:comwell_key_app/database/comwell_db.dart';
+import 'package:equatable/equatable.dart';
+import 'package:flutter/foundation.dart';
+import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
+
+import '../../overview/models/booking.dart';
+import '../../utils/locator.dart';
+import '../booking_details_repository.dart';
+
+part 'booking_details_event.dart';
+
+part 'booking_details_state.dart';
+
+class BookingDetailsBloc extends Bloc<BookingDetailsEvent, BookingDetailsState> {
+ final Booking booking;
+
+ final BookingDetailsRepository bookingDetailsRepository;
+ final ComwellDatabase database = locator<ComwellDatabase>();
+
+ BookingDetailsBloc(
+ this.booking, {
+ required this.bookingDetailsRepository,
+ }) : super(BookingDetailsState.initial()) {
+ on<InitialEvent>((event, emit) async {
+ emit(state.setupStarted());
+ try {
+ await checkIfHouseKeepingOrdered(emit);
+ if (kIsWeb) {
+ emit(state.setupComplete());
+ return;
+ }
+ final isEndPointSetup = true; //await bookingDetailsRepository.startMobilePlugin();
+ if (isEndPointSetup) {
+ emit(state.setupComplete());
+ } else {
+ emit(state.mobilePluginStarted());
+ SetupEndpoint();
+ }
+ } catch (e, st) {
+ if (kDebugMode) print("qqq $e, $st");
+ emit(state.setupError());
+ }
+ });
+
+ on<SetupEndpoint>((event, emit) async {
+ emit(state.setupStarted());
+ try {
+ if (kIsWeb) {
+ emit(state.setupComplete());
+ return;
+ }
+ emit(state.setupComplete());
+ } catch (_) {
+ emit(state.setupError());
+ }
+ });
+
+ on<SearchForKeysEvent>((event, emit) async {
+ if (kIsWeb) {
+ emit(state.invalidOrNoKey());
+ return;
+ }
+ // this is set because there is a bit and issue with updating the endpoint first and second time it is run! will fix this later and remove it
+ if (event.endpointNeedsUpdate) {
+ //await bookingDetailsRepository.updateEndpoint();
+ }
+ final List<MobileKeysKey> keys = [];//await bookingDetailsRepository.refreshKeys();
+ if (keys.length == 1) {
+ emit(state.validKey(keys[0]));
+ } else if (keys.length > 1) {
+ emit(state.multipleKeys(keys));
+ } else {
+ emit(state.invalidOrNoKey());
+ }
+ });
+
+ on<ProvisionKeyEvent>((event, emit) async {
+ if (kIsWeb) {
+ emit(state.keyProvisioned());
+ return;
+ }
+ try {
+ // await bookingDetailsRepository.provisionKey(bookingId: event.bookingId, forceProvision: true,);
+
+ emit(state.keyProvisioned());
+ } catch (_) {
+ emit(state.setupError());
+ }
+ });
+
+ on<CheckIfHouseKeepingOrdered>((event, emit) async {
+ await checkIfHouseKeepingOrdered(emit);
+ });
+ }
+
+ Future<void> checkIfHouseKeepingOrdered(
+ Emitter<BookingDetailsState> emit) async {
+ final isHouseKeepingOrdered = await bookingDetailsRepository.isHousesKeepingOrdered();
+ if (isHouseKeepingOrdered) {
+ emit(state.houseKeepingOrdered());
+ }
+ }
+}
diff --git a/comwell_key_app/lib/booking_details/bloc/booking_details_event.dart b/comwell_key_app/lib/booking_details/bloc/booking_details_event.dart
new file mode 100644
index 00000000..a5df2c69
--- /dev/null
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_event.dart
@@ -0,0 +1,50 @@
+part of 'booking_details_bloc.dart';
+
+sealed class BookingDetailsEvent extends Equatable {
+ const BookingDetailsEvent();
+
+ @override
+ List<Object> get props => [];
+}
+
+final class InitialEvent extends BookingDetailsEvent {}
+
+final class CodeEnteredEvent extends BookingDetailsEvent {
+ final String code;
+
+ const CodeEnteredEvent(this.code);
+
+ @override
+ List<Object> get props => [code];
+}
+
+final class SearchForKeysEvent extends BookingDetailsEvent {
+ final bool endpointNeedsUpdate;
+
+ const SearchForKeysEvent({this.endpointNeedsUpdate = false});
+
+ @override
+ List<Object> get props => [];
+}
+
+final class SetupEndpoint extends BookingDetailsEvent {}
+
+final class KeySelectedEvent extends BookingDetailsEvent {
+ final String key;
+
+ const KeySelectedEvent(this.key);
+
+ @override
+ List<Object> get props => [key];
+}
+
+final class CheckIfHouseKeepingOrdered extends BookingDetailsEvent {}
+
+final class ProvisionKeyEvent extends BookingDetailsEvent {
+ final String bookingId;
+
+ const ProvisionKeyEvent(this.bookingId);
+
+ @override
+ List<Object> get props => [bookingId];
+}
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
new file mode 100644
index 00000000..df5db668
--- /dev/null
+++ b/comwell_key_app/lib/booking_details/bloc/booking_details_state.dart
@@ -0,0 +1,62 @@
+part of 'booking_details_bloc.dart';
+
+class BookingDetailsState extends Equatable {
+
+ final bool isHouseKeepingOrdered;
+ final BookingDetailsStatus status;
+ final MobileKeysKey? key;
+ final List<MobileKeysKey> keys;
+
+ const BookingDetailsState._({required this.status, required this.key, required this.keys, required this.isHouseKeepingOrdered});
+
+ BookingDetailsState.initial() : this._(status: BookingDetailsStatus.unknown, key: null, keys: [], isHouseKeepingOrdered: false);
+ BookingDetailsState setupStarted() => copyWith(status: BookingDetailsStatus.setupStarted);
+ BookingDetailsState setupComplete() => copyWith(status: BookingDetailsStatus.setupComplete);
+ BookingDetailsState mobilePluginStarted() => copyWith(status: BookingDetailsStatus.mobilePluginStarted);
+ BookingDetailsState invalidOrNoKey() => copyWith(status: BookingDetailsStatus.invalidOrNoKey);
+ BookingDetailsState keyProvisioned() => copyWith(status: BookingDetailsStatus.keyProvisioned);
+ BookingDetailsState multipleKeys(List<MobileKeysKey> keys) => copyWith(status: BookingDetailsStatus.multipleKeys, keys: keys);
+ BookingDetailsState setupNotComplete() => copyWith(status: BookingDetailsStatus.setupNotComplete);
+ BookingDetailsState setupError() => copyWith(status: BookingDetailsStatus.setupError);
+ BookingDetailsState validKey(MobileKeysKey key) => copyWith(status: BookingDetailsStatus.validKey, key: key);
+ BookingDetailsState houseKeepingOrdered() => copyWith(status: BookingDetailsStatus.houseKeepingOrdered, isHouseKeepingOrdered: true);
+ BookingDetailsState main() => copyWith(status: BookingDetailsStatus.main);
+
+ @override
+ List<Object?> get props => [status];
+
+ BookingDetailsState copyWith({
+ BookingDetailsStatus? status,
+ MobileKeysKey? key,
+ List<MobileKeysKey>? keys,
+ bool? isHouseKeepingOrdered,
+ }) {
+ return BookingDetailsState._(
+ status: status ?? this.status,
+ key: key ?? this.key,
+ keys: keys ?? this.keys,
+ isHouseKeepingOrdered: isHouseKeepingOrdered ?? this.isHouseKeepingOrdered,
+ );
+ }
+
+ @override
+ String toString() {
+ return "BookingDetailsState(status=$status, key=$key, keys=$keys, isHouseKeepingOrdered=$isHouseKeepingOrdered)";
+ }
+}
+
+enum BookingDetailsStatus {
+ unknown,
+ setupStarted,
+ setupComplete,
+ setupError,
+ setupNotComplete,
+ firstLaunch,
+ mobilePluginStarted,
+ multipleKeys,
+ validKey,
+ invalidOrNoKey,
+ main,
+ keyProvisioned,
+ houseKeepingOrdered
+}
diff --git a/comwell_key_app/lib/booking_details/booking_details_page.dart b/comwell_key_app/lib/booking_details/booking_details_page.dart
new file mode 100644
index 00000000..d55cdd53
--- /dev/null
+++ b/comwell_key_app/lib/booking_details/booking_details_page.dart
@@ -0,0 +1,233 @@
+import 'package:comwell_key_app/common/components/bottom_sheet_widget.dart';
+import 'package:comwell_key_app/common/components/comwell_app_bar.dart';
+import 'package:comwell_key_app/routing/app_routes.dart';
+import 'package:comwell_key_app/themes/light_theme.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:flutter_svg/flutter_svg.dart';
+import 'package:go_router/go_router.dart';
+import 'package:slider_button/slider_button.dart';
+
+import 'bloc/booking_details_bloc.dart';
+import 'components/housekeeping_button.dart';
+import 'components/room_key_widget.dart';
+
+class BookingDetailsPage extends StatefulWidget {
+
+ const BookingDetailsPage({super.key});
+
+ @override
+ State<StatefulWidget> createState() => _BookingDetailsPage();
+}
+
+class _BookingDetailsPage extends State<BookingDetailsPage> {
+ @override
+ void initState() {
+ super.initState();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final theme = Theme.of(context);
+ return BlocConsumer<BookingDetailsBloc, BookingDetailsState>(
+ listener: (context, state) {
+ if (state.status == BookingDetailsStatus.mobilePluginStarted) {
+ context.read<BookingDetailsBloc>().add(SetupEndpoint());
+ }
+ if (state.status == BookingDetailsStatus.setupError) {
+ ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
+ content: Text('Failed to start Mobile Keys Plugin')));
+ context.read<BookingDetailsBloc>().add(SetupEndpoint());
+ }
+ if (state.status == BookingDetailsStatus.setupComplete) {
+ context
+ .read<BookingDetailsBloc>()
+ .add(const ProvisionKeyEvent("Hotel123"));
+ }
+ if (state.status == BookingDetailsStatus.keyProvisioned) {
+ context.read<BookingDetailsBloc>().add(const SearchForKeysEvent());
+ }
+ },
+ builder: (context, state) {
+ if (state.status == BookingDetailsStatus.unknown) {
+ context.read<BookingDetailsBloc>().add(InitialEvent());
+ }
+ if (state.status == BookingDetailsStatus.invalidOrNoKey) {
+ //context.read<HomeBloc>().add(const ProvisionKeyEvent("Hotel123"));
+ }
+ return Scaffold(
+ extendBodyBehindAppBar: true,
+ backgroundColor: sandColor[40],
+ appBar: const ComwellAppBar(),
+ body: Container(
+ decoration: const BoxDecoration(
+ image: DecorationImage(
+ image: AssetImage('assets/images/booking_background.png'),
+ fit: BoxFit.cover,
+ ),
+ ),
+ child: Stack(
+ alignment: Alignment.center,
+ children: [
+ Column(
+ crossAxisAlignment: CrossAxisAlignment.center,
+ mainAxisAlignment: MainAxisAlignment.center,
+ children: [
+ const Spacer(),
+ RoomKeyWidget(onPressed: () {
+ context.pushNamed(AppRoutes.contact.name);
+ }),
+ if (state.status == BookingDetailsStatus.invalidOrNoKey)
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: ElevatedButton(
+ onPressed: () {
+ context.read<BookingDetailsBloc>().add(
+ const SearchForKeysEvent(
+ endpointNeedsUpdate: true));
+ },
+ child: const Text('Get Key')),
+ ),
+ if (state.status == BookingDetailsStatus.validKey ||
+ state.status == BookingDetailsStatus.multipleKeys)
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: SliderButton(
+ backgroundColor: sandColor,
+ width: 300,
+ icon: Center(
+ child: SvgPicture.asset(
+ 'assets/icons/Union.svg',
+ width: 30,
+ ),
+ ),
+ action: () async {
+ context.pushNamed(AppRoutes.key.name);
+ return false;
+ },
+ alignLabel: Alignment.center,
+ label: Text(
+ 'open_room'.tr(),
+ style: theme.textTheme.headlineSmall
+ ?.copyWith(color: Colors.white),
+ textAlign: TextAlign.center,
+ ),
+ ),
+ ),
+ const SizedBox(
+ height: 220,
+ ),
+ ],
+ ),
+ BottomSheetWidget(
+ widgetChildren: [
+ const SizedBox(
+ height: 10,
+ width: double.infinity,
+ ),
+ const Text('Rooms'),
+ const SizedBox(height: 12),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ child: HousekeepingButton(
+ key: ValueKey(state.isHouseKeepingOrdered)),
+ ),
+ const SizedBox(height: 12),
+ ElevatedButton(
+ onPressed: () {
+ context.pushNamed(AppRoutes.checkIn.name,
+ pathParameters: {"booking_id": "hello world"});
+ },
+ style: ButtonStyle(
+ backgroundColor:
+ WidgetStateProperty.resolveWith((states) {
+ if (states.contains(WidgetState.disabled)) {
+ return Colors.grey;
+ }
+ return const Color(0xffAA8D65);
+ }),
+ foregroundColor:
+ const WidgetStatePropertyAll(Colors.white)),
+ child: const Padding(
+ padding: EdgeInsets.symmetric(vertical: 16.0),
+ child: Text("Klargør dit værelse"),
+ ),
+ ),
+ const Text('Keys'),
+ const SizedBox(height: 400),
+ ],
+ )
+ ],
+ ),
+ ),
+ );
+ },
+ );
+
+ /* listener: (context, state) {
+
+
+ },
+ builder: (context, state) {
+ return RefreshIndicator(
+ key: _refreshIndicatorKey,
+ displacement: 20,
+ onRefresh: () async {
+ return await _updateEndpoint();
+ },
+ child: Scaffold(
+ extendBodyBehindAppBar: true,
+ appBar: const ComwellAppBar(
+ shouldShowAppBar: true,
+ )
+ ,
+ body: Column(
+ mainAxisAlignment: MainAxisAlignment.start,
+ children: <Widget>[
+ Expanded(
+ child: Image.asset(
+ 'assets/images/welcome_image.jpeg',
+ width: double.infinity,
+ height: 300,
+ fit: BoxFit.cover,
+ )),
+ const SizedBox(height: 100),
+ if (state is CodeNotRedeemed)
+ ElevatedButton(
+ onPressed: () {
+ context.goNamed( AppRoutes.redeem.name);
+ },
+ child: Text('redeem_code'.tr()),
+ )
+ else if (state is ValidKey)
+ RoomKeyWidget(onPressed: () {
+ context.goNamed(AppRoutes.key.name);
+ })
+ else if (state is InvalidOrNoKey)
+ RoomKeyWidget(isMultipleKeys: true,onPressed: () {
+ context.goNamed(AppRoutes.key.name);
+ })
+ else if (state is MultipleKeys)
+ RoomKeyWidget(isMultipleKeys: true,onPressed: () {
+ context.goNamed(AppRoutes.key.name);
+ }),
+ ElevatedButton(
+
+ onPressed: () => _refreshIndicatorKey.currentState?.show(), child: const Text("refresh")),
+ ElevatedButton(onPressed: () => context.goNamed( AppRoutes.redeem.name), child: const Text("Go to redeem")),
+ const SizedBox(height: 100)
+ ],
+ ),
+ ));
+ }); */
+ /* body: ListView(
+ children: _menuList(context),
+ ), */
+
+ /* onFocusGained: () {
+ if (_toCredentials) _seosMobileKeysPlugin.stopIfScanning();
+ _toCredentials = false;
+ }, */
+ }
+}
diff --git a/comwell_key_app/lib/booking_details/booking_details_repository.dart b/comwell_key_app/lib/booking_details/booking_details_repository.dart
new file mode 100644
index 00000000..3753498e
--- /dev/null
+++ b/comwell_key_app/lib/booking_details/booking_details_repository.dart
@@ -0,0 +1,26 @@
+import 'package:comwell_key_app/housekeeping/housekeeping_repository.dart';
+import 'package:comwell_key_app/services/api.dart';
+import 'package:comwell_key_app/utils/secure_storage.dart';
+
+class BookingDetailsRepository {
+ final api = Api();
+ final secureStorage = SecureStorage();
+
+ Future<bool> isHousesKeepingOrdered() async {
+ final lastOrderedValue = await secureStorage.read(HouseKeepingRepository.houseKeepingLastOrderedKey);
+ if (lastOrderedValue != null) {
+ final lastOrdered =
+ DateTime.fromMillisecondsSinceEpoch(int.parse(lastOrderedValue));
+ final dayOfLastOrder = lastOrdered.day;
+ final dayOfToday = DateTime.now().day;
+ final timeOfToday = DateTime.now().hour;
+ return dayOfToday > dayOfLastOrder &&
+ timeOfToday > 2; // If it's after 3am on the day after the order
+ }
+ return false;
+ }
+
+ Future<String?> doesInvitationCodeExist(String key) async {
+ return await secureStorage.read(key);
+ }
+}
diff --git a/comwell_key_app/lib/booking_details/components/housekeeping_button.dart b/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
new file mode 100644
index 00000000..df482174
--- /dev/null
+++ b/comwell_key_app/lib/booking_details/components/housekeeping_button.dart
@@ -0,0 +1,80 @@
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:flutter_svg/svg.dart';
+import 'package:go_router/go_router.dart';
+
+import '../../routing/app_routes.dart';
+import '../../themes/dark_theme.dart';
+import '../bloc/booking_details_bloc.dart';
+
+class HousekeepingButton extends StatelessWidget {
+ const HousekeepingButton({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ final bloc = context.read<BookingDetailsBloc>();
+ return InkWell(
+ borderRadius: BorderRadius.circular(10),
+ onTap: () async {
+ if (bloc.state.isHouseKeepingOrdered) return;
+ await context.pushNamed(AppRoutes.houseKeeping.name);
+ bloc.add(CheckIfHouseKeepingOrdered());
+ },
+ child: Container(
+ decoration: BoxDecoration(
+ border: Border.all(
+ color: Colors.grey,
+ ),
+ borderRadius: BorderRadius.circular(10),
+ ),
+ child: Padding(
+ padding: const EdgeInsets.all(16.0),
+ child: Row(
+ children: [
+ Container(
+ height: 36,
+ width: 36,
+ decoration: const BoxDecoration(
+ color: colorSecondary,
+ shape: BoxShape.circle,
+ ),
+ child: Padding(
+ padding: const EdgeInsets.all(10.0),
+ child: SvgPicture.asset(
+ "assets/icons/icon_housekeeping_cleaning.svg"),
+ ),
+ ),
+ const SizedBox(width: 12),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ "booking_details_page_housekeeping_button_title".tr(),
+ style: Theme.of(context).textTheme.headlineSmall,
+ maxLines: 1,
+ ),
+ Text(
+ "booking_details_page_housekeeping_button_subtitle".tr(),
+ maxLines: 1,
+ style: Theme.of(context)
+ .textTheme
+ .headlineSmall
+ ?.copyWith(color: Colors.grey),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(width: 12),
+ if (bloc.state.isHouseKeepingOrdered == true)
+ SvgPicture.asset("assets/icons/ic_checkmark.svg")
+ else
+ SvgPicture.asset("assets/icons/arrow-left.svg")
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/comwell_key_app/lib/booking_details/components/room_key_widget.dart b/comwell_key_app/lib/booking_details/components/room_key_widget.dart
new file mode 100644
index 00000000..73a29884
--- /dev/null
+++ b/comwell_key_app/lib/booking_details/components/room_key_widget.dart
@@ -0,0 +1,67 @@
+// ignore_for_file: must_be_immutable
+
+import 'package:comwell_key_app/themes/light_theme.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+
+class RoomKeyWidget extends StatelessWidget {
+ RoomKeyWidget({super.key, this.isMultipleKeys = false, required this.onPressed});
+ bool isMultipleKeys = false;
+ Function onPressed;
+
+ @override
+ Widget build(BuildContext context) {
+ return Card(
+ elevation: 5,
+ color: sandColor[20],
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(10),
+ ),
+ child: InkWell(
+ onTap: () {
+ if (isMultipleKeys) {
+ // Navigate to multiple keys page
+ } else {
+ onPressed();
+ }
+ },
+ child: Container (
+ width: 150,
+ height: 150,
+ padding: const EdgeInsets.all(8),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+
+ children: [
+ Container(
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: sandColor[40],
+ ),
+ padding: const EdgeInsets.all(8),
+ child: ImageIcon(
+ const AssetImage('assets/images/key.png'),
+ size: 24,
+ color: Theme.of(context).colorScheme.onSecondary,
+ ),
+ ),
+ const SizedBox(height: 20),
+ Text(
+ isMultipleKeys ? 'room_keys'.tr() :'room_key'.tr(),
+ style: const TextStyle(
+ fontSize: 16,
+ fontWeight: FontWeight.bold,
+ ),
+ ),
+ const SizedBox(height: 5),
+ Text('room_key_description'.tr(),
+ style: TextStyle(
+ fontSize: 12,
+ color: Theme.of(context).colorScheme.onSecondary,
+ ),
+ )],
+ ),
+ ),
+ ));
+ }
+}
\ No newline at end of file
diff --git a/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart b/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart
index 8df22217..60afb7b3 100644
--- a/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart
+++ b/comwell_key_app/lib/check_in/bloc/check_in_cubit.dart
@@ -2,9 +2,11 @@ import 'package:bloc/bloc.dart';
import 'package:comwell_key_app/check_in/bloc/check_in_state.dart';
import 'package:comwell_key_app/check_in/check_in_repository.dart';
import 'package:comwell_key_app/overview/models/booking.dart';
+import 'package:comwell_key_app/utils/seos_repository.dart';
class CheckInCubit extends Cubit<CheckInState> {
- final CheckInRepository checkInRepository = CheckInRepository();
+ final _checkInRepository = CheckInRepository();
+ final _seosRepository = SeosRepository();
final String bookingId;
late final Booking booking;
@@ -16,7 +18,7 @@ class CheckInCubit extends Cubit<CheckInState> {
void getBooking() async {
emit(state.setLoading(true));
try {
- booking = await checkInRepository.getBooking(bookingId);
+ booking = await _checkInRepository.getBooking(bookingId);
emit(state.setLoading(false));
startLoading();
} catch (err) {
@@ -28,11 +30,12 @@ class CheckInCubit extends Cubit<CheckInState> {
try {
await Future<void>.delayed(const Duration(seconds: 1));
emit(state.checkInStatusLoading());
- await checkInRepository.checkIn(booking.confirmationId);
+ await _checkInRepository.checkIn(booking.confirmationId);
emit(state.checkInStatusRoomFound(roomNumber: booking.roomNumber));
- await Future<void>.delayed(const Duration(seconds: 1));
+ await _seosRepository.refreshKeys();
emit(state.checkInStatusYourDigitalCard(roomNumber: booking.roomNumber));
- }catch(err){
+ } catch (err, st) {
+ print("qqq err=$err, $st");
emit(state.setLoading(false));
emit(state.checkInStatusError(Exception(err.toString())));
}
diff --git a/comwell_key_app/lib/check_in/check_in_repository.dart b/comwell_key_app/lib/check_in/check_in_repository.dart
index 25924737..73c2fbc3 100644
--- a/comwell_key_app/lib/check_in/check_in_repository.dart
+++ b/comwell_key_app/lib/check_in/check_in_repository.dart
@@ -16,30 +16,33 @@ class CheckInRepository {
}
Future<Booking> getBooking(String bookingId) async {
- return Booking(
- id: "helloworld",
- userId: "123",
- roomNumber: "1234",
- startDate: DateTime.now(),
- endDate: DateTime.now(),
- status: BookingStatus.current,
- image: "",
- hotelName: "hotelName",
- roomType: "roomType",
- children: 0,
- adults: 2,
- hotelCode: "hotelCode",
- booker: "booker",
- bookingDate: DateTime.now(),
- paymentDetails: const PaymentDetails(
- cardNumber: "cardNumber",
- cardHolder: "cardHolder",
- expiryDate: "expiryDate",
- cvc: "cvc",
- cardType: CardType.visa),
- );
+ return mockBooking;
final entity = await db.bookingsDao.getBooking(bookingId);
final Json json = jsonDecode(entity.json) as Json;
return Booking.fromJson(json);
}
+
+ static final mockBooking = Booking(
+ id: "helloworld",
+ userId: "123",
+ roomNumber: "1234",
+ startDate: DateTime.now(),
+ endDate: DateTime.now(),
+ status: BookingStatus.current,
+ image: "",
+ hotelName: "hotelName",
+ roomType: "roomType",
+ confirmationId: "",
+ children: 0,
+ adults: 2,
+ hotelCode: "hotelCode",
+ booker: "booker",
+ bookingDate: DateTime.now(),
+ paymentDetails: const PaymentDetails(
+ cardNumber: "cardNumber",
+ cardHolder: "cardHolder",
+ expiryDate: "expiryDate",
+ cvc: "cvc",
+ cardType: CardType.visa),
+ );
}
diff --git a/comwell_key_app/lib/comwell_app.dart b/comwell_key_app/lib/comwell_app.dart
index 1b7ac184..62a8b609 100644
--- a/comwell_key_app/lib/comwell_app.dart
+++ b/comwell_key_app/lib/comwell_app.dart
@@ -1,7 +1,7 @@
import 'package:comwell_key_app/authentication/authentication_repository.dart';
import 'package:comwell_key_app/authentication/bloc/authentication_bloc.dart';
-import 'package:comwell_key_app/home/bloc/home_bloc.dart';
-import 'package:comwell_key_app/home/home_repository.dart';
+import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
+import 'package:comwell_key_app/booking_details/booking_details_repository.dart';
import 'package:comwell_key_app/key/bloc/key_bloc.dart';
import 'package:comwell_key_app/key/repository/key_repository.dart';
import 'package:comwell_key_app/overview/cubit/overview_cubit.dart';
@@ -14,21 +14,23 @@ import 'package:comwell_key_app/routing/app_router.dart';
import 'package:comwell_key_app/themes/dark_theme.dart';
import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:comwell_key_app/utils/locator.dart';
+import 'package:comwell_key_app/utils/seos_repository.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class ComwellApp extends StatelessWidget {
- final AuthenticationBloc authBloc =
- AuthenticationBloc(authenticationRepository: AuthenticationRepository());
+ final AuthenticationBloc authBloc = AuthenticationBloc(authenticationRepository: locator<AuthenticationRepository>());
ComwellApp({super.key});
@override
Widget build(BuildContext context) {
+ authBloc.post();
+ print("qqq build App");
return BlocProvider<AuthenticationBloc>(
- create: (context) => authBloc..add(AuthenticationSubscriptionRequested()),
+ create: (context) => authBloc,
child: MultiBlocProvider(
providers: blocProviderList,
child: MaterialApp.router(
@@ -47,16 +49,12 @@ class ComwellApp extends StatelessWidget {
}
final List<BlocProvider> blocProviderList = [
- BlocProvider<HomeBloc>(
- lazy: false,
- create: (BuildContext context) =>
- HomeBloc(homeRepository: locator<HomeRepository>()),
- ),
BlocProvider<KeyBloc>(
lazy: true,
create: (BuildContext context) => KeyBloc(
keyRepository: locator<KeyRepository>(),
- homeRepository: locator<HomeRepository>()),
+ seosRepository: locator<SeosRepository>(),
+ bookingDetailsRepository: locator<BookingDetailsRepository>()),
),
BlocProvider<OverviewCubit>(
lazy: true,
diff --git a/comwell_key_app/lib/home/bloc/home_bloc.dart b/comwell_key_app/lib/home/bloc/home_bloc.dart
deleted file mode 100644
index 3e8311a3..00000000
--- a/comwell_key_app/lib/home/bloc/home_bloc.dart
+++ /dev/null
@@ -1,112 +0,0 @@
-import 'package:bloc/bloc.dart';
-import 'package:equatable/equatable.dart';
-import 'package:flutter/foundation.dart';
-import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
-import 'package:comwell_key_app/home/home_repository.dart';
-
-part 'home_event.dart';
-
-part 'home_state.dart';
-
-class HomeBloc extends Bloc<HomeEvent, HomeState> {
- final HomeRepository homeRepository;
-
- HomeBloc({required this.homeRepository}) : super(HomeState.initial()) {
- on<HomeInitialEvent>((event, emit) async {
- emit(state.setupStarted());
- await checkIfHouseKeepingOrdered(emit);
- try {
- if (kIsWeb) {
- emit(state.setupComplete());
- return;
- }
- final isEndPointSetup = await homeRepository.startMobilePlugin();
- if (isEndPointSetup) {
- emit(state.setupComplete());
- } else {
- emit(state.mobilePluginStarted());
- SetupEndpoint();
- }
- } catch (_) {
- emit(state.setupError());
- }
- });
-
- on<SetupEndpoint>((event, emit) async {
- emit(state.setupStarted());
- try {
- if (kIsWeb) {
- emit(state.setupComplete());
- return;
- }
- await homeRepository.setupEndpoint();
- emit(state.setupComplete());
- } catch (_) {
- emit(state.setupError());
- }
- });
-
- on<SearchForKeysEvent>((event, emit) async {
- if (kIsWeb) {
- emit(state.invalidOrNoKey());
- return;
- }
- // this is set because there is a bit and issue with updating the endpoint first and second time it is run! will fix this later and remove it
- if (event.endpointNeedsUpdate) {
- await homeRepository.updateEndpoint();
- }
- //await homeRepository.updateEndpoint();
- final List<MobileKeysKey> keys = await homeRepository.refreshKeys();
- if (keys.length == 1) {
- emit(state.validKey(keys[0]));
- } else if (keys.length > 1) {
- emit(state.multipleKeys(keys));
- } else {
- emit(state.invalidOrNoKey());
- }
- });
-
- on<ProvisionKeyEvent>((event, emit) async {
- if (kIsWeb) {
- emit(state.keyProvisioned());
- return;
- }
- try {
- await homeRepository.provisionKey(event.bookingId,
- forceProvision: true);
-
- emit(state.keyProvisioned());
- } catch (_) {
- emit(state.setupError());
- }
- });
-
- on<CheckIfHouseKeepingOrdered>((event, emit) async {
- await checkIfHouseKeepingOrdered(emit);
- });
- }
-
- Future<void> checkIfHouseKeepingOrdered(Emitter<HomeState> emit) async {
- final isHouseKeepingOrdered = await homeRepository.isHousesKeepingOrdered();
- if (isHouseKeepingOrdered) {
- emit(state.houseKeepingOrdered());
- }
- }
-}
-
-/* if (isEndpointSetup) {
- List<MobileKeysKey?>? keys = await homeRepository.refreshKeys();
- if(keys != null) {
- if(keys.length == 1) {
- emit(ValidKey(keys[0]!));
- } else if(keys.length > 1) {
- emit(MultipleKeys(keys as List<MobileKeysKey>));
- } else {
- emit(InvalidOrNoKey());
- }
- } else {
- emit(InvalidOrNoKey());
- }
- } else {
- emit(CodeNotRedeemed());
- } */
diff --git a/comwell_key_app/lib/home/bloc/home_event.dart b/comwell_key_app/lib/home/bloc/home_event.dart
deleted file mode 100644
index abe8244e..00000000
--- a/comwell_key_app/lib/home/bloc/home_event.dart
+++ /dev/null
@@ -1,50 +0,0 @@
-part of 'home_bloc.dart';
-
-sealed class HomeEvent extends Equatable {
- const HomeEvent();
-
- @override
- List<Object> get props => [];
-}
-
-final class HomeInitialEvent extends HomeEvent {}
-
-final class CodeEnteredEvent extends HomeEvent {
- final String code;
-
- const CodeEnteredEvent(this.code);
-
- @override
- List<Object> get props => [code];
-}
-
-final class SearchForKeysEvent extends HomeEvent {
- final bool endpointNeedsUpdate;
-
- const SearchForKeysEvent({this.endpointNeedsUpdate = false});
-
- @override
- List<Object> get props => [];
-}
-
-final class SetupEndpoint extends HomeEvent {}
-
-final class KeySelectedEvent extends HomeEvent {
- final String key;
-
- const KeySelectedEvent(this.key);
-
- @override
- List<Object> get props => [key];
-}
-
-final class CheckIfHouseKeepingOrdered extends HomeEvent {}
-
-final class ProvisionKeyEvent extends HomeEvent {
- final String bookingId;
-
- const ProvisionKeyEvent(this.bookingId);
-
- @override
- List<Object> get props => [bookingId];
-}
diff --git a/comwell_key_app/lib/home/bloc/home_state.dart b/comwell_key_app/lib/home/bloc/home_state.dart
deleted file mode 100644
index 72c47e12..00000000
--- a/comwell_key_app/lib/home/bloc/home_state.dart
+++ /dev/null
@@ -1,62 +0,0 @@
-part of 'home_bloc.dart';
-
-class HomeState extends Equatable {
-
- final bool isHouseKeepingOrdered;
- final HomeStatus status;
- final MobileKeysKey? key;
- final List<MobileKeysKey> keys;
-
- const HomeState._({required this.status, required this.key, required this.keys, required this.isHouseKeepingOrdered});
-
- HomeState.initial() : this._(status: HomeStatus.unknown, key: null, keys: [], isHouseKeepingOrdered: false);
- HomeState setupStarted() => copyWith(status: HomeStatus.setupStarted);
- HomeState setupComplete() => copyWith(status: HomeStatus.setupComplete);
- HomeState mobilePluginStarted() => copyWith(status: HomeStatus.mobilePluginStarted);
- HomeState invalidOrNoKey() => copyWith(status: HomeStatus.invalidOrNoKey);
- HomeState keyProvisioned() => copyWith(status: HomeStatus.keyProvisioned);
- HomeState multipleKeys(List<MobileKeysKey> keys) => copyWith(status: HomeStatus.multipleKeys, keys: keys);
- HomeState setupNotComplete() => copyWith(status: HomeStatus.setupNotComplete);
- HomeState setupError() => copyWith(status: HomeStatus.setupError);
- HomeState validKey(MobileKeysKey key) => copyWith(status: HomeStatus.validKey, key: key);
- HomeState houseKeepingOrdered() => copyWith(status: HomeStatus.houseKeepingOrdered, isHouseKeepingOrdered: true);
- HomeState main() => copyWith(status: HomeStatus.main);
-
- @override
- List<Object?> get props => [status];
-
- HomeState copyWith({
- HomeStatus? status,
- MobileKeysKey? key,
- List<MobileKeysKey>? keys,
- bool? isHouseKeepingOrdered,
- }) {
- return HomeState._(
- status: status ?? this.status,
- key: key ?? this.key,
- keys: keys ?? this.keys,
- isHouseKeepingOrdered: isHouseKeepingOrdered ?? this.isHouseKeepingOrdered,
- );
- }
-
- @override
- String toString() {
- return "HomeState(status=$status, key=$key, keys=$keys, isHouseKeepingOrdered=$isHouseKeepingOrdered)";
- }
-}
-
-enum HomeStatus {
- unknown,
- setupStarted,
- setupComplete,
- setupError,
- setupNotComplete,
- firstLaunch,
- mobilePluginStarted,
- multipleKeys,
- validKey,
- invalidOrNoKey,
- main,
- keyProvisioned,
- houseKeepingOrdered
-}
diff --git a/comwell_key_app/lib/home/components/housekeeping_button.dart b/comwell_key_app/lib/home/components/housekeeping_button.dart
deleted file mode 100644
index 7985cf05..00000000
--- a/comwell_key_app/lib/home/components/housekeeping_button.dart
+++ /dev/null
@@ -1,80 +0,0 @@
-import 'package:easy_localization/easy_localization.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
-import 'package:flutter_svg/svg.dart';
-import 'package:go_router/go_router.dart';
-
-import '../../routing/app_routes.dart';
-import '../../themes/dark_theme.dart';
-import '../bloc/home_bloc.dart';
-
-class HousekeepingButton extends StatelessWidget {
- const HousekeepingButton({super.key});
-
- @override
- Widget build(BuildContext context) {
- final bloc = context.read<HomeBloc>();
- return InkWell(
- borderRadius: BorderRadius.circular(10),
- onTap: () async {
- if (bloc.state.isHouseKeepingOrdered) return;
- await context.pushNamed(AppRoutes.houseKeeping.name);
- bloc.add(CheckIfHouseKeepingOrdered());
- },
- child: Container(
- decoration: BoxDecoration(
- border: Border.all(
- color: Colors.grey,
- ),
- borderRadius: BorderRadius.circular(10),
- ),
- child: Padding(
- padding: const EdgeInsets.all(16.0),
- child: Row(
- children: [
- Container(
- height: 36,
- width: 36,
- decoration: const BoxDecoration(
- color: colorSecondary,
- shape: BoxShape.circle,
- ),
- child: Padding(
- padding: const EdgeInsets.all(10.0),
- child: SvgPicture.asset(
- "assets/icons/icon_housekeeping_cleaning.svg"),
- ),
- ),
- const SizedBox(width: 12),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Text(
- "home_page_housekeeping_button_title".tr(),
- style: Theme.of(context).textTheme.headlineSmall,
- maxLines: 1,
- ),
- Text(
- "home_page_housekeeping_button_subtitle".tr(),
- maxLines: 1,
- style: Theme.of(context)
- .textTheme
- .headlineSmall
- ?.copyWith(color: Colors.grey),
- ),
- ],
- ),
- ),
- const SizedBox(width: 12),
- if (bloc.state.isHouseKeepingOrdered == true)
- SvgPicture.asset("assets/icons/ic_checkmark.svg")
- else
- SvgPicture.asset("assets/icons/arrow-left.svg")
- ],
- ),
- ),
- ),
- );
- }
-}
diff --git a/comwell_key_app/lib/home/components/room_key_widget.dart b/comwell_key_app/lib/home/components/room_key_widget.dart
deleted file mode 100644
index 73a29884..00000000
--- a/comwell_key_app/lib/home/components/room_key_widget.dart
+++ /dev/null
@@ -1,67 +0,0 @@
-// ignore_for_file: must_be_immutable
-
-import 'package:comwell_key_app/themes/light_theme.dart';
-import 'package:easy_localization/easy_localization.dart';
-import 'package:flutter/material.dart';
-
-class RoomKeyWidget extends StatelessWidget {
- RoomKeyWidget({super.key, this.isMultipleKeys = false, required this.onPressed});
- bool isMultipleKeys = false;
- Function onPressed;
-
- @override
- Widget build(BuildContext context) {
- return Card(
- elevation: 5,
- color: sandColor[20],
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(10),
- ),
- child: InkWell(
- onTap: () {
- if (isMultipleKeys) {
- // Navigate to multiple keys page
- } else {
- onPressed();
- }
- },
- child: Container (
- width: 150,
- height: 150,
- padding: const EdgeInsets.all(8),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
-
- children: [
- Container(
- decoration: BoxDecoration(
- shape: BoxShape.circle,
- color: sandColor[40],
- ),
- padding: const EdgeInsets.all(8),
- child: ImageIcon(
- const AssetImage('assets/images/key.png'),
- size: 24,
- color: Theme.of(context).colorScheme.onSecondary,
- ),
- ),
- const SizedBox(height: 20),
- Text(
- isMultipleKeys ? 'room_keys'.tr() :'room_key'.tr(),
- style: const TextStyle(
- fontSize: 16,
- fontWeight: FontWeight.bold,
- ),
- ),
- const SizedBox(height: 5),
- Text('room_key_description'.tr(),
- style: TextStyle(
- fontSize: 12,
- color: Theme.of(context).colorScheme.onSecondary,
- ),
- )],
- ),
- ),
- ));
- }
-}
\ No newline at end of file
diff --git a/comwell_key_app/lib/home/home_page.dart b/comwell_key_app/lib/home/home_page.dart
deleted file mode 100644
index 11f4db6e..00000000
--- a/comwell_key_app/lib/home/home_page.dart
+++ /dev/null
@@ -1,229 +0,0 @@
-import 'package:comwell_key_app/common/components/bottom_sheet_widget.dart';
-import 'package:comwell_key_app/common/components/comwell_app_bar.dart';
-import 'package:comwell_key_app/home/bloc/home_bloc.dart';
-import 'package:comwell_key_app/home/components/housekeeping_button.dart';
-import 'package:comwell_key_app/home/components/room_key_widget.dart';
-import 'package:comwell_key_app/routing/app_routes.dart';
-import 'package:comwell_key_app/themes/light_theme.dart';
-import 'package:easy_localization/easy_localization.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter_bloc/flutter_bloc.dart';
-import 'package:flutter_svg/flutter_svg.dart';
-import 'package:go_router/go_router.dart';
-import 'package:slider_button/slider_button.dart';
-
-class HomeWidget extends StatefulWidget {
- const HomeWidget({super.key});
-
- @override
- State<StatefulWidget> createState() => _HomeWidget();
-}
-
-class _HomeWidget extends State<HomeWidget> {
- @override
- void initState() {
- super.initState();
- }
-
- @override
- Widget build(BuildContext context) {
- final theme = Theme.of(context);
- return BlocConsumer<HomeBloc, HomeState>(
- listener: (context, state) {
- if (state.status == HomeStatus.mobilePluginStarted) {
- context.read<HomeBloc>().add(SetupEndpoint());
- }
- if (state.status == HomeStatus.setupError) {
- ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
- content: Text('Failed to start Mobile Keys Plugin')));
- context.read<HomeBloc>().add(SetupEndpoint());
- }
- if (state.status == HomeStatus.setupComplete) {
- context.read<HomeBloc>().add(const ProvisionKeyEvent("Hotel123"));
- }
- if (state.status == HomeStatus.keyProvisioned) {
- context.read<HomeBloc>().add(const SearchForKeysEvent());
- }
- },
- builder: (context, state) {
- if (state.status == HomeStatus.unknown) {
- context.read<HomeBloc>().add(HomeInitialEvent());
- }
- if (state.status == HomeStatus.invalidOrNoKey) {
- //context.read<HomeBloc>().add(const ProvisionKeyEvent("Hotel123"));
- }
- return Scaffold(
- extendBodyBehindAppBar: true,
- backgroundColor: sandColor[40],
- appBar: const ComwellAppBar(),
- body: Container(
- decoration: const BoxDecoration(
- image: DecorationImage(
- image: AssetImage('assets/images/booking_background.png'),
- fit: BoxFit.cover,
- ),
- ),
- child: Stack(
- alignment: Alignment.center,
- children: [
- Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- const Spacer(),
- RoomKeyWidget(onPressed: () {
- context.pushNamed(AppRoutes.contact.name);
- }),
- if (state.status == HomeStatus.invalidOrNoKey)
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: ElevatedButton(
- onPressed: () {
- context.read<HomeBloc>().add(
- const SearchForKeysEvent(
- endpointNeedsUpdate: true));
- },
- child: const Text('Get Key')),
- ),
- if(state.status == HomeStatus.validKey ||
- state.status == HomeStatus.multipleKeys)
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: SliderButton(
- backgroundColor: sandColor,
- width: 300,
- icon: Center(
- child: SvgPicture.asset(
- 'assets/icons/Union.svg',
- width: 30,
- ),
- ),
- action: () async {
- context.pushNamed(AppRoutes.key.name);
- return false;
- },
- alignLabel: Alignment.center,
- label: Text(
- 'open_room'.tr(),
- style: theme.textTheme.headlineSmall
- ?.copyWith(color: Colors.white),
- textAlign: TextAlign.center,
- ),
- ),
- ),
- const SizedBox(
- height: 220,
- ),
- ],
- ),
- BottomSheetWidget(
- widgetChildren: [
- const SizedBox(
- height: 10,
- width: double.infinity,
- ),
- const Text('Rooms'),
- const SizedBox(height: 12),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16.0),
- child: HousekeepingButton(key: ValueKey(state.isHouseKeepingOrdered)),
- ),
- const SizedBox(height: 12),
- ElevatedButton(
- onPressed: () {
- context.pushNamed(AppRoutes.checkIn.name, pathParameters: {
- "booking_id": "hello world"
- });
- },
- style: ButtonStyle(
- backgroundColor:
- WidgetStateProperty.resolveWith((states) {
- if (states.contains(WidgetState.disabled)) {
- return Colors.grey;
- }
- return const Color(0xffAA8D65);
- }),
- foregroundColor:
- const WidgetStatePropertyAll(Colors.white)),
- child: const Padding(
- padding: EdgeInsets.symmetric(vertical: 16.0),
- child: Text("Klargør dit værelse"),
- ),
- ),
- const Text('Keys'),
- const SizedBox(height: 400),
- ],
- )
- ],
- ),
- ),
- );
- },
- );
-
- /* listener: (context, state) {
-
-
- },
- builder: (context, state) {
- return RefreshIndicator(
- key: _refreshIndicatorKey,
- displacement: 20,
- onRefresh: () async {
- return await _updateEndpoint();
- },
- child: Scaffold(
- extendBodyBehindAppBar: true,
- appBar: const ComwellAppBar(
- shouldShowAppBar: true,
- )
- ,
- body: Column(
- mainAxisAlignment: MainAxisAlignment.start,
- children: <Widget>[
- Expanded(
- child: Image.asset(
- 'assets/images/welcome_image.jpeg',
- width: double.infinity,
- height: 300,
- fit: BoxFit.cover,
- )),
- const SizedBox(height: 100),
- if (state is CodeNotRedeemed)
- ElevatedButton(
- onPressed: () {
- context.goNamed( AppRoutes.redeem.name);
- },
- child: Text('redeem_code'.tr()),
- )
- else if (state is ValidKey)
- RoomKeyWidget(onPressed: () {
- context.goNamed(AppRoutes.key.name);
- })
- else if (state is InvalidOrNoKey)
- RoomKeyWidget(isMultipleKeys: true,onPressed: () {
- context.goNamed(AppRoutes.key.name);
- })
- else if (state is MultipleKeys)
- RoomKeyWidget(isMultipleKeys: true,onPressed: () {
- context.goNamed(AppRoutes.key.name);
- }),
- ElevatedButton(
-
- onPressed: () => _refreshIndicatorKey.currentState?.show(), child: const Text("refresh")),
- ElevatedButton(onPressed: () => context.goNamed( AppRoutes.redeem.name), child: const Text("Go to redeem")),
- const SizedBox(height: 100)
- ],
- ),
- ));
- }); */
- /* body: ListView(
- children: _menuList(context),
- ), */
-
- /* onFocusGained: () {
- if (_toCredentials) _seosMobileKeysPlugin.stopIfScanning();
- _toCredentials = false;
- }, */
- }
-}
diff --git a/comwell_key_app/lib/home/home_repository.dart b/comwell_key_app/lib/home/home_repository.dart
deleted file mode 100644
index 7f3dceea..00000000
--- a/comwell_key_app/lib/home/home_repository.dart
+++ /dev/null
@@ -1,125 +0,0 @@
-import 'package:comwell_key_app/housekeeping/housekeeping_repository.dart';
-import 'package:comwell_key_app/services/api.dart';
-import 'package:comwell_key_app/utils/secure_storage.dart';
-import 'package:comwell_key_app/utils/singleton.dart';
-import 'package:dio/dio.dart';
-import 'package:flutter/services.dart';
-import 'package:flutter_dotenv/flutter_dotenv.dart';
-import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
-import 'package:comwell_key_app/common/const.dart' as constants;
-
-class HomeRepository {
- final _seosMobileKeysPlugin = Singleton().seosMobileKeysPlugin;
- final api = Api();
- final secureStorage = SecureStorage();
-
- Future<bool> isEndpointSetup({bool firstLaunch = true}) async {
- try {
- return await _seosMobileKeysPlugin.isEndpointSetup();
- } catch (e) {
- throw Exception('Failed to check if endpoint setup - ${e.toString()}');
- }
- }
-
- Future<bool> updateEndpoint() async {
- try {
- await _seosMobileKeysPlugin.updateEndpoint();
- return true;
- } catch (e) {
- throw Exception('Failed to update endpoint - ${e.toString()}');
- }
- }
-
- Future<List<MobileKeysKey>> refreshKeys() async {
- try {
- //await updateEndpoint();
- final List<MobileKeysKey> listOfKeys =
- await _seosMobileKeysPlugin.listMobileKeys();
- await secureStorage.write(constants.hasKey, DateTime.now().toString());
- return listOfKeys;
- } catch (e) {
- throw Exception('Failed to list keys - ${e.toString()}');
- }
- }
-
- Future<bool> isHousesKeepingOrdered() async {
- final lastOrderedValue = await secureStorage.read(HouseKeepingRepository.houseKeepingLastOrderedKey);
- print("lastOrderedValue: $lastOrderedValue");
- if (lastOrderedValue != null) {
- return true;
- final lastOrdered =
- DateTime.fromMillisecondsSinceEpoch(int.parse(lastOrderedValue));
- final dayOfLastOrder = lastOrdered.day;
- final dayOfToday = DateTime.now().day;
- final timeOfToday = DateTime.now().hour;
-
- return dayOfToday > dayOfLastOrder &&
- timeOfToday > 2; // If it's after 3am on the day after the order
- }
- return false;
- }
-
- Future<void> setupEndpoint() async {
- try {
- final Response<dynamic> code = await api.createEndpointRegistration();
- await _seosMobileKeysPlugin
- .setupEndpoint(code.data['InvitationCode'] as String);
- await secureStorage.write(constants.isEndpointSetup, 'true');
- } catch (e) {
- throw Exception('Failed to setup endpoint - ${e.toString()}');
- }
- }
-
- Future<void> provisionKey(
- String bookingId, {
- bool forceProvision = false,
- }) async {
- try {
- final String? hasKey = await secureStorage.read(constants.hasKey);
- if (hasKey != null) {
- final DateTime hasKeyDate = DateTime.parse(hasKey);
- if (DateTime.now().difference(hasKeyDate).inDays < 1) {
- return;
- }
- }
-
- await api.provisionKey(bookingId);
- secureStorage.write(constants.hasKey, DateTime.now().toString());
- await updateEndpoint();
- } catch (e) {
- throw Exception('Failed to provision a key - ${e.toString()}');
- }
- }
-
- Future<bool> startMobilePlugin() async {
- final mobileKeysOptions = {
- "MobileKeysOptionApplicationId":
- dotenv.env['MOBILEKEYSOPTIONAPPLICATIONID'],
- "MobileKeysOptionAppDescription":
- dotenv.env['MOBILEKEYSOPTIONAPPDESCRIPTION'],
- "MobileKeysOptionVersion": dotenv.env['MOBILEKEYSOPTIONVERSION'],
- "MobileKeysOptionLockServiceCodes": [1],
- "MobileKeysOptionLogsMail": dotenv.env['MOBILEKEYSOPTIONLOGSMAIL'],
- };
-
- try {
- await _seosMobileKeysPlugin.startUp(mobileKeysOptions);
- final bool isendpointSetup =
- await _seosMobileKeysPlugin.isEndpointSetup();
- if (isendpointSetup) {
- updateEndpoint();
- return true;
- } else {
- return false;
- }
- } on PlatformException catch (e) {
- throw Exception('Failed to init MobileKeysManager - ${e.toString()}');
- } catch (_) {
- throw Exception('Failed to init start');
- }
- }
-
- Future<String?> doesInvitationCodeExist(String key) async {
- return await secureStorage.read(key);
- }
-}
diff --git a/comwell_key_app/lib/key/bloc/key_bloc.dart b/comwell_key_app/lib/key/bloc/key_bloc.dart
index cdeb42f3..efc3b696 100644
--- a/comwell_key_app/lib/key/bloc/key_bloc.dart
+++ b/comwell_key_app/lib/key/bloc/key_bloc.dart
@@ -1,30 +1,30 @@
import 'dart:core';
import 'package:bloc/bloc.dart';
-import 'package:comwell_key_app/home/home_repository.dart';
import 'package:comwell_key_app/key/repository/key_repository.dart';
+import 'package:comwell_key_app/utils/seos_repository.dart';
import 'package:equatable/equatable.dart';
import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
+import '../../booking_details/booking_details_repository.dart';
+
part 'key_event.dart';
+
part 'key_state.dart';
class KeyBloc extends Bloc<KeyEvent, KeyState> {
final KeyRepository keyRepository;
- final HomeRepository homeRepository;
+ final BookingDetailsRepository bookingDetailsRepository;
+ final SeosRepository seosRepository;
- KeyBloc({required this.keyRepository, required this.homeRepository})
+ KeyBloc({required this.seosRepository, required this.keyRepository, required this.bookingDetailsRepository})
: super(KeyState.unknown()) {
on<SearchForKeys>((event, emit) async {
emit(KeyState.searchForKeys());
try {
- List<MobileKeysKey?>? keys = await homeRepository.refreshKeys();
- if (keys != null) {
- emit(KeyState.validKeys(keys));
- add(const StartScanning());
- } else {
- emit(KeyState.searchForKeysError('Failed to list keys'));
- }
- } catch (e) {
+ final keys = await seosRepository.refreshKeys();
+ emit(KeyState.validKeys(keys));
+ add(const StartScanning());
+ } catch (e) {
emit(KeyState.searchForKeysError(e.toString()));
}
});
@@ -35,7 +35,7 @@ class KeyBloc extends Bloc<KeyEvent, KeyState> {
emit(KeyState.scanning());
//Timer.periodic(const Duration(seconds: 1), (timer) async {
- // await keyRepository.openClosestReader();
+ // await keyRepository.openClosestReader();
//keyRepository.stopScanning();
//emit(KeyState.openClosestReaderSuccess());
// });
diff --git a/comwell_key_app/lib/key/repository/key_repository.dart b/comwell_key_app/lib/key/repository/key_repository.dart
index 71d715c2..fd9a6fb2 100644
--- a/comwell_key_app/lib/key/repository/key_repository.dart
+++ b/comwell_key_app/lib/key/repository/key_repository.dart
@@ -18,8 +18,8 @@ class KeyRepository {
Future<void> checkDeviceInfo() async {
try {
if (Platform.isAndroid) {
- DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
- AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
+ final deviceInfo = DeviceInfoPlugin();
+ final androidInfo = await deviceInfo.androidInfo;
if (androidInfo.version.sdkInt >= 33) {
await Permission.bluetoothScan.request();
await Permission.bluetoothConnect.onGrantedCallback(() {
@@ -55,7 +55,7 @@ class KeyRepository {
}
}
- Future<void>? stopScanning() async {
+ Future<void> stopScanning() async {
try {
await seosMobileKeysPlugin.stopReaderScan();
} catch (e) {
@@ -63,7 +63,7 @@ class KeyRepository {
}
}
- Future<void>? startScanning() async {
+ Future<void> startScanning() async {
try {
await seosMobileKeysPlugin
.startReaderScan(MobileKeysScanMode.optimizePerformance, [
@@ -85,7 +85,7 @@ class KeyRepository {
}
}
- Future<void>? openClosestReader() async {
+ Future<void> openClosestReader() async {
try {
await seosMobileKeysPlugin.openClosestReader();
} catch (e) {
diff --git a/comwell_key_app/lib/overview/components/booking_list_item_view.dart b/comwell_key_app/lib/overview/components/booking_list_item_view.dart
index 2cfae4d2..bcb0009b 100644
--- a/comwell_key_app/lib/overview/components/booking_list_item_view.dart
+++ b/comwell_key_app/lib/overview/components/booking_list_item_view.dart
@@ -26,7 +26,8 @@ class BookingListItemView extends StatelessWidget {
Widget build(BuildContext context) {
final theme = Theme.of(context);
return InkWell(
- onTap: () => {context.pushNamed(AppRoutes.bookingDetails.name, extra: booking)},
+ onTap: () =>
+ context.pushNamed(AppRoutes.bookingDetails.name, extra: booking),
child: Container(
height: 66,
margin: const EdgeInsets.only(bottom: 8, left: 8, right: 8),
diff --git a/comwell_key_app/lib/overview/components/current_booking_list_item_view.dart b/comwell_key_app/lib/overview/components/current_booking_list_item_view.dart
index 69cb1972..5ca7f3c2 100644
--- a/comwell_key_app/lib/overview/components/current_booking_list_item_view.dart
+++ b/comwell_key_app/lib/overview/components/current_booking_list_item_view.dart
@@ -8,6 +8,7 @@ import 'package:go_router/go_router.dart';
class CurrentBookingListItem extends StatelessWidget {
final Booking booking;
+
const CurrentBookingListItem({required this.booking, super.key});
@override
@@ -24,7 +25,8 @@ class CurrentBookingListItem extends StatelessWidget {
),
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
child: InkWell(
- onTap: () => context.pushNamed(AppRoutes.home.name),
+ onTap: () =>
+ context.pushNamed(AppRoutes.bookingDetails.name, extra: booking),
child: Column(
children: [
ClipRRect(
diff --git a/comwell_key_app/lib/overview/cubit/overview_cubit.dart b/comwell_key_app/lib/overview/cubit/overview_cubit.dart
index 2d39ccb5..09180a61 100644
--- a/comwell_key_app/lib/overview/cubit/overview_cubit.dart
+++ b/comwell_key_app/lib/overview/cubit/overview_cubit.dart
@@ -3,6 +3,7 @@ import 'package:comwell_key_app/overview/models/booking.dart';
import 'package:comwell_key_app/overview/models/bookings.dart';
import 'package:comwell_key_app/overview/repository/overview_repository.dart';
import 'package:equatable/equatable.dart';
+import 'package:flutter/foundation.dart';
part 'overview_state.dart';
@@ -16,7 +17,8 @@ class OverviewCubit extends Cubit<OverviewState> {
//TODO: add correct paramenter when API is ready
final bookings = await overviewRepository.fetchAllBookingsForUser("1");
emit(OverviewLoaded(bookings: bookings));
- } catch (e) {
+ } catch (e, st) {
+ if(kDebugMode) print("qqq err=$e, $st");
emit(OverviewError(error: e.toString()));
}
}
diff --git a/comwell_key_app/lib/overview/repository/overview_repository.dart b/comwell_key_app/lib/overview/repository/overview_repository.dart
index 44ed90b8..0b9afb3b 100644
--- a/comwell_key_app/lib/overview/repository/overview_repository.dart
+++ b/comwell_key_app/lib/overview/repository/overview_repository.dart
@@ -66,6 +66,7 @@ final response = {
"roomType": "Deluxe",
"adults": 2,
"children": 1,
+ "confirmationId": "",
"booker": "John Doe",
"bookingDate": "2024-10-15T14:00:00",
"paymentDetails": {
@@ -87,6 +88,7 @@ final response = {
"image": "assets/images/current_room.png",
"hotelName": "Mountain View Hotel",
"hotelCode": "MV002",
+ "confirmationId": "",
"roomType": "Suite",
"adults": 1,
"children": 0,
@@ -111,6 +113,7 @@ final response = {
"image": "assets/images/current_room.png",
"hotelName": "City Center Inn",
"hotelCode": "CCI003",
+ "confirmationId": "",
"roomType": "Standard",
"adults": 2,
"children": 0,
@@ -131,6 +134,7 @@ final response = {
"id": "4",
"userId": "126",
"roomNumber": "104",
+ "confirmationId": "",
"startDate": "2024-09-25T14:00:00",
"endDate": "2024-09-28T12:00:00",
"status": "past",
@@ -155,6 +159,7 @@ final response = {
"id": "5",
"userId": "127",
"roomNumber": "105",
+ "confirmationId": "",
"startDate": "2024-09-10T14:00:00",
"endDate": "2024-09-12T12:00:00",
"status": "past",
@@ -179,6 +184,7 @@ final response = {
"id": "6",
"userId": "128",
"roomNumber": "106",
+ "confirmationId": "",
"startDate": "2024-09-01T14:00:00",
"endDate": "2024-09-05T12:00:00",
"status": "past",
@@ -205,6 +211,7 @@ final response = {
"id": "7",
"userId": "129",
"roomNumber": "107",
+ "confirmationId": "",
"startDate": "2024-10-15T14:00:00",
"endDate": "2024-10-17T12:00:00",
"status": "cancelled",
@@ -229,6 +236,7 @@ final response = {
"id": "8",
"userId": "130",
"roomNumber": "108",
+ "confirmationId": "",
"startDate": "2024-10-10T14:00:00",
"endDate": "2024-10-12T12:00:00",
"status": "cancelled",
@@ -253,6 +261,7 @@ final response = {
"id": "9",
"userId": "131",
"roomNumber": "109",
+ "confirmationId": "",
"startDate": "2024-11-05T14:00:00",
"endDate": "2024-11-07T12:00:00",
"status": "cancelled",
diff --git a/comwell_key_app/lib/profile/profile_repository.dart b/comwell_key_app/lib/profile/profile_repository.dart
index dead5e74..040fe097 100644
--- a/comwell_key_app/lib/profile/profile_repository.dart
+++ b/comwell_key_app/lib/profile/profile_repository.dart
@@ -1,10 +1,10 @@
import 'package:comwell_key_app/utils/secure_storage.dart';
-import 'package:comwell_key_app/utils/singleton.dart';
+import 'package:comwell_key_app/utils/seos_repository.dart';
import 'package:seos_mobile_keys_plugin/seos_mobile_keys_plugin.dart';
class ProfileRepository {
final SecureStorage secureStorage = SecureStorage();
- final SeosMobileKeysPlugin seosMobileKeysPlugin = Singleton().seosMobileKeysPlugin;
+ final SeosMobileKeysPlugin seosMobileKeysPlugin = SeosRepository().seosMobileKeysPlugin;
ProfileRepository() {
// Constructor
diff --git a/comwell_key_app/lib/redeem_debug/redeem_page.dart b/comwell_key_app/lib/redeem_debug/redeem_page.dart
index 385f0527..36508b8c 100644
--- a/comwell_key_app/lib/redeem_debug/redeem_page.dart
+++ b/comwell_key_app/lib/redeem_debug/redeem_page.dart
@@ -5,7 +5,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'invitation_code_textfield.dart';
import '../common/extensions/scaffold_messenger_state_extension.dart';
-import '../utils/singleton.dart';
+import '../utils/seos_repository.dart';
class RedeemPage extends StatefulWidget {
const RedeemPage({super.key});
@@ -15,7 +15,7 @@ class RedeemPage extends StatefulWidget {
}
class _RedeemPage extends State<RedeemPage> {
- final _seosMobileKeysPlugin = Singleton().seosMobileKeysPlugin;
+ final _seosMobileKeysPlugin = SeosRepository().seosMobileKeysPlugin;
late final _invitationCodeField = InvitationCodeTextField();
SecureStorage secureStorage = SecureStorage();
var _isRedeeming = false;
@@ -70,7 +70,7 @@ class _RedeemPage extends State<RedeemPage> {
await _seosMobileKeysPlugin.setupEndpoint(code);
await secureStorage.write("invitation",code);
if (!context.mounted) return;
- context.goNamed(AppRoutes.home.name);
+ context.goNamed(AppRoutes.bookingDetails.name);
} catch (e) {
ScaffoldMessenger.of(context)
.showActionSnackBar(
diff --git a/comwell_key_app/lib/routing/app_router.dart b/comwell_key_app/lib/routing/app_router.dart
index b0848753..220b5609 100644
--- a/comwell_key_app/lib/routing/app_router.dart
+++ b/comwell_key_app/lib/routing/app_router.dart
@@ -5,7 +5,6 @@ import 'package:comwell_key_app/check_in/check_in_page.dart';
import 'package:comwell_key_app/contact/contact_page.dart';
import 'package:comwell_key_app/find_booking/find_booking_page.dart';
import 'package:comwell_key_app/find_booking/loading_page.dart';
-import 'package:comwell_key_app/home/home_page.dart';
import 'package:comwell_key_app/housekeeping/housekeeping_page.dart';
import 'package:comwell_key_app/key/key_page.dart';
import 'package:comwell_key_app/login/login_page.dart';
@@ -24,6 +23,11 @@ import 'package:go_router/go_router.dart';
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
+import '../booking_details/bloc/booking_details_bloc.dart';
+import '../booking_details/booking_details_page.dart';
+import '../booking_details/booking_details_repository.dart';
+import '../utils/locator.dart';
+
final _rootNavigatorKey = GlobalKey<NavigatorState>();
GoRouter goRouter(AuthenticationBloc authBloc) {
@@ -51,7 +55,7 @@ GoRouter goRouter(AuthenticationBloc authBloc) {
if (isUnAuthenticated && !state.matchedLocation.contains("/login")) {
return "/login";
}
- // Redirect to the home page if the user is authenticated
+ // Redirect to the booking_details page if the user is authenticated
else if (isAuthenticated && state.matchedLocation.contains("/login")) {
return "/oauthredirect";
}
@@ -78,11 +82,12 @@ GoRouter goRouter(AuthenticationBloc authBloc) {
builder: (context, state) => const FindBookingPage(),
),
GoRoute(
- path: "/check_in",
+ path: "/${AppRoutes.checkIn.name}/:booking_id",
name: AppRoutes.checkIn.name,
builder: (context, state) {
+ final bookingId = state.pathParameters["booking_id"] as String;
return BlocProvider(
- create: (context) => CheckInCubit(),
+ create: (context) => CheckInCubit(bookingId),
child: const CheckInPage(),
);
}),
@@ -113,16 +118,27 @@ GoRouter goRouter(AuthenticationBloc authBloc) {
],
),
GoRoute(
- path: "booking_details",
- name: AppRoutes.bookingDetails.name,
+ path: AppRoutes.pastCancelledBookings.name,
+ name: AppRoutes.pastCancelledBookings.name,
builder: (context, state) {
Booking booking = state.extra as Booking;
return PastCancelledBookingDetailPage(booking: booking);
}),
GoRoute(
- path: "home",
- name: AppRoutes.home.name,
- builder: (context, state) => const HomeWidget(),
+ path: AppRoutes.bookingDetails.name,
+ name: AppRoutes.bookingDetails.name,
+ builder: (context, state) {
+ final booking = state.extra as Booking;
+ return BlocProvider<BookingDetailsBloc>(
+ lazy: false,
+ create: (BuildContext context) => BookingDetailsBloc(
+ booking,
+ bookingDetailsRepository:
+ locator<BookingDetailsRepository>(),
+ ),
+ child: const BookingDetailsPage(),
+ );
+ },
routes: [
GoRoute(
path: "key",
diff --git a/comwell_key_app/lib/routing/app_routes.dart b/comwell_key_app/lib/routing/app_routes.dart
index bdb86e31..5fcac0ee 100644
--- a/comwell_key_app/lib/routing/app_routes.dart
+++ b/comwell_key_app/lib/routing/app_routes.dart
@@ -1,6 +1,5 @@
enum AppRoutes {
welcome,
- home,
initial,
redeem,
key,
@@ -12,6 +11,7 @@ enum AppRoutes {
overview,
profileSettings,
bookingDetails,
+ pastCancelledBookings,
findBooking,
loadingPage,
changePassword,
diff --git a/comwell_key_app/lib/services/api.dart b/comwell_key_app/lib/services/api.dart
index 5a099fc2..ac197c69 100644
--- a/comwell_key_app/lib/services/api.dart
+++ b/comwell_key_app/lib/services/api.dart
@@ -36,8 +36,11 @@ class Api {
return response.data as Json;
}
- Future<Response<dynamic>> createEndpointRegistration() async {
- return await dio.post('/keys/v1/CreateEndpointRegistration');
+ Future<String> createEndpointRegistration() async {
+ final response =
+ await dio.post<String>('/keys/v1/CreateEndpointRegistration');
+ final json = jsonDecode(response.data!) as Map<String, String>;
+ return json["invitationCode"] as String;
}
Future<Response<dynamic>> provisionKey(String bookingId) async {
@@ -86,11 +89,10 @@ class Api {
}
// Check in
- Future<void> checkIn(String confirmationId) async {
- await dio.post("/booking/v1/CheckIn", data: {
- "confirmationId": confirmationId
- });
- }
+ Future<void> checkIn(String confirmationId) async {
+ await dio.post<void>("/booking/v1/CheckIn",
+ data: {"confirmationId": confirmationId});
+ }
Future<void> sendContact(String hotelCode) async {}
}
diff --git a/comwell_key_app/lib/settings/settings_page.dart b/comwell_key_app/lib/settings/settings_page.dart
index a42dff5f..bce582da 100644
--- a/comwell_key_app/lib/settings/settings_page.dart
+++ b/comwell_key_app/lib/settings/settings_page.dart
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
-import '../utils/singleton.dart';
+import '../utils/seos_repository.dart';
import '../common/extensions/scaffold_messenger_state_extension.dart';
class SettingsPage extends StatefulWidget {
@@ -12,7 +12,7 @@ class SettingsPage extends StatefulWidget {
}
class _SettingPage extends State<SettingsPage> {
- final _seosMobileKeysPlugin = Singleton().seosMobileKeysPlugin;
+ final _seosMobileKeysPlugin = SeosRepository().seosMobileKeysPlugin;
bool _isUnregistering = false;
@override
diff --git a/comwell_key_app/lib/utils/locator.dart b/comwell_key_app/lib/utils/locator.dart
index 455b9ac1..7e90d738 100644
--- a/comwell_key_app/lib/utils/locator.dart
+++ b/comwell_key_app/lib/utils/locator.dart
@@ -1,17 +1,19 @@
import 'package:comwell_key_app/authentication/authentication_repository.dart';
import 'package:comwell_key_app/database/comwell_db.dart';
-import 'package:comwell_key_app/home/home_repository.dart';
import 'package:comwell_key_app/key/repository/key_repository.dart';
import 'package:comwell_key_app/overview/repository/overview_repository.dart';
import 'package:comwell_key_app/pregistration/pregistration_repository.dart';
import 'package:comwell_key_app/profile/profile_repository.dart';
import 'package:comwell_key_app/profile_settings/repostiory/profile_settings_repository.dart';
import 'package:comwell_key_app/tracking/comwell_tracking.dart';
+import 'package:comwell_key_app/utils/seos_repository.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:get_it/get_it.dart';
import 'package:seos_mobile_keys_plugin/seos_mobile_keys_plugin.dart';
+import '../booking_details/booking_details_repository.dart';
+
final locator = GetIt.I;
void setupLocator() {
@@ -21,12 +23,12 @@ void setupLocator() {
locator.registerFactory<KeyRepository>(() => KeyRepository(
deviceInfoPlugin: locator<DeviceInfoPlugin>(),
seosMobileKeysPlugin: locator<SeosMobileKeysPlugin>()));
+ locator.registerSingleton(SeosRepository());
locator.registerFactory<OverviewRepository>(() => OverviewRepository());
locator.registerFactory<ProfileSettingsRepository>(
() => ProfileSettingsRepository());
- locator.registerFactory<AuthenticationRepository>(
- () => AuthenticationRepository());
- locator.registerFactory<HomeRepository>(() => HomeRepository());
+ locator.registerSingleton<AuthenticationRepository>(AuthenticationRepository());
+ locator.registerFactory<BookingDetailsRepository>(() => BookingDetailsRepository());
locator.registerFactory<ProfileRepository>(() => ProfileRepository());
locator.registerFactory<PreregistrationRepository>(
() => PreregistrationRepository());
diff --git a/comwell_key_app/lib/utils/seos_repository.dart b/comwell_key_app/lib/utils/seos_repository.dart
new file mode 100644
index 00000000..e626f717
--- /dev/null
+++ b/comwell_key_app/lib/utils/seos_repository.dart
@@ -0,0 +1,92 @@
+import 'package:comwell_key_app/services/api.dart';
+import 'package:comwell_key_app/utils/secure_storage.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_dotenv/flutter_dotenv.dart';
+import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
+import 'package:seos_mobile_keys_plugin/seos_mobile_keys_plugin.dart';
+import 'package:comwell_key_app/common/const.dart' as constants;
+
+class SeosRepository {
+ final secureStorage = SecureStorage();
+ final api = Api();
+ final seosMobileKeysPlugin = SeosMobileKeysPlugin();
+
+ Future<bool> startMobilePlugin() async {
+ final mobileKeysOptions = {
+ "MobileKeysOptionApplicationId":
+ dotenv.env['MOBILEKEYSOPTIONAPPLICATIONID'],
+ "MobileKeysOptionAppDescription":
+ dotenv.env['MOBILEKEYSOPTIONAPPDESCRIPTION'],
+ "MobileKeysOptionVersion": dotenv.env['MOBILEKEYSOPTIONVERSION'],
+ "MobileKeysOptionLockServiceCodes": [1],
+ "MobileKeysOptionLogsMail": dotenv.env['MOBILEKEYSOPTIONLOGSMAIL'],
+ };
+
+ try {
+ await seosMobileKeysPlugin.startUp(mobileKeysOptions);
+ final isEndpointSetup = await seosMobileKeysPlugin.isEndpointSetup();
+ if (isEndpointSetup) {
+ updateEndpoint();
+ return true;
+ } else {
+ return false;
+ }
+ } on PlatformException catch (e) {
+ throw Exception('Failed to init MobileKeysManager - ${e.toString()}');
+ } catch (_) {
+ throw Exception('Failed to init start');
+ }
+ }
+
+ Future<bool> isEndpointSetup({bool firstLaunch = true}) async {
+ try {
+ return await seosMobileKeysPlugin.isEndpointSetup();
+ } catch (e) {
+ throw Exception('Failed to check if endpoint setup - ${e.toString()}');
+ }
+ }
+
+ Future<void> provisionKey({
+ required String bookingId,
+ bool forceProvision = false,
+ }) async {
+ try {
+ final hasKey = await secureStorage.read(constants.hasKey);
+ if (hasKey != null) {
+ final DateTime hasKeyDate = DateTime.parse(hasKey);
+ if (DateTime.now().difference(hasKeyDate).inDays < 1) {
+ return;
+ }
+ }
+
+ await api.provisionKey(bookingId);
+ secureStorage.write(constants.hasKey, DateTime.now().toString());
+ await updateEndpoint();
+ } catch (e) {
+ throw Exception('Failed to provision a key - ${e.toString()}');
+ }
+ }
+
+ Future<bool> updateEndpoint() async {
+ try {
+ await seosMobileKeysPlugin.updateEndpoint();
+ return true;
+ } catch (e) {
+ throw Exception('Failed to update endpoint - ${e.toString()}');
+ }
+ }
+
+ Future<void> setupEndpoint(String invitationCode) async {
+ await seosMobileKeysPlugin.setupEndpoint(invitationCode);
+ }
+
+ Future<List<MobileKeysKey>> refreshKeys() async {
+ try {
+ final List<MobileKeysKey> listOfKeys = await seosMobileKeysPlugin.listMobileKeys();
+ await secureStorage.write(constants.hasKey, DateTime.now().toString());
+ return listOfKeys;
+ } catch (e) {
+ throw Exception('Failed to list keys - ${e.toString()}');
+ }
+ }
+}
diff --git a/comwell_key_app/lib/utils/singleton.dart b/comwell_key_app/lib/utils/singleton.dart
deleted file mode 100644
index b250971f..00000000
--- a/comwell_key_app/lib/utils/singleton.dart
+++ /dev/null
@@ -1,14 +0,0 @@
-import 'package:seos_mobile_keys_plugin/seos_mobile_keys_plugin.dart';
-
-class Singleton {
-
- static final Singleton _instance = Singleton._internal();
-
- factory Singleton() {
- return _instance;
- }
-
- Singleton._internal();
-
- final seosMobileKeysPlugin = SeosMobileKeysPlugin();
-}
\ No newline at end of file
diff --git a/comwell_key_app/test/authentication_test/authentication_bloc_test.dart b/comwell_key_app/test/authentication_test/authentication_bloc_test.dart
index 169749f5..f3486273 100644
--- a/comwell_key_app/test/authentication_test/authentication_bloc_test.dart
+++ b/comwell_key_app/test/authentication_test/authentication_bloc_test.dart
@@ -21,6 +21,7 @@ void main() {
);
}
+
group('authenticationBloc', () {
group('AuthenticationSubscriptionRequested', () {
final error = Exception('oops');
diff --git a/comwell_key_app/test/authentication_test/authentication_repository.dart b/comwell_key_app/test/authentication_test/authentication_repository.dart
new file mode 100644
index 00000000..4e34440a
--- /dev/null
+++ b/comwell_key_app/test/authentication_test/authentication_repository.dart
@@ -0,0 +1,53 @@
+// Import necessary testing packages and mockito
+import 'package:comwell_key_app/authentication/authentication_repository.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:mockito/mockito.dart';
+import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
+import 'package:seos_mobile_keys_plugin/seos_mobile_keys_plugin.dart';
+
+class MockSeosMobileKeysPlugin extends Mock implements SeosMobileKeysPlugin {}
+class MockAuthenticationRepository extends Mock implements AuthenticationRepository {}
+
+void main() {
+ // Declare the mock SeosMobileKeysPlugin
+ late SeosMobileKeysPlugin mockSeosMobileKeysPlugin;
+ late MockAuthenticationRepository authenticationRepository;
+
+ // Setup function runs before every test
+ setUp(() {
+ // Initialize the mock SeosMobileKeysPlugin
+ TestWidgetsFlutterBinding.ensureInitialized();
+ mockSeosMobileKeysPlugin = MockSeosMobileKeysPlugin();
+ authenticationRepository = MockAuthenticationRepository();
+
+ });
+
+ group('HomeRepository', () {
+ test('isEndpointSetup returns true when endpoint is setup', () async {
+ when(mockSeosMobileKeysPlugin.isEndpointSetup()).thenAnswer((_) async => true);
+
+ expect(await authenticationRepository.seos.isEndpointSetup(), isTrue);
+ });
+
+ test('isEndpointSetup returns false when endpoint is not setup', () async {
+ when(mockSeosMobileKeysPlugin.isEndpointSetup()).thenAnswer((_) async => false);
+
+
+ expect(await authenticationRepository.seos.isEndpointSetup(), isFalse);
+ });
+
+ test('refreshKeys returns a list of MobileKeysKey on success', () async {
+ when(mockSeosMobileKeysPlugin.listMobileKeys()).thenAnswer((_) async => [MobileKeysKey(active: true, credentialType: 1)]);
+
+ final keys = await authenticationRepository.seos.refreshKeys();
+ expect(keys, isNotNull);
+ expect(keys, isA<List<MobileKeysKey?>>());
+ });
+
+ test('refreshKeys throws an exception on failure', () async {
+ when(mockSeosMobileKeysPlugin.listMobileKeys()).thenThrow(Exception('Failed to list keys'));
+
+ expect(authenticationRepository.seos.refreshKeys(), throwsA(isA<Exception>()));
+ });
+ });
+}
\ No newline at end of file
diff --git a/comwell_key_app/test/booking_details_test/booking_details_bloc_test.dart b/comwell_key_app/test/booking_details_test/booking_details_bloc_test.dart
new file mode 100644
index 00000000..7bddb09e
--- /dev/null
+++ b/comwell_key_app/test/booking_details_test/booking_details_bloc_test.dart
@@ -0,0 +1,35 @@
+// Import necessary testing packages, bloc, and mockito
+import 'package:comwell_key_app/booking_details/bloc/booking_details_bloc.dart';
+import 'package:comwell_key_app/booking_details/booking_details_repository.dart';
+import 'package:comwell_key_app/check_in/check_in_repository.dart';
+import 'package:comwell_key_app/utils/locator.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:bloc_test/bloc_test.dart';
+import 'package:mockito/mockito.dart';
+
+class MockBookingDetailsRepository extends Mock implements BookingDetailsRepository {}
+
+void main() {
+ // Declare the mock HomeRepository
+ late BookingDetailsRepository mockBookingDetailsRepository;
+
+ // Setup function runs before every test
+ setUp(() {
+ // Initialize the mock HomeRepository
+ mockBookingDetailsRepository = MockBookingDetailsRepository();
+ setupLocator();
+ });
+
+ // Example test for HomeInitialEvent
+ blocTest<BookingDetailsBloc, BookingDetailsState>(
+ 'emits [ValidKey] when HomeInitialEvent is added and one key is returned',
+ build: () {
+ // Return bloc with mocked repository
+ return BookingDetailsBloc(CheckInRepository.mockBooking, bookingDetailsRepository: mockBookingDetailsRepository);
+ },
+ act: (bloc) => bloc.add(InitialEvent()),
+ // expect: () => [isA<ValidKey>()], // Expecting ValidKey state to be emitted
+ );
+
+ // Add more tests for other scenarios and events...
+}
diff --git a/comwell_key_app/test/booking_details_test/booking_details_repository_test.dart b/comwell_key_app/test/booking_details_test/booking_details_repository_test.dart
new file mode 100644
index 00000000..da380cf0
--- /dev/null
+++ b/comwell_key_app/test/booking_details_test/booking_details_repository_test.dart
@@ -0,0 +1,23 @@
+// Import necessary testing packages and mockito
+import 'package:comwell_key_app/booking_details/booking_details_repository.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:mockito/mockito.dart';
+import 'package:seos_mobile_keys_plugin/seos_mobile_keys_plugin.dart';
+
+class MockSeosMobileKeysPlugin extends Mock implements SeosMobileKeysPlugin {}
+
+void main() {
+ // Declare the mock SeosMobileKeysPlugin
+ late SeosMobileKeysPlugin mockSeosMobileKeysPlugin;
+ late BookingDetailsRepository bookingDetailsRepository;
+
+ // Setup function runs before every test
+ setUp(() {
+ // Initialize the mock SeosMobileKeysPlugin
+ TestWidgetsFlutterBinding.ensureInitialized();
+ mockSeosMobileKeysPlugin = MockSeosMobileKeysPlugin();
+ bookingDetailsRepository = BookingDetailsRepository();
+ });
+
+
+}
\ No newline at end of file
diff --git a/comwell_key_app/test/home_test/home_bloc_test.dart b/comwell_key_app/test/home_test/home_bloc_test.dart
deleted file mode 100644
index ea921995..00000000
--- a/comwell_key_app/test/home_test/home_bloc_test.dart
+++ /dev/null
@@ -1,38 +0,0 @@
-// Import necessary testing packages, bloc, and mockito
-import 'package:comwell_key_app/home/bloc/home_bloc.dart';
-import 'package:comwell_key_app/home/home_repository.dart';
-import 'package:flutter_test/flutter_test.dart';
-import 'package:bloc_test/bloc_test.dart';
-import 'package:mockito/mockito.dart';
-import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
-
-class MockHomeRepository extends Mock implements HomeRepository {}
-
-void main() {
- // Declare the mock HomeRepository
- late HomeRepository mockHomeRepository;
-
- // Setup function runs before every test
- setUp(() {
- // Initialize the mock HomeRepository
- mockHomeRepository = MockHomeRepository();
- });
-
- // Example test for HomeInitialEvent
- blocTest<HomeBloc, HomeState>(
- 'emits [ValidKey] when HomeInitialEvent is added and one key is returned',
- build: () {
- // Setup mock method to return true for isEndpointSetup
- when(mockHomeRepository.isEndpointSetup()).thenAnswer((_) async => true);
- // Setup mock method to return a list with one key for refreshKeys
- when(mockHomeRepository.refreshKeys()).thenAnswer(
- (_) async => [MobileKeysKey(credentialType: 1, active: false)]);
- // Return HomeBloc with mocked repository
- return HomeBloc(homeRepository: mockHomeRepository);
- },
- act: (bloc) => bloc.add(HomeInitialEvent()),
- // expect: () => [isA<ValidKey>()], // Expecting ValidKey state to be emitted
- );
-
- // Add more tests for other scenarios and events...
-}
diff --git a/comwell_key_app/test/home_test/home_repository_test.dart b/comwell_key_app/test/home_test/home_repository_test.dart
deleted file mode 100644
index f3875668..00000000
--- a/comwell_key_app/test/home_test/home_repository_test.dart
+++ /dev/null
@@ -1,53 +0,0 @@
-// Import necessary testing packages and mockito
-import 'package:comwell_key_app/home/home_repository.dart';
-import 'package:flutter_test/flutter_test.dart';
-import 'package:mockito/mockito.dart';
-import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
-import 'package:seos_mobile_keys_plugin/seos_mobile_keys_plugin.dart';
-
-class MockSeosMobileKeysPlugin extends Mock implements SeosMobileKeysPlugin {}
-
-void main() {
- // Declare the mock SeosMobileKeysPlugin
- late SeosMobileKeysPlugin mockSeosMobileKeysPlugin;
- late HomeRepository homeRepository;
-
- // Setup function runs before every test
- setUp(() {
- // Initialize the mock SeosMobileKeysPlugin
- TestWidgetsFlutterBinding.ensureInitialized();
- mockSeosMobileKeysPlugin = MockSeosMobileKeysPlugin();
- homeRepository = HomeRepository();
-
- });
-
- group('HomeRepository', () {
- test('isEndpointSetup returns true when endpoint is setup', () async {
- when(mockSeosMobileKeysPlugin.isEndpointSetup()).thenAnswer((_) async => true);
-
-
- expect(await homeRepository.isEndpointSetup(), isTrue);
- });
-
- test('isEndpointSetup returns false when endpoint is not setup', () async {
- when(mockSeosMobileKeysPlugin.isEndpointSetup()).thenAnswer((_) async => false);
-
-
- expect(await homeRepository.isEndpointSetup(), isFalse);
- });
-
- test('refreshKeys returns a list of MobileKeysKey on success', () async {
- when(mockSeosMobileKeysPlugin.listMobileKeys()).thenAnswer((_) async => [MobileKeysKey(active: true, credentialType: 1)]);
-
- final keys = await homeRepository.refreshKeys();
- expect(keys, isNotNull);
- expect(keys, isA<List<MobileKeysKey?>>());
- });
-
- test('refreshKeys throws an exception on failure', () async {
- when(mockSeosMobileKeysPlugin.listMobileKeys()).thenThrow(Exception('Failed to list keys'));
-
- expect(homeRepository.refreshKeys(), throwsA(isA<Exception>()));
- });
- });
-}
\ No newline at end of file
diff --git a/comwell_key_app/test/key_test/key_bloc_test.dart b/comwell_key_app/test/key_test/key_bloc_test.dart
index e2bcd2e7..366d1115 100644
--- a/comwell_key_app/test/key_test/key_bloc_test.dart
+++ b/comwell_key_app/test/key_test/key_bloc_test.dart
@@ -1,7 +1,8 @@
import 'package:bloc_test/bloc_test.dart';
-import 'package:comwell_key_app/home/home_repository.dart';
+import 'package:comwell_key_app/booking_details/booking_details_repository.dart';
import 'package:comwell_key_app/key/bloc/key_bloc.dart';
import 'package:comwell_key_app/key/repository/key_repository.dart';
+import 'package:comwell_key_app/utils/seos_repository.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/mockito.dart';
import 'package:fake_async/fake_async.dart';
@@ -9,23 +10,28 @@ import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
class MockKeyRepository extends Mock implements KeyRepository {}
-class MockHomeRepository extends Mock implements HomeRepository {}
+class MockBookingDetailsRepository extends Mock implements BookingDetailsRepository {}
class MockMobileKeysKey extends Mock implements MobileKeysKey {}
+class MockSeosRepository extends Mock implements SeosRepository {}
+
void main() {
late KeyBloc keyBloc;
late MockKeyRepository mockKeyRepository;
- late MockHomeRepository mockHomeRepository;
+ late MockBookingDetailsRepository mockBookingDetailsRepository;
late MockMobileKeysKey mockMobileKeysKey;
+ late MockSeosRepository mockSeosRepository;
setUp(() {
mockKeyRepository = MockKeyRepository();
- mockHomeRepository = MockHomeRepository();
+ mockBookingDetailsRepository = MockBookingDetailsRepository();
mockMobileKeysKey = MockMobileKeysKey();
+ mockSeosRepository = MockSeosRepository();
keyBloc = KeyBloc(
+ seosRepository: mockSeosRepository,
keyRepository: mockKeyRepository,
- homeRepository: mockHomeRepository,
+ bookingDetailsRepository: mockBookingDetailsRepository,
);
});
@@ -37,7 +43,6 @@ void main() {
blocTest<KeyBloc, KeyState>(
'emits [KeyState.searchForKeys, KeyState.validKeys, KeyState.scanning, KeyState.openClosestReaderSuccess] when SearchForKeys and StartScanning are added',
build: () {
- when(mockHomeRepository.refreshKeys()).thenAnswer((_) async => [mockMobileKeysKey]);
when(mockKeyRepository.checkDeviceInfo()).thenAnswer((_) async => {});
return keyBloc;
},
@@ -58,7 +63,7 @@ void main() {
blocTest<KeyBloc, KeyState>(
'emits [KeyState.searchForKeys, KeyState.searchForKeysError] when SearchForKeys fails',
build: () {
- when(mockHomeRepository.refreshKeys()).thenThrow(Exception('Failed to list keys'));
+ when(mockSeosRepository.refreshKeys()).thenThrow(Exception('Failed to list keys'));
return keyBloc;
},
act: (bloc) => bloc.add(SearchForKeys()),
diff --git a/comwell_key_app/test/key_test/key_repository_test.dart b/comwell_key_app/test/key_test/key_repository_test.dart
index 6b2d8eec..931f942b 100644
--- a/comwell_key_app/test/key_test/key_repository_test.dart
+++ b/comwell_key_app/test/key_test/key_repository_test.dart
@@ -6,7 +6,7 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:seos_mobile_keys_plugin/app_usage_api.dart';
import 'package:seos_mobile_keys_plugin/seos_mobile_keys_plugin.dart';
-import '../home_test/home_repository_test.dart';
+import '../booking_details_test/booking_details_repository_test.dart';
class MockAndroidDeviceInfo extends Mock implements AndroidDeviceInfo {}
class MockDeviceInfoPlugin extends Mock implements DeviceInfoPlugin {}
diff --git a/comwell_key_app/test/overview_test/overview_cubic_test.dart b/comwell_key_app/test/overview_test/overview_cubic_test.dart
index 4c56d96d..51b5981c 100644
--- a/comwell_key_app/test/overview_test/overview_cubic_test.dart
+++ b/comwell_key_app/test/overview_test/overview_cubic_test.dart
@@ -30,7 +30,8 @@ void main() {
.thenAnswer((_) async => Bookings(
current: [Booking(
id: '1',
- status: BookingStatus.current,
+ status: BookingStatus.current,
+ confirmationId: "s",
userId: '1',
roomNumber: '',
startDate: DateTime(2021, 10, 10),
@@ -62,7 +63,8 @@ void main() {
startDate: DateTime(2021, 10, 10),
endDate: DateTime(2021, 10, 10),
image: '',
- hotelName: '',
+ hotelName: '',
+ confirmationId: "",
roomType: '',
children: 2,
adults: 2,
@@ -109,10 +111,11 @@ void main() {
userId: '1',
roomNumber: '',
startDate: DateTime(2021, 10, 10),
- endDate: DateTime(2021, 10, 10),
+ endDate: DateTime(2021, 10, 10),
+ confirmationId: "",
image: '',
hotelName: '',
- roomType: '',
+ roomType: "",
children: 2,
adults: 2,
hotelCode: '',
@@ -131,7 +134,8 @@ void main() {
endDate: DateTime(2021, 10, 10),
image: '',
hotelName: '',
- roomType: '',
+ roomType: '',
+ confirmationId: "",
children: 2,
adults: 2,
hotelCode: '',
diff --git a/comwell_key_app/test/overview_test/overview_repository_test.dart b/comwell_key_app/test/overview_test/overview_repository_test.dart
index b37377e7..f55c44ad 100644
--- a/comwell_key_app/test/overview_test/overview_repository_test.dart
+++ b/comwell_key_app/test/overview_test/overview_repository_test.dart
@@ -26,6 +26,7 @@ void main() {
roomNumber: '101',
startDate: DateTime.now(),
endDate: DateTime.now().add(const Duration(days: 1)),
+ confirmationId: "s",
image: 'image_url',
hotelName: 'Hotel Name',
roomType: 'Deluxe',
@@ -65,6 +66,7 @@ void main() {
userId: '1',
roomNumber: '101',
startDate: DateTime.now(),
+ confirmationId: "",
endDate: DateTime.now().add(const Duration(days: 1)),
image: 'image_url',
hotelName: 'Hotel Name',