mirror of
https://github.com/smmarty/friflex_flutter_starter.git
synced 2026-02-05 03:32:18 +00:00
Compare commits
8 Commits
main
...
6f839aea24
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6f839aea24 | ||
|
|
617563fb6c | ||
|
|
75c0ac3285 | ||
|
|
4260c7cc65 | ||
|
|
2595692107 | ||
|
|
c86b4cc0bc | ||
|
|
d46c829959 | ||
|
|
84e5f5e869 |
@@ -6,6 +6,7 @@ import 'package:friflex_starter/app/theme/theme_notifier.dart';
|
|||||||
import 'package:friflex_starter/di/di_container.dart';
|
import 'package:friflex_starter/di/di_container.dart';
|
||||||
import 'package:friflex_starter/l10n/gen/app_localizations.dart';
|
import 'package:friflex_starter/l10n/gen/app_localizations.dart';
|
||||||
import 'package:friflex_starter/l10n/localization_notifier.dart';
|
import 'package:friflex_starter/l10n/localization_notifier.dart';
|
||||||
|
import 'package:friflex_starter/router/app_router.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
/// {@template app}
|
/// {@template app}
|
||||||
@@ -13,21 +14,39 @@ import 'package:go_router/go_router.dart';
|
|||||||
///
|
///
|
||||||
/// Отвечает за:
|
/// Отвечает за:
|
||||||
/// - Настройку провайдеров для темы и локализации
|
/// - Настройку провайдеров для темы и локализации
|
||||||
|
/// - Инициализацию роутера приложения
|
||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
class AppRoot extends StatelessWidget {
|
class AppRoot extends StatefulWidget {
|
||||||
/// {@macro app_root}
|
/// {@macro app_root}
|
||||||
const AppRoot({required this.diContainer, required this.router, super.key});
|
const AppRoot({required this.diContainer, super.key});
|
||||||
|
|
||||||
/// Контейнер зависимостей
|
/// Контейнер зависимостей
|
||||||
final DiContainer diContainer;
|
final DiContainer diContainer;
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AppRoot> createState() => _AppRootState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AppRootState extends State<AppRoot> {
|
||||||
/// Роутер приложения
|
/// Роутер приложения
|
||||||
final GoRouter router;
|
late final GoRouter router;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
router = AppRouter.createRouter(widget.diContainer.debugService);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
router.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AppProviders(
|
return AppProviders(
|
||||||
diContainer: diContainer,
|
diContainer: widget.diContainer,
|
||||||
child: LocalizationConsumer(
|
child: LocalizationConsumer(
|
||||||
builder: (localizationContext) {
|
builder: (localizationContext) {
|
||||||
return ThemeConsumer(
|
return ThemeConsumer(
|
||||||
|
|||||||
@@ -23,23 +23,35 @@ class AppRouter {
|
|||||||
|
|
||||||
/// Метод для создания экземпляра GoRouter
|
/// Метод для создания экземпляра GoRouter
|
||||||
static GoRouter createRouter(IDebugService debugService) {
|
static GoRouter createRouter(IDebugService debugService) {
|
||||||
return GoRouter(
|
try {
|
||||||
navigatorKey: rootNavigatorKey,
|
return _init(debugService);
|
||||||
initialLocation: initialLocation,
|
} on Object catch (error, stackTrace) {
|
||||||
observers: [debugService.routeObserver],
|
debugService.logError(
|
||||||
routes: [
|
'Ошибка при создании роутера',
|
||||||
StatefulShellRoute.indexedStack(
|
error: error,
|
||||||
parentNavigatorKey: rootNavigatorKey,
|
stackTrace: stackTrace,
|
||||||
builder: (context, state, navigationShell) =>
|
);
|
||||||
RootScreen(navigationShell: navigationShell),
|
throw StateError('Не удалось создать роутер: $error');
|
||||||
branches: [
|
}
|
||||||
MainRoutes.buildShellBranch(),
|
|
||||||
ProfileRoutes.buildShellBranch(),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
DebugRoutes.buildRoutes(),
|
|
||||||
UpdateRoutes.buildRoutes(),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Внутренний метод для инициализации роутера
|
||||||
|
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(),
|
||||||
|
],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import 'package:friflex_starter/di/di_container.dart';
|
|||||||
import 'package:friflex_starter/features/debug/debug_service.dart';
|
import 'package:friflex_starter/features/debug/debug_service.dart';
|
||||||
import 'package:friflex_starter/features/debug/i_debug_service.dart';
|
import 'package:friflex_starter/features/debug/i_debug_service.dart';
|
||||||
import 'package:friflex_starter/features/error/error_screen.dart';
|
import 'package:friflex_starter/features/error/error_screen.dart';
|
||||||
import 'package:friflex_starter/router/app_router.dart';
|
|
||||||
import 'package:friflex_starter/runner/timer_runner.dart';
|
import 'package:friflex_starter/runner/timer_runner.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
|
|
||||||
@@ -57,9 +56,6 @@ class AppRunner {
|
|||||||
// Инициализация приложения
|
// Инициализация приложения
|
||||||
await _initApp();
|
await _initApp();
|
||||||
|
|
||||||
// Инициализация роутера
|
|
||||||
router = AppRouter.createRouter(_debugService);
|
|
||||||
|
|
||||||
final diContainer = await _initDependencies(
|
final diContainer = await _initDependencies(
|
||||||
debugService: _debugService,
|
debugService: _debugService,
|
||||||
env: env,
|
env: env,
|
||||||
@@ -67,7 +63,7 @@ class AppRunner {
|
|||||||
);
|
);
|
||||||
// Инициализация метода обработки ошибок
|
// Инициализация метода обработки ошибок
|
||||||
_initErrorHandlers(_debugService);
|
_initErrorHandlers(_debugService);
|
||||||
runApp(AppRoot(diContainer: diContainer, router: router));
|
runApp(AppRoot(diContainer: diContainer));
|
||||||
await _onAppLoaded();
|
await _onAppLoaded();
|
||||||
} on Object catch (e, stackTrace) {
|
} on Object catch (e, stackTrace) {
|
||||||
await _onAppLoaded();
|
await _onAppLoaded();
|
||||||
|
|||||||
Reference in New Issue
Block a user