6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 5f423998
Changed files
.../authentication/authentication_repository.dart | 2 +- .../lib/check_in/bloc/check_in_cubit.dart | 19 ++++++++++- comwell_key_app/lib/check_in/check_in_page.dart | 3 ++ .../cubit/hotel_information_state.dart | 1 - .../overview/repository/overview_repository.dart | 2 +- comwell_key_app/lib/services/http_client.dart | 2 +- .../interceptors/response_handle_interceptor.dart | 39 +++++++++++++--------- comwell_key_app/lib/utils/seos_repository.dart | 4 +++ 8 files changed, 51 insertions(+), 21 deletions(-)
Diff
diff --git a/comwell_key_app/lib/authentication/authentication_repository.dart b/comwell_key_app/lib/authentication/authentication_repository.dart
index d0cfa02c..eac9a710 100644
--- a/comwell_key_app/lib/authentication/authentication_repository.dart
+++ b/comwell_key_app/lib/authentication/authentication_repository.dart
@@ -27,7 +27,7 @@ class AuthenticationRepository {
void _onAuthResult(AuthenticationStatus status) async {
try {
if (status == AuthenticationStatus.authenticated) {
- await seos.startMobilePlugin();
+ seos.startMobilePlugin();
}
} catch (e, st) {
if (kDebugMode) print("e=$e, $st");
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 54663aa2..bb928f0c 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
@@ -18,8 +18,9 @@ class CheckInCubit extends Cubit<CheckInState> {
await Future<void>.delayed(const Duration(milliseconds: 500));
emit(state.checkInStatusLoading());
await _checkInRepository.checkIfSetup();
+ await tryGetKeys();
emit(state.checkInStatusRoomFound(roomNumber: booking.roomNumber));
- await _checkInRepository.getKeys(booking.id);
+ await Future<void>.delayed(const Duration(milliseconds: 1000));
emit(state.checkInStatusYourDigitalCard(roomNumber: booking.roomNumber));
} catch (err, st) {
if (kDebugMode) print("qqq err=$err, $st");
@@ -27,4 +28,20 @@ class CheckInCubit extends Cubit<CheckInState> {
emit(state.checkInStatusError(Exception(err.toString())));
}
}
+
+ Future<void> tryGetKeys({int attempt = 0}) async {
+ try {
+ print("qqq attempt=$attempt");
+ await _checkInRepository.getKeys(booking.id);
+ } catch (e) {
+ if (attempt < getKeysRetryAttempts) {
+ await Future<void>.delayed(const Duration(milliseconds: 500));
+ tryGetKeys(attempt: attempt + 1);
+ } else {
+ rethrow;
+ }
+ }
+ }
+
+ static const getKeysRetryAttempts = 3;
}
diff --git a/comwell_key_app/lib/check_in/check_in_page.dart b/comwell_key_app/lib/check_in/check_in_page.dart
index f94e1945..dfc448e1 100644
--- a/comwell_key_app/lib/check_in/check_in_page.dart
+++ b/comwell_key_app/lib/check_in/check_in_page.dart
@@ -121,6 +121,9 @@ class _CheckInPageState extends State<CheckInPage>
}
}, builder: (context, state) {
return Scaffold(
+ appBar: AppBar(
+ automaticallyImplyLeading: true,
+ ),
body: SafeArea(
child: Builder(builder: (context) {
final position = getCardPosition(context);
diff --git a/comwell_key_app/lib/hotel_information/cubit/hotel_information_state.dart b/comwell_key_app/lib/hotel_information/cubit/hotel_information_state.dart
index 83d0558a..8c7cae00 100644
--- a/comwell_key_app/lib/hotel_information/cubit/hotel_information_state.dart
+++ b/comwell_key_app/lib/hotel_information/cubit/hotel_information_state.dart
@@ -21,7 +21,6 @@ class HotelInformationState extends Equatable {
HotelState? hotelState,
bool? spaButtonIsLoading,
}) {
- print("qqq spaButtonIsLoading=$spaButtonIsLoading");
return HotelInformationState._(
hotelState: hotelState ?? this.hotelState,
spaButtonIsLoading: spaButtonIsLoading ?? this.spaButtonIsLoading,
diff --git a/comwell_key_app/lib/overview/repository/overview_repository.dart b/comwell_key_app/lib/overview/repository/overview_repository.dart
index 12e2a57e..7f6c69ee 100644
--- a/comwell_key_app/lib/overview/repository/overview_repository.dart
+++ b/comwell_key_app/lib/overview/repository/overview_repository.dart
@@ -14,7 +14,7 @@ class OverviewRepository {
//final response = await api.fetchAllBookingsForUser(userId);
//if (response != null) {
final bookings = Bookings.fromJson(response);
- await database.bookingsDao.insertBookings(bookings);
+ //await database.bookingsDao.insertBookings(bookings);
return bookings;
// } else {
// throw Exception('Failed to fetch bookings');
diff --git a/comwell_key_app/lib/services/http_client.dart b/comwell_key_app/lib/services/http_client.dart
index 8e9cd4f6..cfe3f00f 100644
--- a/comwell_key_app/lib/services/http_client.dart
+++ b/comwell_key_app/lib/services/http_client.dart
@@ -19,10 +19,10 @@ class HttpClient {
receiveTimeout: const Duration(milliseconds: 10000),
connectTimeout: const Duration(milliseconds: 10000),
sendTimeout: const Duration(milliseconds: 10000),
-
),
);
dio.interceptors.add(ResponseHandleInterceptor(dio));
+ if(kDebugMode) dio.interceptors.add(LogInterceptor());
return dio;
}
diff --git a/comwell_key_app/lib/services/interceptors/response_handle_interceptor.dart b/comwell_key_app/lib/services/interceptors/response_handle_interceptor.dart
index 372fa529..aff49c3c 100644
--- a/comwell_key_app/lib/services/interceptors/response_handle_interceptor.dart
+++ b/comwell_key_app/lib/services/interceptors/response_handle_interceptor.dart
@@ -1,4 +1,3 @@
-
import 'package:comwell_key_app/services/token_error_type.dart';
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
@@ -12,10 +11,14 @@ class ResponseHandleInterceptor extends Interceptor {
const FlutterSecureStorage();
ResponseHandleInterceptor(this._dio);
+
@override
Future<dynamic> onRequest(
- RequestOptions options, RequestInterceptorHandler handler) async {
- final String? accessToken = await _secureStorageService.read(key: constants.accessToken);
+ RequestOptions options,
+ RequestInterceptorHandler handler,
+ ) async {
+ final String? accessToken =
+ await _secureStorageService.read(key: constants.accessToken);
final String? refreshToken =
await _secureStorageService.read(key: constants.refreshToken);
@@ -37,21 +40,17 @@ class ResponseHandleInterceptor extends Interceptor {
}
@override
- Future<dynamic> onResponse(
- Response<dynamic> response, ResponseInterceptorHandler handler) async {
+ Future<dynamic> onError(
+ DioException err, ErrorInterceptorHandler handler) async {
+ final response = err.response!;
+ final statusCode = response.statusCode;
try {
if (response.data == null) {
throw DioException(
requestOptions: response.requestOptions,
error: 'No data received from the server');
}
-
- if (response.statusCode != null &&
- response.statusCode! >= 200 &&
- response.statusCode! < 300) {
- debugPrint(response.toString());
- return handler.next(response);
- } else if (response.statusCode == 401) {
+ if (statusCode == 401) {
final newToken = await _refreshToken();
if (newToken != null) {
// Retry the original request with the new token
@@ -60,7 +59,8 @@ class ResponseHandleInterceptor extends Interceptor {
final opts = Options(
method: response.requestOptions.method,
headers: response.requestOptions.headers);
- final retryRequest = await _dio.request<Response<dynamic>>(response.requestOptions.path,
+ final retryRequest = await _dio.request<Response<dynamic>>(
+ response.requestOptions.path,
options: opts,
data: response.requestOptions.data,
queryParameters: response.requestOptions.queryParameters);
@@ -79,6 +79,14 @@ class ResponseHandleInterceptor extends Interceptor {
}
}
+ @override
+ Future<dynamic> onResponse(
+ Response<dynamic> response,
+ ResponseInterceptorHandler handler,
+ ) async {
+ return handler.next(response);
+ }
+
Future<String?> _refreshToken() async {
final String? refreshToken =
await _secureStorageService.read(key: constants.refreshToken);
@@ -87,9 +95,8 @@ class ResponseHandleInterceptor extends Interceptor {
return null;
}
- final Dio refreshDio = Dio(BaseOptions(
- baseUrl:
- dotenv.env['AAD_B2C_TOKEN_ENDPOINT']!));
+ final Dio refreshDio =
+ Dio(BaseOptions(baseUrl: dotenv.env['AAD_B2C_TOKEN_ENDPOINT']!));
final response = await refreshDio.post<dynamic>('',
data: {
'grant_type': 'refresh_token',
diff --git a/comwell_key_app/lib/utils/seos_repository.dart b/comwell_key_app/lib/utils/seos_repository.dart
index cf4bbe8b..abd528ac 100644
--- a/comwell_key_app/lib/utils/seos_repository.dart
+++ b/comwell_key_app/lib/utils/seos_repository.dart
@@ -29,6 +29,10 @@ class SeosRepository {
await seosMobileKeysPlugin.startUp(mobileKeysOptions);
_pluginStarted = true;
}
+ } catch (e) {
+ // ignore
+ }
+ try {
final isEndpointSetup = await seosMobileKeysPlugin.isEndpointSetup();
if (isEndpointSetup) {
await seosMobileKeysPlugin.updateEndpoint();