From eb6a4b9f87cbc451d79da8b2923c8426ef7a7cd2 Mon Sep 17 00:00:00 2001 From: Fabian Freund Date: Wed, 5 Jun 2024 04:45:00 +0200 Subject: [PATCH] fixed back button navigation --- app/lib/core/routing/routes.dart | 3 +++ app/lib/core/routing/routes.g.dart | 3 +++ .../search_browser/presentation/screens/browser.dart | 12 +++++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/lib/core/routing/routes.dart b/app/lib/core/routing/routes.dart index 0b72dc3b..0d27b805 100644 --- a/app/lib/core/routing/routes.dart +++ b/app/lib/core/routing/routes.dart @@ -8,12 +8,15 @@ import 'package:go_router/go_router.dart'; part 'routes.g.dart'; @TypedGoRoute( + name: 'KagiRoute', path: '/', routes: [ TypedGoRoute( + name: 'AboutRoute', path: 'about', ), TypedGoRoute( + name: 'SettingsRoute', path: 'settings', ), ], diff --git a/app/lib/core/routing/routes.g.dart b/app/lib/core/routing/routes.g.dart index fe009116..74562a2d 100644 --- a/app/lib/core/routing/routes.g.dart +++ b/app/lib/core/routing/routes.g.dart @@ -12,14 +12,17 @@ List get $appRoutes => [ RouteBase get $kagiRoute => GoRouteData.$route( path: '/', + name: 'KagiRoute', factory: $KagiRouteExtension._fromState, routes: [ GoRouteData.$route( path: 'about', + name: 'AboutRoute', factory: $AboutRouteExtension._fromState, ), GoRouteData.$route( path: 'settings', + name: 'SettingsRoute', factory: $SettingsRouteExtension._fromState, ), ], diff --git a/app/lib/features/search_browser/presentation/screens/browser.dart b/app/lib/features/search_browser/presentation/screens/browser.dart index e6b53b3b..412b33a9 100644 --- a/app/lib/features/search_browser/presentation/screens/browser.dart +++ b/app/lib/features/search_browser/presentation/screens/browser.dart @@ -249,6 +249,16 @@ class KagiScreen extends HookConsumerWidget { return BackButtonListener( onBackButtonPressed: () async { + //Don't do anything if a child route is active + if (GoRouterState.of(context).topRoute?.name != 'KagiRoute') { + return false; + } + + if (displayedSheet != null) { + ref.read(bottomSheetProvider.notifier).dismiss(); + return true; + } + if (activeWebView?.page.value.pageHistory.canGoBack == true) { lastBackButtonPress.value = null; @@ -257,7 +267,7 @@ class KagiScreen extends HookConsumerWidget { } if (lastBackButtonPress.value != null && - lastBackButtonPress.value!.difference(DateTime.now()) < + DateTime.now().difference(lastBackButtonPress.value!) < const Duration(seconds: 2)) { lastBackButtonPress.value = null;