Repository navigation
fix(navigation): histórico de navegação para o botão voltar do Android - #75
Merged
Merged
Conversation
Adds AppBackHandler (PopScope) and the context.backOr extension so the Android hardware back button pops the router stack, falls back to a parent route when the stack is empty (deep link or web reload) and asks for exit confirmation on root screens. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Forward navigation now uses context.push instead of context.go, which was replacing the whole stack and left the hardware back button with nothing to pop (closing the app). Back/cancel actions use context.backOr with the parent route, screens created from a form use pushReplacement so the form leaves the history, and every screen is wrapped in AppBackHandler. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sends the platform popRoute message to assert popping to the previous screen, dialog dismissal, the parent fallback when there is no history, and the exit confirmation flow on the root screen. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problema
O botão físico de voltar do Android fechava o aplicativo em qualquer tela. Toda a navegação usava
context.go(...), que substitui a pilha do go_router: sem pilha, o back não tinha o que desempilhar.Solução
Novo
lib/shared/routing/navigation.dart:context.backOr(fallback): desempilha se houver histórico, senão navega para a rota pai (cobre deep link e reload no web, onde a pilha nasce vazia).AppBackHandler:PopScope(canPop: false)que centraliza a decisão do back físico:router.pop()fallbackLocation->router.go(fallback)fallbackLocation == null) -> diálogo de confirmação eSystemNavigator.pop()Diálogos e bottom sheets continuam fechando normalmente: o framework só consulta a rota do topo, e o
AppBackHandlerfica na rota da tela, abaixo deles.Mudanças de navegação
gopara avançar (home -> fichas/NPCs/campanhas, campanha -> sessão, lista -> formulário, login -> registro)push(empilha)gonos botões voltar/cancelar e após salvarbackOr('<rota pai>')goapós criar/entrar em campanha e troca de sessãopushReplacement(o formulário sai do histórico)go('/')ao finalizar/sair da campanhaAs 10 telas foram envolvidas com
AppBackHandler, incluindo os estados de loading/erro. Home e login são raiz e pedem confirmação de saída.Testes
test/shared/routing/navigation_test.dartdispara a mensagem de plataformapopRoute(o mesmo caminho do back físico) e cobre: pop para a tela anterior, fechamento de diálogo, fallback sem histórico e o fluxo de confirmação de saída (cancelar não chamaSystemNavigator.pop, confirmar chama).flutter analyze: sem issuesflutter test: 139 testes passandoValidação pendente
Sem teste em device físico: com
canPop: falseo gesto de back preditivo do Android 14+ perde a animação de preview, mantendo o comportamento funcional.🤖 Generated with Claude Code