6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit db1f7859
Changed files
.../authentication/authentication_repository.dart | 14 ++++------- comwell_key_app/lib/home/bloc/home_bloc.dart | 8 ++++++- comwell_key_app/lib/home/bloc/home_event.dart | 5 ++++ comwell_key_app/lib/home/home_page.dart | 4 +++- comwell_key_app/lib/home/home_repository.dart | 28 ++++++++++++---------- .../lib/profile/cubit/profile_cubit.dart | 2 +- comwell_key_app/lib/profile/profile_page.dart | 1 - .../lib/profile/profile_repository.dart | 5 +--- comwell_key_app/pubspec.yaml | 2 +- 9 files changed, 39 insertions(+), 30 deletions(-)
Diff
diff --git a/comwell_key_app/lib/authentication/authentication_repository.dart b/comwell_key_app/lib/authentication/authentication_repository.dart
index ea2333fa..f4d40600 100644
--- a/comwell_key_app/lib/authentication/authentication_repository.dart
+++ b/comwell_key_app/lib/authentication/authentication_repository.dart
@@ -12,35 +12,31 @@ class AuthenticationRepository {
secureStorage = SecureStorage();
}
-
Stream<AuthenticationStatus> get status async* {
await Future<void>.delayed(const Duration(seconds: 1));
//yield AuthenticationStatus.unauthenticated;
yield* _controller.stream;
}
- Future<void> logIn() async {
+ Future<void> logIn() async {
_controller.sink.add(AuthenticationStatus.authenticated);
}
void logOut() {
+ secureStorage.deleteAll();
_controller.sink.add(AuthenticationStatus.unauthenticated);
}
-
-
void dispose() => _controller.close();
- Future<bool> doesTokenExist() async{
+ Future<bool> doesTokenExist() async {
String? refreshtoken = await secureStorage.read(constants.refreshToken);
String? accesstoken = await secureStorage.read(constants.accessToken);
- if(refreshtoken != null && accesstoken != null){
+ if (refreshtoken != null && accesstoken != null) {
return true;
} else {
return false;
}
-
-
}
-}
\ No newline at end of file
+}
diff --git a/comwell_key_app/lib/home/bloc/home_bloc.dart b/comwell_key_app/lib/home/bloc/home_bloc.dart
index 5f57eed5..312a2cd5 100644
--- a/comwell_key_app/lib/home/bloc/home_bloc.dart
+++ b/comwell_key_app/lib/home/bloc/home_bloc.dart
@@ -48,6 +48,11 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
emit(const HomeState.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();
List<MobileKeysKey?>? keys = await homeRepository.refreshKeys();
if (keys != null) {
if (keys.length == 1) {
@@ -68,7 +73,8 @@ class HomeBloc extends Bloc<HomeEvent, HomeState> {
return;
}
try {
- await homeRepository.provisionKey(event.bookingId);
+ await homeRepository.provisionKey(event.bookingId, forceProvision: true);
+
emit(const HomeState.keyProvisioned());
} catch (_) {
emit(const HomeState.setupError());
diff --git a/comwell_key_app/lib/home/bloc/home_event.dart b/comwell_key_app/lib/home/bloc/home_event.dart
index 4793b322..3609ae9a 100644
--- a/comwell_key_app/lib/home/bloc/home_event.dart
+++ b/comwell_key_app/lib/home/bloc/home_event.dart
@@ -19,6 +19,11 @@ final class CodeEnteredEvent extends HomeEvent {
}
final class SearchForKeysEvent extends HomeEvent {
+ final bool endpointNeedsUpdate;
+ const SearchForKeysEvent({this.endpointNeedsUpdate = false});
+
+ @override
+ List<Object> get props => [];
}
diff --git a/comwell_key_app/lib/home/home_page.dart b/comwell_key_app/lib/home/home_page.dart
index 85353774..50e60aa2 100644
--- a/comwell_key_app/lib/home/home_page.dart
+++ b/comwell_key_app/lib/home/home_page.dart
@@ -34,6 +34,7 @@ class _HomeWidget extends State<HomeWidget> {
if (state == const HomeState.setupError()) {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
content: Text('Failed to start Mobile Keys Plugin')));
+ context.read<HomeBloc>().add(SetupEndpoint());
}
if (state == const HomeState.setupComplete()) {
context.read<HomeBloc>().add(const ProvisionKeyEvent("Hotel123"));
@@ -41,6 +42,7 @@ class _HomeWidget extends State<HomeWidget> {
if (state == const HomeState.keyProvisioned()) {
context.read<HomeBloc>().add(SearchForKeysEvent());
}
+
},
builder: (context, state) {
if (state == const HomeState.unknown()) {
@@ -72,7 +74,7 @@ class _HomeWidget extends State<HomeWidget> {
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: ElevatedButton(onPressed: () {
- context.read<HomeBloc>().add(SearchForKeysEvent());
+ context.read<HomeBloc>().add(SearchForKeysEvent(endpointNeedsUpdate: true));
}
, child: Text('Get Key')),
diff --git a/comwell_key_app/lib/home/home_repository.dart b/comwell_key_app/lib/home/home_repository.dart
index 73c5d2c2..00e5e68a 100644
--- a/comwell_key_app/lib/home/home_repository.dart
+++ b/comwell_key_app/lib/home/home_repository.dart
@@ -32,7 +32,10 @@ class HomeRepository {
Future<List<MobileKeysKey?>>? refreshKeys() async {
try {
//await updateEndpoint();
- return await _seosMobileKeysPlugin.listMobileKeys();
+ 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()}');
}
@@ -41,14 +44,16 @@ class HomeRepository {
Future<void> setupEndpoint() async {
try {
final Response<dynamic> code = await api.createEndpointRegistration();
- await _seosMobileKeysPlugin.setupEndpoint(code.data['InvitationCode'] as String);
+ 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) async {
+ Future<void> provisionKey(String bookingId,
+ {bool forceProvision = false}) async {
try {
String? hasKey = await secureStorage.read(constants.hasKey);
if (hasKey != null) {
@@ -57,9 +62,10 @@ class HomeRepository {
return;
}
}
+
await api.provisionKey(bookingId);
secureStorage.write(constants.hasKey, DateTime.now().toString());
- updateEndpoint();
+ await updateEndpoint();
} catch (e) {
throw Exception('Failed to provision a key - ${e.toString()}');
}
@@ -77,16 +83,14 @@ class HomeRepository {
};
try {
- await _seosMobileKeysPlugin.startUp(mobileKeysOptions);
- bool isendpointSetup = await _seosMobileKeysPlugin.isEndpointSetup();
- if(isendpointSetup){
+ await _seosMobileKeysPlugin.startUp(mobileKeysOptions);
+ bool isendpointSetup = await _seosMobileKeysPlugin.isEndpointSetup();
+ if (isendpointSetup) {
updateEndpoint();
return true;
- }else{
- return false;
- }
-
-
+ } else {
+ return false;
+ }
} on PlatformException catch (e) {
throw Exception('Failed to init MobileKeysManager - ${e.toString()}');
} catch (_) {
diff --git a/comwell_key_app/lib/profile/cubit/profile_cubit.dart b/comwell_key_app/lib/profile/cubit/profile_cubit.dart
index 1e949687..2d435834 100644
--- a/comwell_key_app/lib/profile/cubit/profile_cubit.dart
+++ b/comwell_key_app/lib/profile/cubit/profile_cubit.dart
@@ -9,7 +9,7 @@ class ProfileCubit extends Cubit<ProfileState> {
ProfileCubit({required this.profileRepository}) : super(ProfileInitial());
void deleteAllInfoOnLogOut() async {
- await profileRepository.deleteData();
+
emit(ProfileDeleteAllInfo());
}
}
diff --git a/comwell_key_app/lib/profile/profile_page.dart b/comwell_key_app/lib/profile/profile_page.dart
index b3cf675e..e02679ea 100644
--- a/comwell_key_app/lib/profile/profile_page.dart
+++ b/comwell_key_app/lib/profile/profile_page.dart
@@ -212,7 +212,6 @@ class ProfilePage extends StatelessWidget {
maximumSize: const Size(280, 52),
),
onPressed: () {
- context.read<ProfileCubit>().deleteAllInfoOnLogOut();
context
.read<AuthenticationBloc>()
.add(AuthenticationLogoutPressed());
diff --git a/comwell_key_app/lib/profile/profile_repository.dart b/comwell_key_app/lib/profile/profile_repository.dart
index cd61bce4..dead5e74 100644
--- a/comwell_key_app/lib/profile/profile_repository.dart
+++ b/comwell_key_app/lib/profile/profile_repository.dart
@@ -11,8 +11,5 @@ class ProfileRepository {
}
// Example method
- Future<void> deleteData() async {
- //await seosMobileKeysPlugin.terminateEndpoint();
- await secureStorage.deleteAll();
- }
+
}
\ No newline at end of file
diff --git a/comwell_key_app/pubspec.yaml b/comwell_key_app/pubspec.yaml
index a033d601..adb71429 100644
--- a/comwell_key_app/pubspec.yaml
+++ b/comwell_key_app/pubspec.yaml
@@ -4,7 +4,7 @@ description: This app needs a description
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
-version: 0.0.1+4
+version: 0.0.1+5
environment:
sdk: '>=3.0.0 <3.25.0'