Files
iiEsaywebUIapp/lib/core/services/deep_link_service.dart

71 lines
1.9 KiB
Dart
Raw Normal View History

2025-08-10 01:20:45 +05:30
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../features/chat/views/chat_page.dart';
2025-08-22 01:24:04 +05:30
import '../../features/files/views/workspace_page.dart';
2025-08-10 01:20:45 +05:30
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,
);
}
2025-08-22 01:24:04 +05:30
/// In single-screen mode, workspace/profile deep links route via navigator
static void navigateToWorkspace(BuildContext context) {
2025-08-10 01:20:45 +05:30
Navigator.push(
context,
2025-08-22 01:24:04 +05:30
MaterialPageRoute(builder: (context) => const WorkspacePage()),
2025-08-10 01:20:45 +05:30
);
}
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';
2025-08-22 01:24:04 +05:30
// Support both new and legacy paths for workspace
case '/workspace':
case '/main/workspace':
case '/files': // legacy
case '/main/files': // legacy
return '/workspace';
2025-08-10 01:20:45 +05:30
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) {
2025-08-22 01:24:04 +05:30
case '/workspace':
return const WorkspacePage();
2025-08-10 01:20:45 +05:30
case '/profile':
return const ProfilePage();
case '/chat':
default:
return const ChatPage();
}
}
}
/// Provider for deep link navigation
final deepLinkProvider = Provider<DeepLinkService>((ref) => DeepLinkService());