From 770ed710d7ddaf391795c6c5ff131d1b27e63407 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Fri, 24 Feb 2023 14:24:40 +0200 Subject: [PATCH 1/3] Add app lock feature on mac --- .../desktop_sidebar/side_menu_item.dart | 39 +++++++++++-------- .../desktop_sidebar_wrapper.dart | 20 ++++++++-- .../dashboard/desktop_sidebar_view_model.dart | 6 +-- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar/side_menu_item.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar/side_menu_item.dart index c7f388a92..d84c864d7 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar/side_menu_item.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar/side_menu_item.dart @@ -4,34 +4,41 @@ class SideMenuItem extends StatelessWidget { const SideMenuItem({ Key? key, required this.onTap, - required this.iconPath, - required this.isSelected, + this.imagePath, + this.icon, + this.isSelected = false, }) : super(key: key); final void Function() onTap; - final String iconPath; + final String? imagePath; + final IconData? icon; final bool isSelected; - Color _setColor(BuildContext context) { - if (isSelected) { - return Theme.of(context).primaryTextTheme.headline6!.color!; - } else { - return Theme.of(context).highlightColor; - } + Color _setColor(BuildContext context) { + if (isSelected) { + return Theme.of(context).primaryTextTheme.headline6!.color!; + } else { + return Theme.of(context).highlightColor; } + } @override Widget build(BuildContext context) { return InkWell( child: Padding( padding: EdgeInsets.all(20), - child: Image.asset( - iconPath, - fit: BoxFit.cover, - height: 30, - width: 30, - color: _setColor(context), - ), + child: icon != null + ? Icon( + icon, + color: _setColor(context), + ) + : Image.asset( + imagePath ?? '', + fit: BoxFit.cover, + height: 30, + width: 30, + color: _setColor(context), + ), ), onTap: () => onTap.call(), highlightColor: Colors.transparent, diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart index a411c0243..6f5b2287e 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart @@ -1,5 +1,6 @@ import 'package:cake_wallet/di.dart'; import 'package:cake_wallet/routes.dart'; +import 'package:cake_wallet/src/screens/auth/auth_page.dart'; import 'package:cake_wallet/src/screens/dashboard/desktop_dashboard_page.dart'; import 'package:cake_wallet/src/screens/base_page.dart'; import 'package:cake_wallet/src/screens/dashboard/desktop_widgets/desktop_dashboard_navbar.dart'; @@ -93,18 +94,31 @@ class DesktopSidebarWrapper extends BasePage { width: sideMenuWidth, topItems: [ SideMenuItem( - iconPath: 'assets/images/wallet_outline.png', + imagePath: 'assets/images/wallet_outline.png', isSelected: desktopSidebarViewModel.currentPage == SidebarItem.dashboard, onTap: () => desktopSidebarViewModel.onPageChange(SidebarItem.dashboard), ), + SideMenuItem( + icon: Icons.lock_outline, + onTap: () { + Navigator.of(context).pushNamed( + Routes.unlock, + arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) { + auth.close( + route: isAuthenticatedSuccessfully ? Routes.dashboard : null, + ); + }, + ); + }, + ) ], bottomItems: [ SideMenuItem( - iconPath: 'assets/images/support_icon.png', + imagePath: 'assets/images/support_icon.png', isSelected: desktopSidebarViewModel.currentPage == SidebarItem.support, onTap: () => desktopSidebarViewModel.onPageChange(SidebarItem.support)), SideMenuItem( - iconPath: 'assets/images/settings_outline.png', + imagePath: 'assets/images/settings_outline.png', isSelected: desktopSidebarViewModel.currentPage == SidebarItem.settings, onTap: () => desktopSidebarViewModel.onPageChange(SidebarItem.settings), ), diff --git a/lib/view_model/dashboard/desktop_sidebar_view_model.dart b/lib/view_model/dashboard/desktop_sidebar_view_model.dart index 41a6881f7..d0320c05f 100644 --- a/lib/view_model/dashboard/desktop_sidebar_view_model.dart +++ b/lib/view_model/dashboard/desktop_sidebar_view_model.dart @@ -17,13 +17,11 @@ abstract class DesktopSidebarViewModelBase with Store { @observable SidebarItem currentPage = SidebarItem.dashboard; - @action void onPageChange(SidebarItem item) { - - if(currentPage == item){ + if (currentPage == item) { resetSidebar(); - + return; } currentPage = item; From 538220f7bc6b60002e30498a2bc894e4a04c3152 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Fri, 24 Feb 2023 14:50:19 +0200 Subject: [PATCH 2/3] Add assertion to avoid null --- .../desktop_widgets/desktop_sidebar/side_menu_item.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar/side_menu_item.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar/side_menu_item.dart index d84c864d7..42f4b0e4e 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar/side_menu_item.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar/side_menu_item.dart @@ -7,7 +7,7 @@ class SideMenuItem extends StatelessWidget { this.imagePath, this.icon, this.isSelected = false, - }) : super(key: key); + }) : assert((icon != null && imagePath == null) || (icon == null && imagePath != null)); final void Function() onTap; final String? imagePath; From 143a6eecf51853cca13db8c32e6f76a87772214e Mon Sep 17 00:00:00 2001 From: OmarHatem Date: Fri, 24 Feb 2023 15:38:05 +0200 Subject: [PATCH 3/3] pop only PIN screen after successful auth --- .../dashboard/desktop_widgets/desktop_sidebar_wrapper.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart index 6f5b2287e..cc17dbf79 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart @@ -104,9 +104,9 @@ class DesktopSidebarWrapper extends BasePage { Navigator.of(context).pushNamed( Routes.unlock, arguments: (bool isAuthenticatedSuccessfully, AuthPageState auth) { - auth.close( - route: isAuthenticatedSuccessfully ? Routes.dashboard : null, - ); + if (isAuthenticatedSuccessfully) { + auth.close(); + } }, ); },