Fix back swipe again

This commit is contained in:
franzap
2025-12-19 17:20:52 -03:00
parent 3de921f89b
commit c0d986520f
2 changed files with 13 additions and 2 deletions
+3
View File
@@ -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) {
+10 -2
View File
@@ -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);