From c0d986520fb6d061970ddf9f8dea94271d6ec6e0 Mon Sep 17 00:00:00 2001 From: franzap <_@franzap.com> Date: Fri, 19 Dec 2025 17:20:52 -0300 Subject: [PATCH] Fix back swipe again --- lib/router.dart | 3 +++ lib/screens/main_scaffold.dart | 12 ++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/router.dart b/lib/router.dart index 60bfd3f..6debe74 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -8,6 +8,9 @@ import 'package:zapstore/screens/search_screen.dart'; import 'package:zapstore/screens/updates_screen.dart'; import 'package:zapstore/screens/profile_screen.dart'; +/// Root paths for each navigation branch (used for back navigation handling) +const kBranchRoots = ['/search', '/updates', '/profile']; + typedef _ResolvedAppRoute = ({String identifier, String? author}); _ResolvedAppRoute _resolveAppRouteId(String rawId) { diff --git a/lib/screens/main_scaffold.dart b/lib/screens/main_scaffold.dart index 9dff5fb..49054f4 100644 --- a/lib/screens/main_scaffold.dart +++ b/lib/screens/main_scaffold.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:models/models.dart'; +import 'package:zapstore/router.dart'; import 'package:zapstore/services/updates_service.dart'; import 'package:zapstore/widgets/common/badges.dart'; import '../widgets/common/profile_avatar.dart'; @@ -39,8 +40,15 @@ class MainScaffold extends StatelessWidget { canPop: false, // Never let system close the app via back gesture onPopInvokedWithResult: (didPop, result) { if (!didPop) { - if (router.canPop()) { - router.pop(); // Go back if possible + // Check if we can pop within the current shell branch + // canPop() may return true for shell-level navigation, so we need + // to verify we're not at a branch root before popping + final currentLocation = + router.routerDelegate.currentConfiguration.uri.path; + final isAtBranchRoot = kBranchRoots.contains(currentLocation); + + if (!isAtBranchRoot && router.canPop()) { + router.pop(); // Go back within the branch } else if (navigationShell.currentIndex != 0) { // At root of non-home tab, go to home (search) tab navigationShell.goBranch(0);