iOS navigation fixes: deep-link pop fallback + back-button PopScope

- notification_service: use GoRouter.go (not push) for terminal states
  (session_closing, session_expired) so the nav stack doesn't linger
  behind deep-linked screens
- chat_screen: PopScope + canPop fallback in client_app so iOS back
  gestures fall back to /home when there is nothing to pop
This commit is contained in:
2026-04-24 11:58:05 +08:00
parent 3a25ddc41d
commit 1a610363bb
2 changed files with 39 additions and 26 deletions

View File

@@ -89,9 +89,8 @@ class NotificationService {
final type = data['type'] as String?; final type = data['type'] as String?;
if (type == 'session_closing' || type == 'session_expired') { if (type == 'session_closing' || type == 'session_expired') {
// Navigate to the chat session — closure UI will show
if (sessionId != null) { if (sessionId != null) {
_router!.push('/chat/session/$sessionId', extra: 'Bestie'); _router!.go('/chat/session/$sessionId', extra: 'Bestie');
} }
} else if ((type == 'chat_message' || type == 'paired') && sessionId != null) { } else if ((type == 'chat_message' || type == 'paired') && sessionId != null) {
_router!.push('/chat/session/$sessionId', extra: 'Bestie'); _router!.push('/chat/session/$sessionId', extra: 'Bestie');

View File

@@ -74,6 +74,14 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
_scrollToBottom(); _scrollToBottom();
} }
void _exitChat() {
if (context.canPop()) {
context.pop();
} else {
context.go('/home');
}
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final chatState = ref.watch(chatProvider); final chatState = ref.watch(chatProvider);
@@ -112,7 +120,12 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
} }
}); });
return Scaffold( return PopScope(
canPop: false,
onPopInvokedWithResult: (didPop, _) {
if (!didPop) _exitChat();
},
child: Scaffold(
appBar: AppBar( appBar: AppBar(
backgroundColor: Colors.white, backgroundColor: Colors.white,
foregroundColor: Colors.black, foregroundColor: Colors.black,
@@ -120,7 +133,7 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
centerTitle: true, centerTitle: true,
leading: IconButton( leading: IconButton(
icon: const Icon(Icons.chevron_left, size: 28), icon: const Icon(Icons.chevron_left, size: 28),
onPressed: () => context.pop(), onPressed: _exitChat,
), ),
title: Text(widget.mitraName), title: Text(widget.mitraName),
actions: [ actions: [
@@ -140,6 +153,7 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
], ],
), ),
body: _buildBody(chatState, closureState), body: _buildBody(chatState, closureState),
),
); );
} }