From 617563fb6cf67b0c5563484f0b41d8a6c58d1d88 Mon Sep 17 00:00:00 2001 From: Artem Date: Tue, 30 Dec 2025 12:13:52 +0700 Subject: [PATCH] =?UTF-8?q?refactor(app):=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B8=20=D1=80=D0=BE=D1=83=D1=82=D0=B5=D1=80?= =?UTF-8?q?=20=D0=B1=D0=BB=D0=B8=D0=B6=D0=B5=20=D0=BA=20=D0=BC=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=83=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B2=20AppRoot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/app/app_root.dart | 61 ++++++++++++++++++++++++++++++-------- lib/runner/app_runner.dart | 2 +- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/lib/app/app_root.dart b/lib/app/app_root.dart index f2ca9c5..6a77673 100644 --- a/lib/app/app_root.dart +++ b/lib/app/app_root.dart @@ -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/l10n/gen/app_localizations.dart'; import 'package:friflex_starter/l10n/localization_notifier.dart'; +import 'package:friflex_starter/router/app_router.dart'; import 'package:go_router/go_router.dart'; /// {@template app} @@ -16,14 +17,11 @@ import 'package:go_router/go_router.dart'; /// {@endtemplate} class AppRoot extends StatelessWidget { /// {@macro app_root} - const AppRoot({required this.diContainer, required this.router, super.key}); + const AppRoot({required this.diContainer, super.key}); /// Контейнер зависимостей final DiContainer diContainer; - /// Роутер приложения - final GoRouter router; - @override Widget build(BuildContext context) { return AppProviders( @@ -36,14 +34,10 @@ class AppRoot extends StatelessWidget { data: MediaQuery.of( themeContext, ).copyWith(textScaler: TextScaler.noScaling, boldText: false), - child: MaterialApp.router( - darkTheme: AppTheme.dark, - theme: AppTheme.light, - themeMode: themeContext.theme.themeMode, - locale: localizationContext.localization.locale, - localizationsDelegates: AppLocalizations.localizationsDelegates, - supportedLocales: AppLocalizations.supportedLocales, - routerConfig: router, + child: _Internal( + diContainer: diContainer, + theme: themeContext.theme, + localization: localizationContext.localization, ), ), ); @@ -52,3 +46,46 @@ class AppRoot extends StatelessWidget { ); } } + +class _Internal extends StatefulWidget { + const _Internal({ + required this.theme, + required this.diContainer, + required this.localization, + }); + final ThemeNotifier theme; + + final DiContainer diContainer; + + final LocalizationNotifier localization; + @override + State<_Internal> createState() => _InternalState(); +} + +class _InternalState extends State<_Internal> { + /// Роутер приложения + late final GoRouter router; + + @override + void initState() { + super.initState(); + router = AppRouter.createRouter(widget.diContainer.debugService); + } + + @override + void dispose() { + router.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) => MaterialApp.router( + darkTheme: AppTheme.dark, + theme: AppTheme.light, + themeMode: widget.theme.themeMode, + locale: widget.localization.locale, + localizationsDelegates: AppLocalizations.localizationsDelegates, + supportedLocales: AppLocalizations.supportedLocales, + routerConfig: router, + ); +} diff --git a/lib/runner/app_runner.dart b/lib/runner/app_runner.dart index 6d8306f..483d86c 100644 --- a/lib/runner/app_runner.dart +++ b/lib/runner/app_runner.dart @@ -63,7 +63,7 @@ class AppRunner { ); // Инициализация метода обработки ошибок _initErrorHandlers(_debugService); - runApp(AppRoot(diContainer: diContainer, router: router)); + runApp(AppRoot(diContainer: diContainer)); await _onAppLoaded(); } on Object catch (e, stackTrace) { await _onAppLoaded();