fixed back button navigation

This commit is contained in:
Fabian Freund
2024-06-05 04:45:00 +02:00
parent 99c035b246
commit eb6a4b9f87
3 changed files with 17 additions and 1 deletions
+3
View File
@@ -8,12 +8,15 @@ import 'package:go_router/go_router.dart';
part 'routes.g.dart';
@TypedGoRoute<KagiRoute>(
name: 'KagiRoute',
path: '/',
routes: [
TypedGoRoute<AboutRoute>(
name: 'AboutRoute',
path: 'about',
),
TypedGoRoute<SettingsRoute>(
name: 'SettingsRoute',
path: 'settings',
),
],
+3
View File
@@ -12,14 +12,17 @@ List<RouteBase> 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,
),
],
@@ -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;