2026-03-08 16:05:08 +05:30
|
|
|
import 'package:flutter/material.dart';
|
2026-03-08 21:55:52 +05:30
|
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
|
import 'package:real_estate_mobile/core/services/push_notification_service.dart';
|
2026-03-08 16:05:08 +05:30
|
|
|
import 'package:real_estate_mobile/core/widgets/app_bottom_nav_bar.dart';
|
|
|
|
|
import 'package:real_estate_mobile/features/home/presentation/widgets/home_header.dart';
|
|
|
|
|
|
|
|
|
|
/// Root shell that provides the persistent header and bottom nav bar.
|
|
|
|
|
/// Only the content area (child) swaps when navigating between tabs.
|
2026-03-08 21:55:52 +05:30
|
|
|
class AppShell extends StatefulWidget {
|
2026-03-08 16:05:08 +05:30
|
|
|
final Widget child;
|
|
|
|
|
|
|
|
|
|
const AppShell({super.key, required this.child});
|
|
|
|
|
|
2026-03-08 21:55:52 +05:30
|
|
|
@override
|
|
|
|
|
State<AppShell> createState() => _AppShellState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _AppShellState extends State<AppShell> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
// Wire push notification taps to GoRouter navigation
|
2026-04-08 21:24:35 +05:30
|
|
|
PushNotificationService().onNotificationTap = (data) {
|
2026-03-31 05:59:38 +05:30
|
|
|
if (!mounted) return;
|
2026-04-08 21:24:35 +05:30
|
|
|
debugPrint('[AppShell] Notification tap: $data');
|
|
|
|
|
|
|
|
|
|
// Extract the conversationId from every possible source — FCM payloads
|
|
|
|
|
// from different backends/versions may use different keys, and the
|
|
|
|
|
// link/actionUrl may carry it as a query parameter instead.
|
|
|
|
|
final convId = _extractConversationId(data);
|
|
|
|
|
final type = (data['type'] as String?)?.toLowerCase();
|
|
|
|
|
final link = (data['link'] as String?) ?? (data['actionUrl'] as String?);
|
|
|
|
|
final looksLikeMessage = type == 'message' ||
|
|
|
|
|
(link != null && link.contains('/message'));
|
|
|
|
|
|
|
|
|
|
if (looksLikeMessage && convId != null && convId.isNotEmpty) {
|
|
|
|
|
debugPrint('[AppShell] → /messages/chat/$convId');
|
|
|
|
|
context.go('/messages/chat/$convId');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (type == 'connection_request' || type == 'connection_response') {
|
|
|
|
|
context.go('/notifications');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fall back to actionUrl translation (web-style URLs)
|
|
|
|
|
if (link == null || link.isEmpty) {
|
2026-03-08 21:55:52 +05:30
|
|
|
context.go('/notifications');
|
2026-03-31 05:59:38 +05:30
|
|
|
return;
|
2026-03-08 21:55:52 +05:30
|
|
|
}
|
2026-04-08 21:24:35 +05:30
|
|
|
final mobileRoute = _translateRoute(link);
|
|
|
|
|
debugPrint('[AppShell] → $mobileRoute (from link=$link)');
|
2026-03-31 05:59:38 +05:30
|
|
|
context.go(mobileRoute);
|
2026-03-08 21:55:52 +05:30
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-08 21:24:35 +05:30
|
|
|
/// Try every known source for a conversation id — direct keys, or
|
|
|
|
|
/// query parameters on the link/actionUrl.
|
|
|
|
|
String? _extractConversationId(Map<String, dynamic> data) {
|
|
|
|
|
// Direct keys (backend sends `conversationId`)
|
|
|
|
|
for (final key in const [
|
|
|
|
|
'conversationId',
|
|
|
|
|
'conversation_id',
|
|
|
|
|
'convId',
|
|
|
|
|
'chatId',
|
|
|
|
|
]) {
|
|
|
|
|
final v = data[key];
|
|
|
|
|
if (v is String && v.isNotEmpty) return v;
|
|
|
|
|
}
|
|
|
|
|
// Query parameter on the link or actionUrl
|
|
|
|
|
for (final key in const ['link', 'actionUrl']) {
|
|
|
|
|
final raw = data[key];
|
|
|
|
|
if (raw is String && raw.isNotEmpty) {
|
|
|
|
|
try {
|
|
|
|
|
final uri = Uri.parse(raw);
|
|
|
|
|
final qp = uri.queryParameters['conversationId'] ??
|
|
|
|
|
uri.queryParameters['conversation_id'];
|
|
|
|
|
if (qp != null && qp.isNotEmpty) return qp;
|
|
|
|
|
} catch (_) {}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-31 05:59:38 +05:30
|
|
|
/// Translate web-style actionUrl to mobile route.
|
|
|
|
|
String _translateRoute(String url) {
|
|
|
|
|
final uri = Uri.parse(url);
|
|
|
|
|
final path = uri.path;
|
|
|
|
|
|
|
|
|
|
// Message notification: /user/message?conversationId=xxx or /agent/message?conversationId=xxx
|
|
|
|
|
if (path.contains('/message')) {
|
|
|
|
|
final convId = uri.queryParameters['conversationId'];
|
|
|
|
|
if (convId != null && convId.isNotEmpty) {
|
|
|
|
|
return '/messages/chat/$convId';
|
|
|
|
|
}
|
|
|
|
|
return '/messages';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Connection request/network
|
|
|
|
|
if (path.contains('/network')) {
|
|
|
|
|
// Agent sees network, user sees agent search
|
|
|
|
|
if (path.startsWith('/agent')) {
|
|
|
|
|
return '/agent/network';
|
|
|
|
|
}
|
|
|
|
|
return '/agents/search';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Profile routes
|
|
|
|
|
if (path.contains('/profiles') || path.contains('/profile')) {
|
|
|
|
|
return '/home';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If it's already a valid mobile route, use as-is
|
|
|
|
|
if (path.startsWith('/messages') ||
|
|
|
|
|
path.startsWith('/home') ||
|
|
|
|
|
path.startsWith('/notifications') ||
|
|
|
|
|
path.startsWith('/agents')) {
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fallback
|
|
|
|
|
return '/notifications';
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-08 16:05:08 +05:30
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
body: Column(
|
|
|
|
|
children: [
|
|
|
|
|
SafeArea(
|
|
|
|
|
bottom: false,
|
|
|
|
|
child: const HomeHeader(),
|
|
|
|
|
),
|
|
|
|
|
Expanded(
|
2026-04-02 17:57:57 +05:30
|
|
|
child: widget.child,
|
2026-03-08 16:05:08 +05:30
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
bottomNavigationBar: const AppBottomNavBar(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|