From 9189326c2041f4daaa0a2d9c491db606df7397df Mon Sep 17 00:00:00 2001 From: gabaldon Date: Tue, 12 Nov 2024 11:58:49 +0100 Subject: [PATCH] fix: add default size for panel if wallet list is not measured --- lib/util/get_sized_height.dart | 13 +++++++++++++ lib/widgets/layouts/dashboard_layout.dart | 16 ++++++++++++---- lib/widgets/layouts/layout.dart | 3 ++- lib/widgets/wallet_list.dart | 7 ------- 4 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 lib/util/get_sized_height.dart diff --git a/lib/util/get_sized_height.dart b/lib/util/get_sized_height.dart new file mode 100644 index 00000000..9af665ad --- /dev/null +++ b/lib/util/get_sized_height.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +double getWalletListSize(BuildContext context, int walletsLenght) { + double walletHeight = 98; + double actionHeight = 40; + return walletsLenght * walletHeight + actionHeight; +} + +double getBottomNavigationPadding(BuildContext context) { + return (MediaQuery.of(context).viewInsets.bottom + + kBottomNavigationBarHeight + + MediaQuery.of(context).viewPadding.bottom); +} diff --git a/lib/widgets/layouts/dashboard_layout.dart b/lib/widgets/layouts/dashboard_layout.dart index b24b43bb..90156189 100644 --- a/lib/widgets/layouts/dashboard_layout.dart +++ b/lib/widgets/layouts/dashboard_layout.dart @@ -5,8 +5,10 @@ import 'package:my_wit_wallet/util/current_route.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:my_wit_wallet/screens/login/bloc/login_bloc.dart'; import 'package:my_wit_wallet/shared/api_database.dart'; +import 'package:my_wit_wallet/util/get_sized_height.dart'; import 'package:my_wit_wallet/util/panel.dart'; import 'package:my_wit_wallet/util/storage/database/wallet.dart'; +import 'package:my_wit_wallet/util/storage/database/wallet_storage.dart'; import 'package:my_wit_wallet/widgets/bottom_navigation.dart'; import 'package:my_wit_wallet/widgets/send_receive.dart'; import 'package:my_wit_wallet/widgets/stake_unstake.dart'; @@ -45,13 +47,13 @@ class DashboardLayout extends StatefulWidget { class DashboardLayoutState extends State with TickerProviderStateMixin { - Wallet? walletStorage; late Timer explorerTimer; bool isAddressCopied = false; bool isCopyAddressFocus = false; FocusNode _copyToClipboardFocusNode = FocusNode(); - Wallet get currentWallet => - Locator.instance.get().walletStorage.currentWallet; + WalletStorage get walletStorage => + Locator.instance.get().walletStorage; + Wallet get currentWallet => walletStorage.currentWallet; PanelUtils get panel => Locator.instance.get(); Widget get panelContent => panel.getContent(); @@ -134,11 +136,17 @@ class DashboardLayoutState extends State children: [], ); } - + double walletListSize = + getWalletListSize(context, walletStorage.wallets.length); + double maxSize = MediaQuery.of(context).size.height * 0.8; return Layout( scrollController: widget.scrollController, topNavigation: TopNavigation( onShowWalletList: () async => { + // Sets panel height that shows the wallet list + panel.setHeight(walletListSize > maxSize + ? maxSize + : walletListSize), setState(() => panel.setContent(WalletList())), await panel.toggle(), }, diff --git a/lib/widgets/layouts/layout.dart b/lib/widgets/layouts/layout.dart index 18efe7a7..a342fee9 100644 --- a/lib/widgets/layouts/layout.dart +++ b/lib/widgets/layouts/layout.dart @@ -14,6 +14,7 @@ import 'package:my_wit_wallet/auto_updater_overlay.dart'; import 'package:my_wit_wallet/bloc/explorer/explorer_bloc.dart'; import 'package:my_wit_wallet/bloc/transactions/value_transfer/vtt_create/vtt_create_bloc.dart'; import 'package:my_wit_wallet/constants.dart'; +import 'package:my_wit_wallet/util/get_sized_height.dart'; import 'package:my_wit_wallet/util/panel.dart'; import 'package:my_wit_wallet/util/showTxConnectionError.dart'; import 'package:my_wit_wallet/widgets/layouts/listen_fourth_button.dart'; @@ -203,7 +204,7 @@ class LayoutState extends State with TickerProviderStateMixin { backdropEnabled: true, color: extendedTheme.panelBgColor!, minHeight: 0, - maxHeight: panel.getHeight(), + maxHeight: panel.getHeight() + getBottomNavigationPadding(context), borderRadius: BorderRadius.only( topLeft: extendedTheme.borderRadius!, topRight: extendedTheme.borderRadius!), diff --git a/lib/widgets/wallet_list.dart b/lib/widgets/wallet_list.dart index 0f146d00..7894a18e 100644 --- a/lib/widgets/wallet_list.dart +++ b/lib/widgets/wallet_list.dart @@ -8,7 +8,6 @@ import 'package:my_wit_wallet/screens/create_wallet/bloc/create_wallet_bloc.dart import 'package:my_wit_wallet/screens/create_wallet/create_wallet_screen.dart'; import 'package:my_wit_wallet/screens/dashboard/bloc/dashboard_bloc.dart'; import 'package:my_wit_wallet/shared/locator.dart'; -import 'package:my_wit_wallet/util/panel.dart'; import 'package:my_wit_wallet/util/sort_wallets_by_name.dart'; import 'package:my_wit_wallet/util/storage/database/account.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -189,12 +188,6 @@ class WalletListState extends State { @override Widget build(BuildContext context) { - double walletListSize = (sortedWalletsByName.length * 100) + 16; - double maxSize = MediaQuery.of(context).size.height * 0.8; - // Sets panel height that shows the wallet list - Locator.instance - .get() - .setHeight(walletListSize > maxSize ? maxSize : walletListSize); return SafeArea( top: false, child: ListView(padding: EdgeInsets.all(8), children: [