Skip to content

Commit

Permalink
fix: avoid error when navigating and panel is open
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Oct 22, 2024
1 parent 3d163a3 commit a659c75
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
22 changes: 20 additions & 2 deletions lib/util/panel.dart
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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);
Expand All @@ -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();
Expand Down
21 changes: 9 additions & 12 deletions lib/widgets/layouts/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,10 @@ class Layout extends StatefulWidget {
LayoutState createState() => LayoutState();
}

final panelController = PanelController();

class LayoutState extends State<Layout> 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 =>
Expand Down Expand Up @@ -186,10 +185,10 @@ class LayoutState extends State<Layout> 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();
}
}

Expand All @@ -202,7 +201,7 @@ class LayoutState extends State<Layout> 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,
Expand Down Expand Up @@ -397,9 +396,7 @@ class LayoutState extends State<Layout> with TickerProviderStateMixin {
InitScreen.route)
{
navigator.pop(),
if (panelController.isAttached &&
panelController.isPanelOpen)
{panelController.close()}
if (panel.isAttached() && panel.isOpen()) {panel.close()}
}
},
)
Expand All @@ -418,8 +415,8 @@ class LayoutState extends State<Layout> with TickerProviderStateMixin {
..onTapDown = (TapDownDetails details) {
if (navigator.canPop()) {
navigator.pop();
if (panelController.isPanelOpen) {
panelController.close();
if (panel.isOpen()) {
panel.close();
}
}
};
Expand Down

0 comments on commit a659c75

Please sign in to comment.