Skip to content

Commit

Permalink
fix: close panel on player route pop
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesterday17 committed Sep 17, 2024
1 parent 385bd02 commit 4251872
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/router.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:annix/providers.dart';
import 'package:annix/services/theme.dart';
import 'package:annix/ui/route/delegate.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:annix/services/anniv/anniv_model.dart';
Expand Down Expand Up @@ -39,6 +40,7 @@ GoRouter buildRouter(Ref ref) {
navigatorKey: _mainNavigatorKey,
observers: [
ThemePopObserver(ref.read(themeProvider)),
PlayerRouteObserver(ref.read(routerProvider)),
],
builder: (context, state, child) {
return AnnixLayout(child: child);
Expand Down
15 changes: 10 additions & 5 deletions lib/ui/layout/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class AnnixLayout extends HookConsumerWidget {
final currentIndex =
pages.contains(router.location) ? pages.indexOf(router.location) : null;
onDestinationSelected(final index) {
if (index >= pages.length && router.canPop()) {
router.pop();
return;
}

context.go(
pages[index],
// pageBuilder: fadeThroughTransitionBuilder,
Expand Down Expand Up @@ -214,11 +219,11 @@ class AnnixLayout extends HookConsumerWidget {
),
)
.toList(),
// NavigationRailDestination(
// icon: const Icon(Icons.arrow_back),
// label: const Text('back'),
// disabled: !router.mayPop(),
// )
const NavigationRailDestination(
icon: Icon(Icons.arrow_back),
label: Text('back'),
// disabled: !router.canPop(),
)
],
),
),
Expand Down
13 changes: 13 additions & 0 deletions lib/ui/route/delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,16 @@ class AnnixRouterDelegate with ChangeNotifier {

AnnixRouterDelegate(this.ref);
}

class PlayerRouteObserver extends NavigatorObserver {
final AnnixRouterDelegate delegate;

PlayerRouteObserver(this.delegate);

@override
didPop(final Route<dynamic> route, final Route<dynamic>? previousRoute) {
if (['/player'].contains(route.settings.name)) {
delegate.closePanel();
}
}
}
4 changes: 4 additions & 0 deletions macos/Runner/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ class AppDelegate: FlutterAppDelegate {
override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
return true
}

override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
return true
}
}

0 comments on commit 4251872

Please sign in to comment.