6177214e-ce7c-49e3-99de-ff9721b26f63 — Commit 5f8005bc

AuthorNKL<nikolaj.king@gmail.com>
Date2024-09-03 09:50:18 +0200
added new app bar and fixed issue on keys

Changed files

.../lib/components/comwell_app_bar.dart            | 75 ++++++++++++++++++----
 comwell_key_app/lib/home/home_page.dart            | 23 +++----
 comwell_key_app/lib/home/home_repository.dart      |  3 +-
 comwell_key_app/lib/key/bloc/key_bloc.dart         | 22 ++++++-
 comwell_key_app/lib/key/bloc/key_event.dart        |  4 ++
 comwell_key_app/lib/key/bloc/key_state.dart        |  6 +-
 comwell_key_app/lib/key/key_page.dart              | 62 ++++++++++++------
 .../lib/key/repository/key_repository.dart         | 15 +++--
 comwell_key_app/lib/redeem_debug/redeem_page.dart  | 14 +---
 comwell_key_app/lib/routing/app_router.dart        | 28 ++++----
 10 files changed, 169 insertions(+), 83 deletions(-)

Diff

diff --git a/comwell_key_app/lib/components/comwell_app_bar.dart b/comwell_key_app/lib/components/comwell_app_bar.dart
index 5727e3b5..7191a840 100644
--- a/comwell_key_app/lib/components/comwell_app_bar.dart
+++ b/comwell_key_app/lib/components/comwell_app_bar.dart
@@ -1,14 +1,65 @@
+import 'package:comwell_key_app/themes/light_theme.dart';
import 'package:flutter/material.dart';
-class ComwellAppBar extends AppBar {
- final Widget? label;
- final Widget? leadingWidget;
-
- ComwellAppBar({super.key, required this.label, this.leadingWidget})
- : super(
- backgroundColor: Colors.transparent,
- title: label,
- automaticallyImplyLeading: false,
- leading: leadingWidget,
- );
-}
\ No newline at end of file
+class ComwellAppBar extends StatelessWidget implements PreferredSizeWidget {
+ final bool shouldShowAppBar;
+
+ const ComwellAppBar({super.key, this.shouldShowAppBar = true});
+
+ @override
+ Widget build(BuildContext context) {
+ return Container(
+ decoration: BoxDecoration(
+ color: sandColor[20],
+ borderRadius: const BorderRadius.only(
+ bottomLeft: Radius.circular(24),
+ bottomRight: Radius.circular(24),
+ ),
+ ),
+ height: 112,
+ child: Padding(
+
+ padding: const EdgeInsets.only(bottom: 10),
+ child:Row(
+
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ crossAxisAlignment: CrossAxisAlignment.end,
+
+ children: [
+ RoundIconButton(icon: Icons.chevron_left, onPressed: () {
+ Navigator.of(context).pop();
+ }),
+ RoundIconButton(icon: Icons.person_2_outlined, onPressed: () {
+ //profile
+ }),
+ ],
+ ),
+ ),);
+ }
+
+ @override
+ Size get preferredSize => const Size.fromHeight(112);
+}
+
+class RoundIconButton extends StatelessWidget {
+ final IconData icon;
+ final Function onPressed;
+ const RoundIconButton({
+ required this.icon,
+ required this.onPressed,
+ super.key,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return ElevatedButton(
+ onPressed: () {onPressed();},
+ style: ElevatedButton.styleFrom(
+ elevation: 0,
+ backgroundColor: Colors.white,
+ shape: const CircleBorder(side: BorderSide(style: BorderStyle.none)),
+ ),
+ child: Icon(icon, color: Colors.black),
+ );
+ }
+}
diff --git a/comwell_key_app/lib/home/home_page.dart b/comwell_key_app/lib/home/home_page.dart
index 5073ff73..b8ed7d04 100644
--- a/comwell_key_app/lib/home/home_page.dart
+++ b/comwell_key_app/lib/home/home_page.dart
@@ -41,7 +41,7 @@ Future<void> _updateEndpoint() async {
@override
Widget build(BuildContext context) {
- context.read<HomeBloc>().add(SearchForKeysEvent());
+ //context.read<HomeBloc>().add(SearchForKeysEvent());
return BlocConsumer<HomeBloc, HomeState>(
listener: (context, state) {
@@ -52,21 +52,14 @@ Future<void> _updateEndpoint() async {
key: _refreshIndicatorKey,
displacement: 20,
onRefresh: () async {
- await _updateEndpoint();
+ return await _updateEndpoint();
},
child: Scaffold(
extendBodyBehindAppBar: true,
- appBar: ComwellAppBar(
- label: Row(
- children: [
- Image.asset(
- 'assets/images/Logo.png',
- width: 100,
- height: 30,
- ),
- ],
- ),
- ),
+ appBar: const ComwellAppBar(
+ shouldShowAppBar: true,
+ )
+ ,
body: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
@@ -97,6 +90,10 @@ Future<void> _updateEndpoint() async {
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)
],
),
diff --git a/comwell_key_app/lib/home/home_repository.dart b/comwell_key_app/lib/home/home_repository.dart
index 5a3c05da..5eeef34b 100644
--- a/comwell_key_app/lib/home/home_repository.dart
+++ b/comwell_key_app/lib/home/home_repository.dart
@@ -20,8 +20,7 @@ class HomeRepository {
Future<List<MobileKeysKey?>>? refreshKeys() async {
try {
- return await _seosMobileKeysPlugin.listMobileKeys();
-
+ return await _seosMobileKeysPlugin.listMobileKeys();
} catch (e) {
throw Exception('Failed to list keys - ${e.toString()}');
}
diff --git a/comwell_key_app/lib/key/bloc/key_bloc.dart b/comwell_key_app/lib/key/bloc/key_bloc.dart
index 3ca57820..ce17f52e 100644
--- a/comwell_key_app/lib/key/bloc/key_bloc.dart
+++ b/comwell_key_app/lib/key/bloc/key_bloc.dart
@@ -36,13 +36,29 @@ class KeyBloc extends Bloc<KeyEvent, KeyState> {
emit(KeyState.scanning(event.mobileKey));
Timer.periodic(const Duration(seconds: 1), (timer) async {
- keyRepository.openClosestReader();
- keyRepository.stopScanning();
- emit(KeyState.openClosestReaderSuccess());
+ await keyRepository.openClosestReader();
+ //keyRepository.stopScanning();
+ //emit(KeyState.openClosestReaderSuccess());
});
} catch (e) {
emit(KeyState.scanningError(e.toString()));
}
});
+
+ on<SetRootOpeningTrigger>((event, emit) async {
+ try {
+ await keyRepository.setRootOpeningTrigger();
+ } catch (e) {
+ emit(KeyState.setRootOpeningTriggerError(e.toString()));
+ }
+ });
+
+ on<RemoveRootOpeningTrigger>((event, emit) async {
+ try {
+ await keyRepository.removeRootOpeningTrigger();
+ } catch (e) {
+ emit(KeyState.removeRootOpeningTriggerError(e.toString()));
+ }
+ });
}
}
diff --git a/comwell_key_app/lib/key/bloc/key_event.dart b/comwell_key_app/lib/key/bloc/key_event.dart
index 46cef986..7dcfb3b3 100644
--- a/comwell_key_app/lib/key/bloc/key_event.dart
+++ b/comwell_key_app/lib/key/bloc/key_event.dart
@@ -20,3 +20,7 @@ class StartScanning extends KeyEvent {
class StopScanning extends KeyEvent {}
class OpenClosestReader extends KeyEvent {}
+
+class SetRootOpeningTrigger extends KeyEvent {}
+
+class RemoveRootOpeningTrigger extends KeyEvent {}
diff --git a/comwell_key_app/lib/key/bloc/key_state.dart b/comwell_key_app/lib/key/bloc/key_state.dart
index 8e7cdbea..052a693f 100644
--- a/comwell_key_app/lib/key/bloc/key_state.dart
+++ b/comwell_key_app/lib/key/bloc/key_state.dart
@@ -3,7 +3,7 @@
part of 'key_bloc.dart';
-enum KeyStatus { unknown,searchforKeys, scanning, openClosestReader, openClosestReaderSuccess, openClosestReaderError, scanningError,validKeys, searchForKeysError }
+enum KeyStatus { unknown,searchforKeys, scanning, openClosestReader, openClosestReaderSuccess, openClosestReaderError, scanningError,validKeys, searchForKeysError, setRootOpeningTriggerError, removeRootOpeningTriggerError }
class KeyState extends Equatable {
@@ -31,6 +31,10 @@ class KeyState extends Equatable {
KeyState.scanningError(String error) : this._(status: KeyStatus.scanningError, error: error);
+ KeyState.setRootOpeningTriggerError(String error) : this._(status: KeyStatus.setRootOpeningTriggerError, error: error);
+
+ KeyState.removeRootOpeningTriggerError(String error) : this._(status: KeyStatus.removeRootOpeningTriggerError, error: error);
+
KeyStatus status;
MobileKeysKey? key;
diff --git a/comwell_key_app/lib/key/key_page.dart b/comwell_key_app/lib/key/key_page.dart
index 0ce1e87f..a433f1c2 100644
--- a/comwell_key_app/lib/key/key_page.dart
+++ b/comwell_key_app/lib/key/key_page.dart
@@ -1,7 +1,9 @@
import 'package:comwell_key_app/key/bloc/key_bloc.dart';
+import 'package:comwell_key_app/routing/app_routes.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:focus_detector/focus_detector.dart';
import 'package:go_router/go_router.dart';
import 'package:lottie/lottie.dart';
@@ -11,21 +13,21 @@ class KeyPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
context.read<KeyBloc>().add(SearchForKeys());
- return BlocBuilder<KeyBloc, KeyState>(
- builder: (context, state) {
- if (state.status == KeyStatus.scanning || state.status == KeyStatus.openClosestReaderSuccess) {
- return Container(
- padding: const EdgeInsets.all(20),
- color: Theme.of(context).colorScheme.primary,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.end,
+ return BlocBuilder<KeyBloc, KeyState>(builder: (context, state) {
+ //if (state.status == KeyStatus.scanning || state.status != KeyStatus.openClosestReaderSuccess) {
+ return FocusDetector(
+ child: Container(
+ padding: const EdgeInsets.all(20),
+ color: Theme.of(context).colorScheme.primary,
+ child: Column(
+ mainAxisAlignment: MainAxisAlignment.end,
children: [
- Text('hold_phone_to_door'.tr(),
- style: Theme.of(context).textTheme.displayLarge,
- textAlign: TextAlign.center,
- maxLines: 2,
+ Text(
+ 'hold_phone_to_door'.tr(),
+ style: Theme.of(context).textTheme.displayLarge,
+ textAlign: TextAlign.center,
+ maxLines: 2,
),
-
const SizedBox(height: 40),
Lottie.asset(
'assets/animations/loading_key.json',
@@ -35,13 +37,33 @@ class KeyPage extends StatelessWidget {
animate: true,
),
const SizedBox(height: 150),
- Image.asset('assets/images/seos_key_logo.png', height: 150, fit: BoxFit.cover,),
+ Image.asset(
+ 'assets/images/seos_key_logo.png',
+ height: 150,
+ fit: BoxFit.cover,
+ ),
const SizedBox(height: 40),
+ ElevatedButton(
+ onPressed: () {
+
+ context.read<KeyBloc>().add(RemoveRootOpeningTrigger());
+ context.goNamed(AppRoutes.home.name);
+ },
+ child: const Text('go back'),
+ ),
],
- ));
- } else if(state.status == KeyStatus.openClosestReaderSuccess) {
+ ),
+ ),
+ onFocusGained: () {
+ context.read<KeyBloc>().add(SetRootOpeningTrigger());
+ },
+ onFocusLost: () {
+
+ },
+ );
+ } /* else if(state.status == KeyStatus.openClosestReaderSuccess) {
context.pop(); // Go back to the previous page and stop scanning
- }else if (state.status == KeyStatus.scanning) {
+ }else if (state.status == KeyStatus.searchForKeysError) {
return Container(
color: Theme.of(context).colorScheme.primary,
child: Column(
@@ -59,8 +81,8 @@ class KeyPage extends StatelessWidget {
],
));
}
- return const SizedBox();
- },
- );
+ return const SizedBox(); */
+ // },
+ );
}
}
diff --git a/comwell_key_app/lib/key/repository/key_repository.dart b/comwell_key_app/lib/key/repository/key_repository.dart
index 1c5f2720..0ed05f62 100644
--- a/comwell_key_app/lib/key/repository/key_repository.dart
+++ b/comwell_key_app/lib/key/repository/key_repository.dart
@@ -66,7 +66,7 @@ class KeyRepository {
try {
await seosMobileKeysPlugin
.startReaderScan(MobileKeysScanMode.optimizePerformance, [
- MobileKeysOpeningType(openingType: OpeningType.motion),
+ MobileKeysOpeningType(openingType: OpeningType.proximity),
MobileKeysOpeningType(openingType: OpeningType.proximity),
MobileKeysOpeningType(openingType: OpeningType.applicationSpecific),
MobileKeysOpeningType(openingType: OpeningType.seamless),
@@ -84,25 +84,26 @@ class KeyRepository {
try {
await seosMobileKeysPlugin.openClosestReader();
} catch (e) {
- throw Exception('Failed to open closest reader - ${e.toString()}');
+ print(e.toString());
+ //throw Exception('Failed to open closest reader - ${e.toString()}');
}
}
- /* _setRootOpeningTrigger() async {
+ Future<void> setRootOpeningTrigger() async {
if (!Platform.isAndroid) return;
try {
- await _seosMobileKeysPlugin.setRootOpeningTrigger();
+ await seosMobileKeysPlugin.setRootOpeningTrigger();
} catch (e) {
// Do nothing
}
}
- _removeRootOpeningTrigger() async {
+ Future<void> removeRootOpeningTrigger() async {
if (!Platform.isAndroid) return;
try {
- await _seosMobileKeysPlugin.removeRootOpeningTrigger();
+ await seosMobileKeysPlugin.removeRootOpeningTrigger();
} catch (e) {
// Do nothing
}
- } */
+ }
}
diff --git a/comwell_key_app/lib/redeem_debug/redeem_page.dart b/comwell_key_app/lib/redeem_debug/redeem_page.dart
index e56c3b88..400b6d01 100644
--- a/comwell_key_app/lib/redeem_debug/redeem_page.dart
+++ b/comwell_key_app/lib/redeem_debug/redeem_page.dart
@@ -24,18 +24,8 @@ class _RedeemPage extends State<RedeemPage> {
Widget build(BuildContext context) =>
Scaffold(
extendBodyBehindAppBar: true,
- appBar: ComwellAppBar(
- label: Row(
- children: [
- Image.asset(
- 'assets/images/Logo.png',
- width: 100,
- height: 30,
- color: Colors.black
- ),
- ],
- ),
- ),
+ appBar: const ComwellAppBar(
+ shouldShowAppBar: true),
body: SafeArea(
child: Center(
diff --git a/comwell_key_app/lib/routing/app_router.dart b/comwell_key_app/lib/routing/app_router.dart
index 0deeb303..0055f568 100644
--- a/comwell_key_app/lib/routing/app_router.dart
+++ b/comwell_key_app/lib/routing/app_router.dart
@@ -1,4 +1,3 @@
-
import 'package:comwell_key_app/home/home_page.dart';
import 'package:comwell_key_app/key/key_page.dart';
import 'package:comwell_key_app/redeem_debug/redeem_page.dart';
@@ -6,11 +5,12 @@ import 'package:comwell_key_app/routing/app_routes.dart';
import 'package:comwell_key_app/welcome/welcome_page.dart';
import 'package:go_router/go_router.dart';
import 'package:flutter/material.dart';
+
final _rootNavigatorKey = GlobalKey<NavigatorState>();
GoRouter goRouter() {
return GoRouter(
- initialLocation: '/',
+ initialLocation: '/home',
navigatorKey: _rootNavigatorKey,
debugLogDiagnostics: true,
redirect: (context, state) {},
@@ -21,22 +21,24 @@ GoRouter goRouter() {
builder: (context, state) => WelcomePage(),
),
GoRoute(
- path: "/home",
- name: AppRoutes.home.name,
- builder: (context, state) => const HomeWidget(),
- ),
+ path: "/home",
+ name: AppRoutes.home.name,
+ builder: (context, state) => const HomeWidget(),
+ routes: [
+ GoRoute(
+ path: "key",
+ name: AppRoutes.key.name,
+ builder: (context, state) {
+ return const KeyPage(); //mobileKey: key);
+ },
+ ),
+ ]),
GoRoute(
path: "/redeem",
name: AppRoutes.redeem.name,
builder: (context, state) => const RedeemPage(),
),
- GoRoute(
- path: "/key",
- name: AppRoutes.key.name,
- builder: (context, state) {
- return const KeyPage();//mobileKey: key);
- },
- ),
+
/* GoRoute(
path: "/keys",
name: AppRoutes.keys.name,