92 lines
2.5 KiB
Dart
92 lines
2.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
import 'core/router/app_router.dart';
|
|
import 'core/theme/app_theme.dart';
|
|
import 'features/auth/data/repositories/auth_repository_impl.dart';
|
|
import 'features/auth/domain/usecases/auth_usecases.dart';
|
|
import 'features/auth/presentation/bloc/auth_bloc.dart';
|
|
import 'features/auth/presentation/bloc/auth_event.dart';
|
|
|
|
Future<void> main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
|
|
// Inicializa SharedPreferences para persistencia de sesión
|
|
final prefs = await SharedPreferences.getInstance();
|
|
|
|
// Inyección de dependencias manual (Clean Architecture sin service locator)
|
|
// PRODUCCIÓN: Reemplazar con get_it o injectable para mayor escalabilidad
|
|
final authRepository = AuthRepositoryImpl(prefs);
|
|
|
|
final loginUseCase = LoginUseCase(authRepository);
|
|
final logoutUseCase = LogoutUseCase(authRepository);
|
|
final getStoredSessionUseCase = GetStoredSessionUseCase(authRepository);
|
|
|
|
final authBloc = AuthBloc(
|
|
loginUseCase: loginUseCase,
|
|
logoutUseCase: logoutUseCase,
|
|
getStoredSessionUseCase: getStoredSessionUseCase,
|
|
);
|
|
|
|
// Verifica sesión almacenada al iniciar
|
|
authBloc.add(const AuthSessionCheckRequested());
|
|
|
|
runApp(WasteNotifyApp(authBloc: authBloc));
|
|
}
|
|
|
|
/// Punto de entrada de la aplicación WasteNotify.
|
|
///
|
|
/// Arquitectura: Clean Architecture + BLoC + go_router
|
|
/// Privacidad: Sin rastreo GPS, sin mapas en tiempo real
|
|
/// Seguridad: Sesiones JWT simuladas (fase MVP)
|
|
class WasteNotifyApp extends StatelessWidget {
|
|
final AuthBloc authBloc;
|
|
|
|
const WasteNotifyApp({super.key, required this.authBloc});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocProvider.value(
|
|
value: authBloc,
|
|
child: _AppView(authBloc: authBloc),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _AppView extends StatefulWidget {
|
|
final AuthBloc authBloc;
|
|
|
|
const _AppView({required this.authBloc});
|
|
|
|
@override
|
|
State<_AppView> createState() => _AppViewState();
|
|
}
|
|
|
|
class _AppViewState extends State<_AppView> {
|
|
late final GoRouter _router;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_router = createRouter(widget.authBloc);
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_router.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp.router(
|
|
title: 'WasteNotify',
|
|
debugShowCheckedModeBanner: false,
|
|
theme: AppTheme.light,
|
|
routerConfig: _router,
|
|
);
|
|
}
|
|
}
|