From 3dcf5b05a559eedcff0cd28b785bdbb26a24c76d Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Wed, 15 Feb 2023 22:11:34 +0200 Subject: [PATCH 1/9] Fix wallet create in settings --- lib/reactions/on_authentication_state_change.dart | 8 ++++++-- lib/src/screens/dashboard/dashboard_page.dart | 1 - lib/src/screens/dashboard/desktop_dashboard_page.dart | 11 ++++++++++- .../desktop_settings/dashboard_settings_page.dart | 5 +++-- lib/src/screens/wallet_list/wallet_list_page.dart | 9 +++++---- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/reactions/on_authentication_state_change.dart b/lib/reactions/on_authentication_state_change.dart index edadf33b0..f7078a45e 100644 --- a/lib/reactions/on_authentication_state_change.dart +++ b/lib/reactions/on_authentication_state_change.dart @@ -1,4 +1,5 @@ import 'package:cake_wallet/routes.dart'; +import 'package:cake_wallet/src/screens/dashboard/desktop_widgets/desktop_dashboard_view.dart'; import 'package:flutter/widgets.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/entities/load_current_wallet.dart'; @@ -23,8 +24,11 @@ void startAuthenticationStateChange(AuthenticationStore authenticationStore, } if (state == AuthenticationState.allowed) { - await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false); - return; + // Temporary workaround for the issue with desktopKey dispose + Future.delayed(Duration(milliseconds: 2), () async { + await navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false); + return; + }); } }); } diff --git a/lib/src/screens/dashboard/dashboard_page.dart b/lib/src/screens/dashboard/dashboard_page.dart index 0557f0415..b06fa26a2 100644 --- a/lib/src/screens/dashboard/dashboard_page.dart +++ b/lib/src/screens/dashboard/dashboard_page.dart @@ -25,7 +25,6 @@ import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:mobx/mobx.dart'; import 'package:smooth_page_indicator/smooth_page_indicator.dart'; import 'package:cake_wallet/main.dart'; -import 'package:cake_wallet/router.dart' as Router; class DashboardPage extends StatelessWidget { DashboardPage({ diff --git a/lib/src/screens/dashboard/desktop_dashboard_page.dart b/lib/src/screens/dashboard/desktop_dashboard_page.dart index ea4d458ba..685873c53 100644 --- a/lib/src/screens/dashboard/desktop_dashboard_page.dart +++ b/lib/src/screens/dashboard/desktop_dashboard_page.dart @@ -33,7 +33,16 @@ class DesktopDashboardPage extends BasePage { @override bool get resizeToAvoidBottomInset => false; - + @override + Widget Function(BuildContext, Widget) get rootWrapper => + (BuildContext context, Widget scaffold) => Container( + decoration: BoxDecoration( + gradient: LinearGradient(colors: [ + Theme.of(context).accentColor, + Theme.of(context).scaffoldBackgroundColor, + Theme.of(context).primaryColor, + ], begin: Alignment.topRight, end: Alignment.bottomLeft)), + child: scaffold); final BalancePage balancePage; diff --git a/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart b/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart index 69cd2ad27..9a5c6620d 100644 --- a/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart +++ b/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart @@ -6,7 +6,6 @@ import 'package:cake_wallet/typography.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/router.dart' as Router; -final _settingsNavigatorKey = GlobalKey(); class DesktopSettingsPage extends StatefulWidget { const DesktopSettingsPage({super.key}); @@ -16,6 +15,8 @@ class DesktopSettingsPage extends StatefulWidget { } class _DesktopSettingsPageState extends State { + GlobalKey _settingsNavigatorKey = GlobalKey(); + final int itemCount = SettingActions.all.length; int? currentPage; @@ -58,7 +59,7 @@ class _DesktopSettingsPageState extends State { onTap: () { if (currentPage != index) { final settingContext = - _settingsNavigatorKey.currentState?.context ?? context; + _settingsNavigatorKey.currentState!.context; item.onTap.call(settingContext); _onItemChange(index); } diff --git a/lib/src/screens/wallet_list/wallet_list_page.dart b/lib/src/screens/wallet_list/wallet_list_page.dart index d76631b3f..235b59fbc 100644 --- a/lib/src/screens/wallet_list/wallet_list_page.dart +++ b/lib/src/screens/wallet_list/wallet_list_page.dart @@ -1,3 +1,4 @@ +import 'package:cake_wallet/main.dart'; import 'package:cake_wallet/src/screens/auth/auth_page.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/utils/show_bar.dart'; @@ -100,9 +101,9 @@ class WalletListBodyState extends State { leftButtonText: S.of(context).cancel, rightButtonText: S.of(context).change, actionLeftButton: () => - Navigator.of(context).pop(false), + Navigator.of(dialogContext).pop(false), actionRightButton: () => - Navigator.of(context).pop(true)); + Navigator.of(dialogContext).pop(true)); }) ?? false; @@ -233,7 +234,7 @@ class WalletListBodyState extends State { auth.hideProgressText(); auth.close(); WidgetsBinding.instance.addPostFrameCallback((_) { - Navigator.of(context).pop(); + navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false); }); } catch (e) { auth.changeProcessText( @@ -245,7 +246,7 @@ class WalletListBodyState extends State { changeProcessText(S.of(context).wallet_list_loading_wallet(wallet.name)); await widget.walletListViewModel.loadWallet(wallet); hideProgressText(); - Navigator.of(context).pop(); + navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false); } catch (e) { changeProcessText(S.of(context).wallet_list_failed_to_load(wallet.name, e.toString())); } From f0c49528096f1628f661282a890452a8e929c4e2 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Wed, 15 Feb 2023 22:13:24 +0200 Subject: [PATCH 2/9] remove unnecessary code --- .../screens/dashboard/desktop_dashboard_page.dart | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/lib/src/screens/dashboard/desktop_dashboard_page.dart b/lib/src/screens/dashboard/desktop_dashboard_page.dart index 685873c53..9caca8797 100644 --- a/lib/src/screens/dashboard/desktop_dashboard_page.dart +++ b/lib/src/screens/dashboard/desktop_dashboard_page.dart @@ -33,18 +33,6 @@ class DesktopDashboardPage extends BasePage { @override bool get resizeToAvoidBottomInset => false; - @override - Widget Function(BuildContext, Widget) get rootWrapper => - (BuildContext context, Widget scaffold) => Container( - decoration: BoxDecoration( - gradient: LinearGradient(colors: [ - Theme.of(context).accentColor, - Theme.of(context).scaffoldBackgroundColor, - Theme.of(context).primaryColor, - ], begin: Alignment.topRight, end: Alignment.bottomLeft)), - child: scaffold); - - final BalancePage balancePage; final DashboardViewModel walletViewModel; final WalletAddressListViewModel addressListViewModel; From 2496a6574acf47c6de0571c373303ee0108db01a Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Wed, 15 Feb 2023 22:14:07 +0200 Subject: [PATCH 3/9] remove unnecessary code --- .../settings/desktop_settings/dashboard_settings_page.dart | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart b/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart index 9a5c6620d..69cd2ad27 100644 --- a/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart +++ b/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart @@ -6,6 +6,7 @@ import 'package:cake_wallet/typography.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/router.dart' as Router; +final _settingsNavigatorKey = GlobalKey(); class DesktopSettingsPage extends StatefulWidget { const DesktopSettingsPage({super.key}); @@ -15,8 +16,6 @@ class DesktopSettingsPage extends StatefulWidget { } class _DesktopSettingsPageState extends State { - GlobalKey _settingsNavigatorKey = GlobalKey(); - final int itemCount = SettingActions.all.length; int? currentPage; @@ -59,7 +58,7 @@ class _DesktopSettingsPageState extends State { onTap: () { if (currentPage != index) { final settingContext = - _settingsNavigatorKey.currentState!.context; + _settingsNavigatorKey.currentState?.context ?? context; item.onTap.call(settingContext); _onItemChange(index); } From e0970fa182c98fd038ae3559116c263c771c520e Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Thu, 16 Feb 2023 18:05:10 +0200 Subject: [PATCH 4/9] fix pageview controller reset index --- .../desktop_sidebar_wrapper.dart | 62 ++++++++----------- 1 file changed, 26 insertions(+), 36 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 5d26f88f2..af5a932ed 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_sidebar_wrapper.dart @@ -13,7 +13,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_mobx/flutter_mobx.dart'; import 'package:cake_wallet/router.dart' as Router; import 'package:mobx/mobx.dart'; - class DesktopSidebarWrapper extends BasePage { final Widget child; final DesktopSidebarViewModel desktopSidebarViewModel; @@ -25,6 +24,8 @@ class DesktopSidebarWrapper extends BasePage { required this.dashboardViewModel, }); + static Key _pageViewKey = GlobalKey(); + @override Color get backgroundLightColor => currentTheme.type == ThemeType.bright ? Colors.transparent : Colors.white; @@ -38,23 +39,6 @@ class DesktopSidebarWrapper extends BasePage { final unselectedIconPath = 'assets/images/desktop_transactions_outline_icon.png'; double get sideMenuWidth => 76.0; - @override - Widget Function(BuildContext, Widget) get rootWrapper => - (BuildContext context, Widget scaffold) => Container( - decoration: BoxDecoration( - gradient: LinearGradient( - colors: [ - Theme.of(context).accentColor, - Theme.of(context).scaffoldBackgroundColor, - Theme.of(context).primaryColor, - ], - begin: Alignment.topRight, - end: Alignment.bottomLeft, - ), - ), - child: scaffold, - ); - @override Widget? leading(BuildContext context) => Padding( padding: EdgeInsets.only(left: sideMenuWidth), @@ -105,24 +89,8 @@ class DesktopSidebarWrapper extends BasePage { @override Widget body(BuildContext context) { - reaction((_) => desktopSidebarViewModel.currentPage, (page) { - String? currentPath; - - desktopKey.currentState?.popUntil((route) { - currentPath = route.settings.name; - return true; - }); - if (page == SidebarItem.transactions) { - return; - } - - if (currentPath == Routes.transactionsPage) { - Navigator.of(desktopKey.currentContext!).pop(); - } - - pageController.jumpToPage(page.index); - }); - + _setEffects(); + return Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -151,6 +119,7 @@ class DesktopSidebarWrapper extends BasePage { }), Expanded( child: PageView( + key: _pageViewKey, controller: pageController, physics: NeverScrollableScrollPhysics(), children: [ @@ -182,4 +151,25 @@ class DesktopSidebarWrapper extends BasePage { ], ); } + +void _setEffects() async { + + reaction((_) => desktopSidebarViewModel.currentPage, (page) { + + String? currentPath; + + desktopKey.currentState?.popUntil((route) { + currentPath = route.settings.name; + return true; + }); + if (page == SidebarItem.transactions) { + return; + } + + if (currentPath == Routes.transactionsPage) { + Navigator.of(desktopKey.currentContext!).pop(); + } + pageController.jumpToPage(page.index); + }); + } } From 4bc81242fc506888a5592197ec45304936642c40 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Fri, 17 Feb 2023 16:41:49 +0200 Subject: [PATCH 5/9] Add create and restore wallet options to dropdown menu --- lib/entities/desktop_dropdown_item.dart | 20 ++++++++ .../on_authentication_state_change.dart | 1 - .../dashboard/desktop_dashboard_page.dart | 1 + .../desktop_wallet_selection_dropdown.dart | 47 ++++++++++++++++--- .../dashboard_settings_page.dart | 16 +++++-- .../screens/wallet_list/wallet_list_page.dart | 4 +- .../wallet_list/wallet_list_item.dart | 9 ++-- .../wallet_list/wallet_list_view_model.dart | 17 +++++++ 8 files changed, 97 insertions(+), 18 deletions(-) create mode 100644 lib/entities/desktop_dropdown_item.dart diff --git a/lib/entities/desktop_dropdown_item.dart b/lib/entities/desktop_dropdown_item.dart new file mode 100644 index 000000000..235aa6d55 --- /dev/null +++ b/lib/entities/desktop_dropdown_item.dart @@ -0,0 +1,20 @@ +import 'package:cw_core/wallet_type.dart'; + +abstract class DesktopDropdownItem { + + final String name; + final WalletType type; + final bool isCurrent; + final dynamic key; + final bool isEnabled; + final String? optionName; + + DesktopDropdownItem({this.name = '', this.type = WalletType.none, this.isCurrent = false, this.key, this.isEnabled = true, this.optionName}); +} + +class DropdownOption extends DesktopDropdownItem { + DropdownOption({required this.name, required this.optionName}); + + final String name; + final String optionName; +} \ No newline at end of file diff --git a/lib/reactions/on_authentication_state_change.dart b/lib/reactions/on_authentication_state_change.dart index f7078a45e..0adea5128 100644 --- a/lib/reactions/on_authentication_state_change.dart +++ b/lib/reactions/on_authentication_state_change.dart @@ -1,5 +1,4 @@ import 'package:cake_wallet/routes.dart'; -import 'package:cake_wallet/src/screens/dashboard/desktop_widgets/desktop_dashboard_view.dart'; import 'package:flutter/widgets.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/entities/load_current_wallet.dart'; diff --git a/lib/src/screens/dashboard/desktop_dashboard_page.dart b/lib/src/screens/dashboard/desktop_dashboard_page.dart index f79d2f9e2..c2b7285b7 100644 --- a/lib/src/screens/dashboard/desktop_dashboard_page.dart +++ b/lib/src/screens/dashboard/desktop_dashboard_page.dart @@ -24,6 +24,7 @@ class DesktopDashboardPage extends StatelessWidget { final WalletAddressListViewModel addressListViewModel; static final GlobalKey desktopKey = GlobalKey(); + static final GlobalKey kex = GlobalKey(); bool _isEffectsInstalled = false; StreamSubscription? _onInactiveSub; diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart index fe98a0af9..5c5cd557e 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart @@ -1,4 +1,5 @@ import 'package:another_flushbar/flushbar.dart'; +import 'package:cake_wallet/entities/desktop_dropdown_item.dart'; import 'package:cake_wallet/generated/i18n.dart'; import 'package:cake_wallet/routes.dart'; import 'package:cake_wallet/src/screens/auth/auth_page.dart'; @@ -7,6 +8,7 @@ import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_item.dart'; import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart'; +import 'package:cake_wallet/wallet_type_utils.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:flutter/material.dart'; @@ -33,8 +35,8 @@ class _DesktopWalletSelectionDropDownState extends State( - items: widget.walletListViewModel.wallets + return DropdownButton( + items: widget.walletListViewModel.dropdownItems .map((wallet) => DropdownMenuItem( child: ConstrainedBox( constraints: BoxConstraints(maxWidth: 500), @@ -47,7 +49,12 @@ class _DesktopWalletSelectionDropDownState extends State( context: context, builder: (dialogContext) { @@ -61,25 +68,25 @@ class _DesktopWalletSelectionDropDownState extends State widget.walletListViewModel.wallets + selectedItemBuilder: (context) => widget.walletListViewModel.dropdownItems .map((wallet) => ConstrainedBox( constraints: BoxConstraints(maxWidth: 500), child: walletListItemTile(wallet), )) .toList(), - value: widget.walletListViewModel.wallets.firstWhere((element) => element.isCurrent), + value: widget.walletListViewModel.dropdownItems.firstWhere((element) => element.isCurrent), underline: const SizedBox(), focusColor: Colors.transparent, ); } - Widget walletListItemTile(WalletListItem wallet) { + Widget walletListItemTile(DesktopDropdownItem wallet) { return Container( height: tileHeight, padding: EdgeInsets.symmetric(horizontal: 20), @@ -152,6 +159,32 @@ class _DesktopWalletSelectionDropDownState extends State(text, duration: null)..show(context); } diff --git a/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart b/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart index 69cd2ad27..f4312aba4 100644 --- a/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart +++ b/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart @@ -16,7 +16,8 @@ class DesktopSettingsPage extends StatefulWidget { } class _DesktopSettingsPageState extends State { - final int itemCount = SettingActions.all.length; + final List _allItems = []; + int? currentPage; void _onItemChange(int index) { @@ -25,6 +26,13 @@ class _DesktopSettingsPageState extends State { }); } + @override + void initState() { + final allActions = List.from(SettingActions.all); + allActions.remove(SettingActions.walletSettingAction); + _allItems.addAll(allActions); super.initState(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -48,8 +56,8 @@ class _DesktopSettingsPageState extends State { child: ListView.separated( padding: EdgeInsets.only(top: 0), itemBuilder: (_, index) { - final item = SettingActions.all[index]; - final isLastTile = index == itemCount; + final item = _allItems[index]; + final isLastTile = index == _allItems.length - 1; return SettingActionButton( isLastTile: isLastTile, selectionActive: currentPage != null, @@ -71,7 +79,7 @@ class _DesktopSettingsPageState extends State { height: 1, color: Theme.of(context).primaryTextTheme.caption!.decorationColor!, ), - itemCount: itemCount, + itemCount: _allItems.length, ), ), ], diff --git a/lib/src/screens/wallet_list/wallet_list_page.dart b/lib/src/screens/wallet_list/wallet_list_page.dart index 235b59fbc..8acc14d2f 100644 --- a/lib/src/screens/wallet_list/wallet_list_page.dart +++ b/lib/src/screens/wallet_list/wallet_list_page.dart @@ -234,7 +234,7 @@ class WalletListBodyState extends State { auth.hideProgressText(); auth.close(); WidgetsBinding.instance.addPostFrameCallback((_) { - navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false); + Navigator.of(context).pop(); }); } catch (e) { auth.changeProcessText( @@ -246,7 +246,7 @@ class WalletListBodyState extends State { changeProcessText(S.of(context).wallet_list_loading_wallet(wallet.name)); await widget.walletListViewModel.loadWallet(wallet); hideProgressText(); - navigatorKey.currentState!.pushNamedAndRemoveUntil(Routes.dashboard, (route) => false); + Navigator.of(context).pop(); } catch (e) { changeProcessText(S.of(context).wallet_list_failed_to_load(wallet.name, e.toString())); } diff --git a/lib/view_model/wallet_list/wallet_list_item.dart b/lib/view_model/wallet_list/wallet_list_item.dart index af30b9bea..ec03bdb64 100644 --- a/lib/view_model/wallet_list/wallet_list_item.dart +++ b/lib/view_model/wallet_list/wallet_list_item.dart @@ -1,17 +1,18 @@ -import 'package:flutter/foundation.dart'; +import 'package:cake_wallet/entities/desktop_dropdown_item.dart'; import 'package:cw_core/wallet_type.dart'; -class WalletListItem { - const WalletListItem( +class WalletListItem extends DesktopDropdownItem { + WalletListItem( {required this.name, required this.type, required this.key, this.isCurrent = false, - this.isEnabled = true}); + this.isEnabled = true, this.optionName = '',}); final String name; final WalletType type; final bool isCurrent; final dynamic key; final bool isEnabled; + final String optionName; } diff --git a/lib/view_model/wallet_list/wallet_list_view_model.dart b/lib/view_model/wallet_list/wallet_list_view_model.dart index 6d63675ba..9c89da1c7 100644 --- a/lib/view_model/wallet_list/wallet_list_view_model.dart +++ b/lib/view_model/wallet_list/wallet_list_view_model.dart @@ -1,5 +1,7 @@ import 'package:cake_wallet/core/auth_service.dart'; import 'package:cake_wallet/core/wallet_loading_service.dart'; +import 'package:cake_wallet/entities/desktop_dropdown_item.dart'; +import 'package:cake_wallet/generated/i18n.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/di.dart'; @@ -27,6 +29,21 @@ abstract class WalletListViewModelBase with Store { @observable ObservableList wallets; + @computed + ObservableList get dropdownItems { + final items = []; + + for (final wallet in wallets) { + items.add(wallet); + } + items.addAll([ + DropdownOption(name: S.current.create_new, optionName: "create_wallet"), + DropdownOption(name: S.current.restore_wallet, optionName: "restore_wallet"), + ]); + + return ObservableList.of(items); + } + final AppStore _appStore; final Box _walletInfoSource; final WalletLoadingService _walletLoadingService; From 88e245e480ed4d82d36eea52c0b857899deb3483 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Tue, 21 Feb 2023 12:22:32 +0200 Subject: [PATCH 6/9] Fix issues from code review --- .../screens/dashboard/desktop_dashboard_page.dart | 1 - .../desktop_settings/dashboard_settings_page.dart | 15 ++++----------- lib/src/widgets/setting_actions.dart | 10 ++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/src/screens/dashboard/desktop_dashboard_page.dart b/lib/src/screens/dashboard/desktop_dashboard_page.dart index c2b7285b7..f79d2f9e2 100644 --- a/lib/src/screens/dashboard/desktop_dashboard_page.dart +++ b/lib/src/screens/dashboard/desktop_dashboard_page.dart @@ -24,7 +24,6 @@ class DesktopDashboardPage extends StatelessWidget { final WalletAddressListViewModel addressListViewModel; static final GlobalKey desktopKey = GlobalKey(); - static final GlobalKey kex = GlobalKey(); bool _isEffectsInstalled = false; StreamSubscription? _onInactiveSub; diff --git a/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart b/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart index f4312aba4..8028e6057 100644 --- a/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart +++ b/lib/src/screens/settings/desktop_settings/dashboard_settings_page.dart @@ -16,7 +16,7 @@ class DesktopSettingsPage extends StatefulWidget { } class _DesktopSettingsPageState extends State { - final List _allItems = []; + final int itemCount = SettingActions.desktopSettings.length; int? currentPage; @@ -26,13 +26,6 @@ class _DesktopSettingsPageState extends State { }); } - @override - void initState() { - final allActions = List.from(SettingActions.all); - allActions.remove(SettingActions.walletSettingAction); - _allItems.addAll(allActions); super.initState(); - } - @override Widget build(BuildContext context) { return Scaffold( @@ -56,8 +49,8 @@ class _DesktopSettingsPageState extends State { child: ListView.separated( padding: EdgeInsets.only(top: 0), itemBuilder: (_, index) { - final item = _allItems[index]; - final isLastTile = index == _allItems.length - 1; + final item = SettingActions.desktopSettings[index]; + final isLastTile = index == itemCount - 1; return SettingActionButton( isLastTile: isLastTile, selectionActive: currentPage != null, @@ -79,7 +72,7 @@ class _DesktopSettingsPageState extends State { height: 1, color: Theme.of(context).primaryTextTheme.caption!.decorationColor!, ), - itemCount: _allItems.length, + itemCount: itemCount, ), ), ], diff --git a/lib/src/widgets/setting_actions.dart b/lib/src/widgets/setting_actions.dart index 76e5d2c76..043c8bd0e 100644 --- a/lib/src/widgets/setting_actions.dart +++ b/lib/src/widgets/setting_actions.dart @@ -24,6 +24,16 @@ class SettingActions { supportSettingAction, ]; + static List desktopSettings = [ + connectionSettingAction, + addressBookSettingAction, + securityBackupSettingAction, + privacySettingAction, + displaySettingAction, + otherSettingAction, + supportSettingAction, + ]; + static SettingActions connectionSettingAction = SettingActions._( name: S.current.connection_sync, image: 'assets/images/nodes_menu.png', From 07f6f43e0ba43825abd1c1670b2360e51721ddf5 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Tue, 21 Feb 2023 22:05:02 +0200 Subject: [PATCH 7/9] refactor dropdown items --- lib/entities/desktop_dropdown_item.dart | 23 +-- .../desktop_wallet_selection_dropdown.dart | 149 ++++++++---------- .../desktop_widgets/dropdown_item_widget.dart | 36 +++++ .../wallet_list/wallet_list_item.dart | 17 +- .../wallet_list/wallet_list_view_model.dart | 16 -- 5 files changed, 114 insertions(+), 127 deletions(-) create mode 100644 lib/src/screens/dashboard/desktop_widgets/dropdown_item_widget.dart diff --git a/lib/entities/desktop_dropdown_item.dart b/lib/entities/desktop_dropdown_item.dart index 235aa6d55..3a542f5e8 100644 --- a/lib/entities/desktop_dropdown_item.dart +++ b/lib/entities/desktop_dropdown_item.dart @@ -1,20 +1,9 @@ -import 'package:cw_core/wallet_type.dart'; +import 'package:flutter/material.dart'; -abstract class DesktopDropdownItem { - - final String name; - final WalletType type; - final bool isCurrent; - final dynamic key; - final bool isEnabled; - final String? optionName; +class DesktopDropdownItem { + final Function() onSelected; + final Widget child; + final bool isSelected; - DesktopDropdownItem({this.name = '', this.type = WalletType.none, this.isCurrent = false, this.key, this.isEnabled = true, this.optionName}); + DesktopDropdownItem({required this.onSelected, required this.child, this.isSelected = false}); } - -class DropdownOption extends DesktopDropdownItem { - DropdownOption({required this.name, required this.optionName}); - - final String name; - final String optionName; -} \ No newline at end of file diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart index 5c5cd557e..8197bd43a 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart @@ -3,6 +3,7 @@ import 'package:cake_wallet/entities/desktop_dropdown_item.dart'; import 'package:cake_wallet/generated/i18n.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_widgets/dropdown_item_widget.dart'; import 'package:cake_wallet/src/widgets/alert_with_two_actions.dart'; import 'package:cake_wallet/utils/show_bar.dart'; import 'package:cake_wallet/utils/show_pop_up.dart'; @@ -28,89 +29,75 @@ class _DesktopWalletSelectionDropDownState extends State? _progressBar; @override Widget build(BuildContext context) { final themeData = Theme.of(context); - return DropdownButton( - items: widget.walletListViewModel.dropdownItems - .map((wallet) => DropdownMenuItem( + final dropDownItems = [ + ...widget.walletListViewModel.wallets + .map((wallet) => DesktopDropdownItem( + isSelected: wallet.isCurrent, child: ConstrainedBox( constraints: BoxConstraints(maxWidth: 500), - child: walletListItemTile(wallet), + child: DropDownItemWidget( + title: wallet.name, + image: wallet.isEnabled ? _imageFor(type: wallet.type) : nonWalletTypeIcon), ), - value: wallet, + onSelected: () => _onSelectedWallet(wallet), )) .toList(), - onChanged: (selectedWallet) async { - if (selectedWallet!.isCurrent || !selectedWallet.isEnabled) { - return; - } - - if(selectedWallet is DropdownOption){ - _handleCreateOption(selectedWallet); - - return; - } - final confirmed = await showPopUp( - context: context, - builder: (dialogContext) { - return AlertWithTwoActions( - alertTitle: S.of(context).change_wallet_alert_title, - alertContent: S.of(context).change_wallet_alert_content(selectedWallet.name), - leftButtonText: S.of(context).cancel, - rightButtonText: S.of(context).change, - actionLeftButton: () => Navigator.of(context).pop(false), - actionRightButton: () => Navigator.of(context).pop(true)); - }) ?? - false; + DesktopDropdownItem( + onSelected: () => _navigateToCreateWallet(), + child: DropDownItemWidget(title: S.of(context).create_new, image: nonWalletTypeIcon), + ), + DesktopDropdownItem( + onSelected: () => _navigateToRestoreWallet(), + child: DropDownItemWidget(title: S.of(context).restore_wallet, image: nonWalletTypeIcon), + ), + ]; - if (confirmed && selectedWallet is WalletListItem) { - await _loadWallet(selectedWallet); - } + return DropdownButton( + items: dropDownItems + .map( + (wallet) => DropdownMenuItem( + child: wallet.child, + value: wallet, + ), + ) + .toList(), + onChanged: (item) { + item?.onSelected(); }, dropdownColor: themeData.textTheme.bodyText1?.decorationColor, style: TextStyle(color: themeData.primaryTextTheme.headline6?.color), - selectedItemBuilder: (context) => widget.walletListViewModel.dropdownItems - .map((wallet) => ConstrainedBox( - constraints: BoxConstraints(maxWidth: 500), - child: walletListItemTile(wallet), - )) - .toList(), - value: widget.walletListViewModel.dropdownItems.firstWhere((element) => element.isCurrent), + selectedItemBuilder: (context) => dropDownItems.map((item) => item.child).toList(), + value: dropDownItems.firstWhere((element) => element.isSelected), underline: const SizedBox(), focusColor: Colors.transparent, ); } - Widget walletListItemTile(DesktopDropdownItem wallet) { - return Container( - height: tileHeight, - padding: EdgeInsets.symmetric(horizontal: 20), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - children: [ - wallet.isEnabled ? _imageFor(type: wallet.type) : nonWalletTypeIcon, - SizedBox(width: 10), - Flexible( - child: Text( - wallet.name, - style: TextStyle( - fontSize: 22, - fontWeight: FontWeight.w500, - color: Theme.of(context).primaryTextTheme.headline6!.color!, - ), - overflow: TextOverflow.ellipsis, - maxLines: 1, - ), - ) - ], - ), - ); + void _onSelectedWallet(WalletListItem selectedWallet) async { + if (selectedWallet.isCurrent || !selectedWallet.isEnabled) { + return; + } + final confirmed = await showPopUp( + context: context, + builder: (dialogContext) { + return AlertWithTwoActions( + alertTitle: S.of(context).change_wallet_alert_title, + alertContent: S.of(context).change_wallet_alert_content(selectedWallet.name), + leftButtonText: S.of(context).cancel, + rightButtonText: S.of(context).change, + actionLeftButton: () => Navigator.of(context).pop(false), + actionRightButton: () => Navigator.of(context).pop(true)); + }) ?? + false; + + if (confirmed) { + await _loadWallet(selectedWallet); + } } Image _imageFor({required WalletType type}) { @@ -159,31 +146,23 @@ class _DesktopWalletSelectionDropDownState extends State(text, duration: null)..show(context); diff --git a/lib/src/screens/dashboard/desktop_widgets/dropdown_item_widget.dart b/lib/src/screens/dashboard/desktop_widgets/dropdown_item_widget.dart new file mode 100644 index 000000000..47efd04a7 --- /dev/null +++ b/lib/src/screens/dashboard/desktop_widgets/dropdown_item_widget.dart @@ -0,0 +1,36 @@ +import 'package:flutter/material.dart'; + +class DropDownItemWidget extends StatelessWidget { + const DropDownItemWidget({super.key, required this.title, required this.image}); + final double tileHeight = 60; + final Image image; + final String title; + + @override + Widget build(BuildContext context) { + return Container( + height: tileHeight, + padding: EdgeInsets.symmetric(horizontal: 20), + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ + image, + SizedBox(width: 10), + Flexible( + child: Text( + title, + style: TextStyle( + fontSize: 22, + fontWeight: FontWeight.w500, + color: Theme.of(context).primaryTextTheme.headline6!.color!, + ), + overflow: TextOverflow.ellipsis, + maxLines: 1, + ), + ) + ], + ), + ); + } +} diff --git a/lib/view_model/wallet_list/wallet_list_item.dart b/lib/view_model/wallet_list/wallet_list_item.dart index ec03bdb64..a644c07b3 100644 --- a/lib/view_model/wallet_list/wallet_list_item.dart +++ b/lib/view_model/wallet_list/wallet_list_item.dart @@ -1,18 +1,17 @@ -import 'package:cake_wallet/entities/desktop_dropdown_item.dart'; import 'package:cw_core/wallet_type.dart'; -class WalletListItem extends DesktopDropdownItem { - WalletListItem( - {required this.name, - required this.type, - required this.key, - this.isCurrent = false, - this.isEnabled = true, this.optionName = '',}); +class WalletListItem { + const WalletListItem({ + required this.name, + required this.type, + required this.key, + this.isCurrent = false, + this.isEnabled = true, + }); final String name; final WalletType type; final bool isCurrent; final dynamic key; final bool isEnabled; - final String optionName; } diff --git a/lib/view_model/wallet_list/wallet_list_view_model.dart b/lib/view_model/wallet_list/wallet_list_view_model.dart index 9c89da1c7..f44b3fd90 100644 --- a/lib/view_model/wallet_list/wallet_list_view_model.dart +++ b/lib/view_model/wallet_list/wallet_list_view_model.dart @@ -1,7 +1,5 @@ import 'package:cake_wallet/core/auth_service.dart'; import 'package:cake_wallet/core/wallet_loading_service.dart'; -import 'package:cake_wallet/entities/desktop_dropdown_item.dart'; -import 'package:cake_wallet/generated/i18n.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/di.dart'; @@ -29,20 +27,6 @@ abstract class WalletListViewModelBase with Store { @observable ObservableList wallets; - @computed - ObservableList get dropdownItems { - final items = []; - - for (final wallet in wallets) { - items.add(wallet); - } - items.addAll([ - DropdownOption(name: S.current.create_new, optionName: "create_wallet"), - DropdownOption(name: S.current.restore_wallet, optionName: "restore_wallet"), - ]); - - return ObservableList.of(items); - } final AppStore _appStore; final Box _walletInfoSource; From 6dc4eafff48f6f53c0f437429aef0598345a0b83 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Wed, 22 Feb 2023 18:44:49 +0200 Subject: [PATCH 8/9] Fix dropdown change state bug Hide scanner for desktop --- .../desktop_wallet_selection_dropdown.dart | 103 +++++++++++------- lib/src/widgets/address_text_field.dart | 11 +- lib/utils/device_info.dart | 11 ++ .../wallet_list/wallet_list_view_model.dart | 5 + 4 files changed, 86 insertions(+), 44 deletions(-) create mode 100644 lib/utils/device_info.dart diff --git a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart index 8197bd43a..1e714d992 100644 --- a/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart +++ b/lib/src/screens/dashboard/desktop_widgets/desktop_wallet_selection_dropdown.dart @@ -12,6 +12,7 @@ import 'package:cake_wallet/view_model/wallet_list/wallet_list_view_model.dart'; import 'package:cake_wallet/wallet_type_utils.dart'; import 'package:cw_core/wallet_type.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_mobx/flutter_mobx.dart'; class DesktopWalletSelectionDropDown extends StatefulWidget { final WalletListViewModel walletListViewModel; @@ -28,54 +29,74 @@ class _DesktopWalletSelectionDropDownState extends State Image.asset( + 'assets/images/new_wallet.png', + height: 12, + width: 12, + color: Theme.of(context).primaryTextTheme.headline6!.color!, + ); + Image _getRestoreWalletImage(BuildContext context) => Image.asset( + 'assets/images/restore_wallet.png', + height: 12, + width: 12, + color: Theme.of(context).primaryTextTheme.headline6!.color!, + ); Flushbar? _progressBar; @override Widget build(BuildContext context) { final themeData = Theme.of(context); - final dropDownItems = [ - ...widget.walletListViewModel.wallets - .map((wallet) => DesktopDropdownItem( - isSelected: wallet.isCurrent, - child: ConstrainedBox( - constraints: BoxConstraints(maxWidth: 500), - child: DropDownItemWidget( - title: wallet.name, - image: wallet.isEnabled ? _imageFor(type: wallet.type) : nonWalletTypeIcon), - ), - onSelected: () => _onSelectedWallet(wallet), - )) - .toList(), - DesktopDropdownItem( - onSelected: () => _navigateToCreateWallet(), - child: DropDownItemWidget(title: S.of(context).create_new, image: nonWalletTypeIcon), - ), - DesktopDropdownItem( - onSelected: () => _navigateToRestoreWallet(), - child: DropDownItemWidget(title: S.of(context).restore_wallet, image: nonWalletTypeIcon), - ), - ]; + return Observer(builder: (context) { + final dropDownItems = [ + ...widget.walletListViewModel.wallets + .map((wallet) => DesktopDropdownItem( + isSelected: wallet.isCurrent, + child: ConstrainedBox( + constraints: BoxConstraints(maxWidth: 500), + child: DropDownItemWidget( + title: wallet.name, + image: wallet.isEnabled ? _imageFor(type: wallet.type) : nonWalletTypeIcon), + ), + onSelected: () => _onSelectedWallet(wallet), + )) + .toList(), + DesktopDropdownItem( + onSelected: () => _navigateToCreateWallet(), + child: DropDownItemWidget( + title: S.of(context).create_new, + image: _getNewWalletImage(context), + ), + ), + DesktopDropdownItem( + onSelected: () => _navigateToRestoreWallet(), + child: DropDownItemWidget( + title: S.of(context).restore_wallet, + image: _getRestoreWalletImage(context), + ), + ), + ]; - return DropdownButton( - items: dropDownItems - .map( - (wallet) => DropdownMenuItem( - child: wallet.child, - value: wallet, - ), - ) - .toList(), - onChanged: (item) { - item?.onSelected(); - }, - dropdownColor: themeData.textTheme.bodyText1?.decorationColor, - style: TextStyle(color: themeData.primaryTextTheme.headline6?.color), - selectedItemBuilder: (context) => dropDownItems.map((item) => item.child).toList(), - value: dropDownItems.firstWhere((element) => element.isSelected), - underline: const SizedBox(), - focusColor: Colors.transparent, - ); + return DropdownButton( + items: dropDownItems + .map( + (wallet) => DropdownMenuItem( + child: wallet.child, + value: wallet, + ), + ) + .toList(), + onChanged: (item) { + item?.onSelected(); + }, + dropdownColor: themeData.textTheme.bodyText1?.decorationColor, + style: TextStyle(color: themeData.primaryTextTheme.headline6?.color), + selectedItemBuilder: (context) => dropDownItems.map((item) => item.child).toList(), + value: dropDownItems.firstWhere((element) => element.isSelected), + underline: const SizedBox(), + focusColor: Colors.transparent, + ); + }); } void _onSelectedWallet(WalletListItem selectedWallet) async { diff --git a/lib/src/widgets/address_text_field.dart b/lib/src/widgets/address_text_field.dart index 7e0727312..9db864343 100644 --- a/lib/src/widgets/address_text_field.dart +++ b/lib/src/widgets/address_text_field.dart @@ -1,3 +1,6 @@ +import 'dart:io'; + +import 'package:cake_wallet/utils/device_info.dart'; import 'package:flutter/services.dart'; import 'package:flutter/material.dart'; import 'package:cake_wallet/routes.dart'; @@ -100,7 +103,8 @@ class AddressTextField extends StatelessWidget { width: prefixIconWidth * options.length + (spaceBetweenPrefixIcons * options.length), child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: DeviceInfo.instance.isMobile + ? MainAxisAlignment.spaceBetween : MainAxisAlignment.end, children: [ SizedBox(width: 5), if (this.options.contains(AddressTextFieldOption.paste)) ...[ @@ -130,7 +134,8 @@ class AddressTextField extends StatelessWidget { )), )), ], - if (this.options.contains(AddressTextFieldOption.qrCode)) ...[ + if (this.options.contains(AddressTextFieldOption.qrCode) && DeviceInfo.instance.isMobile) + ...[ Container( width: prefixIconWidth, height: prefixIconHeight, @@ -156,7 +161,7 @@ class AddressTextField extends StatelessWidget { .decorationColor!, )), )) - ], + ] else SizedBox(width: 5), if (this .options .contains(AddressTextFieldOption.addressBook)) ...[ diff --git a/lib/utils/device_info.dart b/lib/utils/device_info.dart new file mode 100644 index 000000000..144ea3fa4 --- /dev/null +++ b/lib/utils/device_info.dart @@ -0,0 +1,11 @@ +import 'dart:io'; + +class DeviceInfo { + DeviceInfo._(); + + static DeviceInfo get instance => DeviceInfo._(); + + bool get isMobile => Platform.isAndroid || Platform.isIOS; + + bool get isDesktop => Platform.isMacOS || Platform.isWindows || Platform.isLinux; +} \ No newline at end of file diff --git a/lib/view_model/wallet_list/wallet_list_view_model.dart b/lib/view_model/wallet_list/wallet_list_view_model.dart index f44b3fd90..d6fcd7664 100644 --- a/lib/view_model/wallet_list/wallet_list_view_model.dart +++ b/lib/view_model/wallet_list/wallet_list_view_model.dart @@ -1,5 +1,9 @@ import 'package:cake_wallet/core/auth_service.dart'; import 'package:cake_wallet/core/wallet_loading_service.dart'; +import 'package:cw_core/balance.dart'; +import 'package:cw_core/transaction_history.dart'; +import 'package:cw_core/transaction_info.dart'; +import 'package:cw_core/wallet_base.dart'; import 'package:hive/hive.dart'; import 'package:mobx/mobx.dart'; import 'package:cake_wallet/di.dart'; @@ -22,6 +26,7 @@ abstract class WalletListViewModelBase with Store { this._authService, ) : wallets = ObservableList() { _updateList(); + reaction((_) => _appStore.wallet, (_) => _updateList()); } @observable From 24dc9bea27c93f4c74906ebec2325ef058992f94 Mon Sep 17 00:00:00 2001 From: Godwin Asuquo Date: Wed, 22 Feb 2023 18:47:00 +0200 Subject: [PATCH 9/9] remove space --- lib/view_model/wallet_list/wallet_list_view_model.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/view_model/wallet_list/wallet_list_view_model.dart b/lib/view_model/wallet_list/wallet_list_view_model.dart index d6fcd7664..fb6fe4c22 100644 --- a/lib/view_model/wallet_list/wallet_list_view_model.dart +++ b/lib/view_model/wallet_list/wallet_list_view_model.dart @@ -32,7 +32,6 @@ abstract class WalletListViewModelBase with Store { @observable ObservableList wallets; - final AppStore _appStore; final Box _walletInfoSource; final WalletLoadingService _walletLoadingService;