Skip to content

Commit

Permalink
fix sidebar overlay with dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
ArthurHeitmann committed Sep 7, 2024
1 parent 1bc1cee commit 1ee3984
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ void init(List<String> args) async {

final _rootKey = GlobalKey<ScaffoldState>(debugLabel: "RootGlobalKey");

final routeObserver = RouteObserver<Route>();

BuildContext getGlobalContext() => _rootKey.currentContext!;

class MyApp extends StatefulWidget {
Expand Down Expand Up @@ -137,6 +139,7 @@ class _MyAppState extends State<MyApp> {
return MaterialApp(
title: "F-SERVO",
debugShowCheckedModeBanner: false,
navigatorObservers: [routeObserver],
theme: PreferencesData().makeTheme(context),
home: MyAppBody(key: _rootKey)
);
Expand Down
32 changes: 31 additions & 1 deletion lib/widgets/layout/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:math';

import 'package:flutter/material.dart';

import '../../main.dart';
import '../../utils/utils.dart';
import '../theme/customTheme.dart';

Expand Down Expand Up @@ -31,7 +32,7 @@ class Sidebar extends StatefulWidget {
State<Sidebar> createState() => _SidebarState();
}

class _SidebarState extends State<Sidebar> {
class _SidebarState extends State<Sidebar> with RouteAware {
int _selectedIndex = 0;
double _width = 0;
bool _isExpanded = true;
Expand All @@ -53,15 +54,44 @@ class _SidebarState extends State<Sidebar> {
)
);
Overlay.of(context).insert(_draggableOverlayEntry!);
routeObserver.subscribe(this, ModalRoute.of(context)!);
});
}

@override
void dispose() {
_draggableOverlayEntry?.remove();
routeObserver.unsubscribe(this);
super.dispose();
}

@override
void didPopNext() {
onNavigatorChange();
}
@override
void didPushNext() {
onNavigatorChange();
}
void onNavigatorChange() {
if (ModalRoute.of(context)?.isCurrent == true) {
if (_draggableOverlayEntry == null) {
_draggableOverlayEntry = OverlayEntry(
builder: (context) => _ResizeHandle(
layerLink: _layerLink,
switcherPosition: widget.switcherPosition,
onWidthChanged: (w) => _onDrag(context, w),
)
);
Overlay.of(context).insert(_draggableOverlayEntry!);
}
}
else {
_draggableOverlayEntry?.remove();
_draggableOverlayEntry = null;
}
}

void _onDrag(BuildContext overlayContext, double width) {
_width += width;
if (_width < 150)
Expand Down

0 comments on commit 1ee3984

Please sign in to comment.