refactor(router): улучшить обработку ошибок при создании роутера

refactor(app): изменить AppRoot на StatefulWidget и переместить инициализацию роутера
This commit is contained in:
Artem
2025-12-30 12:18:23 +07:00
parent 617563fb6c
commit 6f839aea24
2 changed files with 60 additions and 66 deletions

View File

@@ -23,23 +23,35 @@ class AppRouter {
/// Метод для создания экземпляра GoRouter
static GoRouter createRouter(IDebugService debugService) {
return GoRouter(
navigatorKey: rootNavigatorKey,
initialLocation: initialLocation,
observers: [debugService.routeObserver],
routes: [
StatefulShellRoute.indexedStack(
parentNavigatorKey: rootNavigatorKey,
builder: (context, state, navigationShell) =>
RootScreen(navigationShell: navigationShell),
branches: [
MainRoutes.buildShellBranch(),
ProfileRoutes.buildShellBranch(),
],
),
DebugRoutes.buildRoutes(),
UpdateRoutes.buildRoutes(),
],
);
try {
return _init(debugService);
} on Object catch (error, stackTrace) {
debugService.logError(
'Ошибка при создании роутера',
error: error,
stackTrace: stackTrace,
);
throw StateError('Не удалось создать роутер: $error');
}
}
/// Внутренний метод для инициализации роутера
static GoRouter _init(IDebugService debugService) => GoRouter(
navigatorKey: rootNavigatorKey,
initialLocation: initialLocation,
observers: [debugService.routeObserver],
routes: [
StatefulShellRoute.indexedStack(
parentNavigatorKey: rootNavigatorKey,
builder: (context, state, navigationShell) =>
RootScreen(navigationShell: navigationShell),
branches: [
MainRoutes.buildShellBranch(),
ProfileRoutes.buildShellBranch(),
],
),
DebugRoutes.buildRoutes(),
UpdateRoutes.buildRoutes(),
],
);
}