forked from eatvio/eatvio_app
81 lines
2.8 KiB
Dart
81 lines
2.8 KiB
Dart
import 'package:eatvio_app/core/routing/auth_routes.dart';
|
|
import 'package:eatvio_app/core/routing/content_routes.dart';
|
|
import 'package:eatvio_app/core/routing/main_navigation_routes.dart';
|
|
import 'package:eatvio_app/core/routing/other_routes.dart';
|
|
import 'package:eatvio_app/core/routing/route_constants.dart';
|
|
import 'package:eatvio_app/core/routing/settings_routes.dart';
|
|
import 'package:eatvio_app/features/auth/entities/auth_result_entity.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_native_splash/flutter_native_splash.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
|
|
/// Главный роутер приложения
|
|
class AppRouter {
|
|
static GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
static GoRouter appRouter = GoRouter(
|
|
initialLocation: RouteConstants.updateScreen,
|
|
navigatorKey: navigatorKey,
|
|
redirect: _handleRedirect,
|
|
routes: [
|
|
...AuthRoutes.createRoutes(),
|
|
...MainNavigationRoutes.createRoutes(),
|
|
...ContentRoutes.createRoutes(),
|
|
...SettingsRoutes.createRoutes(),
|
|
...OtherRoutes.createRoutes(),
|
|
],
|
|
);
|
|
|
|
/// Обработка редиректов для deep links
|
|
static String? _handleRedirect(BuildContext context, GoRouterState state) {
|
|
final segments = state.uri.pathSegments;
|
|
if (segments.length == 4) {
|
|
final type = segments[1];
|
|
switch (type) {
|
|
case 'diary':
|
|
FlutterNativeSplash.remove();
|
|
return '/diary-screen';
|
|
}
|
|
}
|
|
if (segments.length == 3) {
|
|
final type = segments[1];
|
|
final contentIdentifier = segments[2];
|
|
|
|
switch (type) {
|
|
case 'recipe':
|
|
FlutterNativeSplash.remove();
|
|
return '/about-recipes-screen?slug=$contentIdentifier';
|
|
case 'blog_post':
|
|
FlutterNativeSplash.remove();
|
|
return '/blog-post-screen?id=$contentIdentifier';
|
|
case 'plan':
|
|
FlutterNativeSplash.remove();
|
|
return '/about-plan-screen?slug=$contentIdentifier';
|
|
case 'diet':
|
|
FlutterNativeSplash.remove();
|
|
return '/about-diet-screen?slug=$contentIdentifier';
|
|
case 'chat':
|
|
FlutterNativeSplash.remove();
|
|
return '/chat-select-screen';
|
|
case 'profile':
|
|
FlutterNativeSplash.remove();
|
|
return '/profile-screen?slug=$contentIdentifier';
|
|
}
|
|
}
|
|
if (segments.length == 2) {
|
|
final type = segments[1];
|
|
switch (type) {
|
|
case 'chat':
|
|
FlutterNativeSplash.remove();
|
|
return '/chat-select-screen';
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
static void navigateToRegisterViaSocial({required AuthResultEntity authResult, required String provider}) {
|
|
appRouter.pushNamed('registerViaSocialScreen', extra: {'authResult': authResult, 'provider': provider});
|
|
}
|
|
}
|