2 Commits

8 changed files with 37 additions and 64 deletions

View File

@@ -6,7 +6,6 @@ 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}
@@ -14,39 +13,21 @@ import 'package:go_router/go_router.dart';
///
/// Отвечает за:
/// - Настройку провайдеров для темы и локализации
/// - Инициализацию роутера приложения
/// {@endtemplate}
class AppRoot extends StatefulWidget {
class AppRoot extends StatelessWidget {
/// {@macro app_root}
const AppRoot({required this.diContainer, super.key});
const AppRoot({required this.diContainer, required this.router, super.key});
/// Контейнер зависимостей
final DiContainer diContainer;
@override
State<AppRoot> createState() => _AppRootState();
}
class _AppRootState extends State<AppRoot> {
/// Роутер приложения
late final GoRouter router;
@override
void initState() {
super.initState();
router = AppRouter.createRouter(widget.diContainer.debugService);
}
@override
void dispose() {
router.dispose();
super.dispose();
}
final GoRouter router;
@override
Widget build(BuildContext context) {
return AppProviders(
diContainer: widget.diContainer,
diContainer: diContainer,
child: LocalizationConsumer(
builder: (localizationContext) {
return ThemeConsumer(

View File

@@ -37,6 +37,7 @@
- Статический метод `show` безопасно не откроет модалку, если `updateEntity == null`
Пример показа модального окна:
```dart
await SoftUpdateModal.show(
context,
@@ -54,10 +55,9 @@ await SoftUpdateModal.show(
- `UpdateRoutes.buildRoutes()` — регистрирует экран hard-обновления по пути `/update`
## Структура модуля
```
```md
features/update/
├── data/
│ └── repository/

View File

@@ -26,7 +26,7 @@ final class UpdateMockRepository implements IUpdateRepository {
@override
Future<UpdateEntity> checkForUpdates({
required String versionCode,
required String versionApp,
required String platform,
}) async {
// Имитация задержки для асинхронной операции

View File

@@ -14,7 +14,7 @@ final class UpdateRepository implements IUpdateRepository {
@override
Future<UpdateEntity> checkForUpdates({
required String versionCode,
required String versionApp,
required String platform,
}) {
// TODO: Реализовать реальную логику проверки обновлений

View File

@@ -6,11 +6,11 @@ import 'package:friflex_starter/features/update/domain/entity/update_entity.dart
/// {@endtemplate}
abstract interface class IUpdateRepository with DiBaseRepo {
/// Проверяет наличие обновлений
/// [versionCode] - текущий код версии приложения
/// [versionApp] - текущий версия приложения
/// [platform] - платформа (например, 'android' или 'ios')
/// Возвращает [UpdateEntity] с информацией об обновлении
Future<UpdateEntity> checkForUpdates({
required String versionCode,
required String versionApp,
required String platform,
});
}

View File

@@ -16,17 +16,17 @@ class UpdateCubit extends Cubit<UpdateState> {
final IUpdateRepository _updatesRepository;
/// Метод для проверки доступности обновлений
/// [versionCode] - текущий код версии приложения
/// [versionApp] - текущая версия приложения
/// [platform] - платформа (например, 'android' или 'ios')
Future<void> checkForUpdates({
required String versionCode,
required String versionApp,
required String platform,
}) async {
if (state is UpdateLoadingState) return;
emit(const UpdateLoadingState());
try {
final updateInfo = await _updatesRepository.checkForUpdates(
versionCode: versionCode,
versionApp: versionApp,
platform: platform,
);
emit(UpdateSuccessState(updateInfo));

View File

@@ -23,35 +23,23 @@ class AppRouter {
/// Метод для создания экземпляра GoRouter
static GoRouter createRouter(IDebugService debugService) {
try {
return _init(debugService);
} on Object catch (error, stackTrace) {
debugService.logError(
'Ошибка при создании роутера',
error: error,
stackTrace: stackTrace,
);
throw StateError('Не удалось создать роутер: $error');
}
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(),
],
);
}
/// Внутренний метод для инициализации роутера
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(),
],
);
}

View File

@@ -10,6 +10,7 @@ import 'package:friflex_starter/di/di_container.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/error/error_screen.dart';
import 'package:friflex_starter/router/app_router.dart';
import 'package:friflex_starter/runner/timer_runner.dart';
import 'package:go_router/go_router.dart';
@@ -32,7 +33,7 @@ class AppRunner {
/// Тип окружения сборки приложения¬
final AppEnv env;
/// Контейнер зависимостей приложения
/// Сервис отладки
late IDebugService _debugService;
/// Роутер приложения
@@ -56,6 +57,9 @@ class AppRunner {
// Инициализация приложения
await _initApp();
// Инициализация роутера
router = AppRouter.createRouter(_debugService);
final diContainer = await _initDependencies(
debugService: _debugService,
env: env,
@@ -63,7 +67,7 @@ class AppRunner {
);
// Инициализация метода обработки ошибок
_initErrorHandlers(_debugService);
runApp(AppRoot(diContainer: diContainer));
runApp(AppRoot(diContainer: diContainer, router: router));
await _onAppLoaded();
} on Object catch (e, stackTrace) {
await _onAppLoaded();