Files
iiEsaywebUIapp/lib/core/services/deep_link_service.dart
2025-08-22 01:24:04 +05:30

71 lines
1.9 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../features/chat/views/chat_page.dart';
import '../../features/files/views/workspace_page.dart';
import '../../features/profile/views/profile_page.dart';
/// Service for handling deep links and navigation routing
class DeepLinkService {
/// Route to chat tab
static void navigateToChat(BuildContext context) {
Navigator.pushAndRemoveUntil(
context,
MaterialPageRoute(builder: (context) => const ChatPage()),
(route) => false,
);
}
/// In single-screen mode, workspace/profile deep links route via navigator
static void navigateToWorkspace(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const WorkspacePage()),
);
}
static void navigateToProfile(BuildContext context) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const ProfilePage()),
);
}
/// Parse route and determine target tab
static String? parsePath(String route) {
switch (route) {
case '/chat':
case '/main/chat':
return '/chat';
// Support both new and legacy paths for workspace
case '/workspace':
case '/main/workspace':
case '/files': // legacy
case '/main/files': // legacy
return '/workspace';
case '/profile':
case '/main/profile':
return '/profile';
default:
return null;
}
}
/// Handle deep link navigation
static Widget handleDeepLink(String route) {
final path = parsePath(route);
switch (path) {
case '/workspace':
return const WorkspacePage();
case '/profile':
return const ProfilePage();
case '/chat':
default:
return const ChatPage();
}
}
}
/// Provider for deep link navigation
final deepLinkProvider = Provider<DeepLinkService>((ref) => DeepLinkService());