From a659c75f1ab80b7ca06db5822e4e871a721a8cbe Mon Sep 17 00:00:00 2001 From: gabaldon Date: Tue, 22 Oct 2024 17:23:59 +0200 Subject: [PATCH] fix: avoid error when navigating and panel is open --- lib/util/panel.dart | 22 ++++++++++++++++++++-- lib/widgets/layouts/layout.dart | 21 +++++++++------------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/lib/util/panel.dart b/lib/util/panel.dart index c411e7ba1..fc7d11065 100644 --- a/lib/util/panel.dart +++ b/lib/util/panel.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; -import 'package:my_wit_wallet/widgets/layouts/layout.dart'; import 'package:my_wit_wallet/widgets/wallet_list.dart'; import 'package:my_wit_wallet/globals.dart' as globals; +import 'package:sliding_up_panel/sliding_up_panel.dart'; + +PanelController panelController = PanelController(); class PanelUtils { Widget panelContent = WalletList(); @@ -27,6 +29,22 @@ class PanelUtils { } } + PanelController getPanelController() { + return panelController; + } + + bool isAttached() { + return panelController.isAttached; + } + + bool isOpen() { + return panelController.isPanelOpen; + } + + bool isClose() { + return panelController.isPanelClosed; + } + void open({required Widget content}) { // FocusScope.of(context).unfocus(); setContent(content); @@ -39,7 +57,7 @@ class PanelUtils { } void close({Widget? content}) { - if (panelController.isPanelOpen) { + if (isAttached() && panelController.isPanelOpen) { Widget defaultContent = WalletList(); setContent(content ?? defaultContent); panelController.close(); diff --git a/lib/widgets/layouts/layout.dart b/lib/widgets/layouts/layout.dart index 53aeb0288..744f428df 100644 --- a/lib/widgets/layouts/layout.dart +++ b/lib/widgets/layouts/layout.dart @@ -52,11 +52,10 @@ class Layout extends StatefulWidget { LayoutState createState() => LayoutState(); } -final panelController = PanelController(); - class LayoutState extends State with TickerProviderStateMixin { ScrollController defaultScrollController = ScrollController(keepScrollOffset: false); + PanelUtils panel = PanelUtils(); bool get isUpdateCheckerEnabled => Platform.isMacOS || Platform.isLinux; bool get isDashboard => widget.dashboardActions != null; bool get allowBottomBar => @@ -186,10 +185,10 @@ class LayoutState extends State with TickerProviderStateMixin { void hidePanelOnMobileIfKeyboard() { if ((Platform.isAndroid || Platform.isIOS) && - FocusScope.of(context).isFirstFocus && - panelController.isAttached && - panelController.isPanelOpen) { - panelController.close(); + MediaQuery.of(context).viewInsets.bottom > 0 && + panel.isAttached() && + panel.isOpen()) { + panel.close(); } } @@ -202,7 +201,7 @@ class LayoutState extends State with TickerProviderStateMixin { // Hide panel if the mobile keyboard is open hidePanelOnMobileIfKeyboard(); return SlidingUpPanel( - controller: panelController, + controller: panel.getPanelController(), backdropEnabled: true, color: extendedTheme.panelBgColor!, minHeight: 0, @@ -397,9 +396,7 @@ class LayoutState extends State with TickerProviderStateMixin { InitScreen.route) { navigator.pop(), - if (panelController.isAttached && - panelController.isPanelOpen) - {panelController.close()} + if (panel.isAttached() && panel.isOpen()) {panel.close()} } }, ) @@ -418,8 +415,8 @@ class LayoutState extends State with TickerProviderStateMixin { ..onTapDown = (TapDownDetails details) { if (navigator.canPop()) { navigator.pop(); - if (panelController.isPanelOpen) { - panelController.close(); + if (panel.isOpen()) { + panel.close(); } } };