feat:implementacion grafica 2.0

This commit is contained in:
25030248hasel
2026-05-22 18:43:29 -06:00
parent a0f2ce40b1
commit cb005d33f6
22 changed files with 2047 additions and 108 deletions

View File

@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-all.zip

View File

@@ -18,7 +18,7 @@ pluginManagement {
plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false
id "com.android.application" version "8.2.1" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

View File

@@ -0,0 +1,121 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../features/auth/presentation/bloc/auth_bloc.dart';
import '../../features/auth/presentation/bloc/auth_state.dart';
import '../../features/auth/presentation/screens/login_screen.dart';
import '../../features/auth/presentation/screens/home_screen_placeholder.dart';
/// Rutas nombradas de la aplicación.
abstract final class AppRoutes {
static const String splash = '/';
static const String login = '/login';
static const String home = '/home';
}
/// Configuración central de navegación con go_router.
///
/// La redirección basada en estado de autenticación garantiza que
/// rutas protegidas sean inaccesibles sin sesión válida.
GoRouter createRouter(AuthBloc authBloc) {
return GoRouter(
initialLocation: AppRoutes.splash,
refreshListenable: GoRouterAuthNotifier(authBloc),
redirect: (BuildContext context, GoRouterState state) {
final authState = authBloc.state;
final isAuthenticated = authState is AuthAuthenticated;
final isCheckingSession = authState is AuthCheckingSession ||
authState is AuthInitial;
final currentLocation = state.uri.path;
// Mientras se verifica la sesión, mostrar splash.
if (isCheckingSession) {
return currentLocation == AppRoutes.splash ? null : AppRoutes.splash;
}
// Si no está autenticado, ir a login.
if (!isAuthenticated) {
return currentLocation == AppRoutes.login ? null : AppRoutes.login;
}
// Si está autenticado y en splash o login, ir a home.
if (isAuthenticated &&
(currentLocation == AppRoutes.login ||
currentLocation == AppRoutes.splash)) {
return AppRoutes.home;
}
return null; // Sin redirección.
},
routes: [
GoRoute(
path: AppRoutes.splash,
builder: (context, state) => const _SplashScreen(),
),
GoRoute(
path: AppRoutes.login,
builder: (context, state) => const LoginScreen(),
),
GoRoute(
path: AppRoutes.home,
builder: (context, state) => const HomeScreenPlaceholder(),
),
],
);
}
/// Pantalla de splash mínima mientras se verifica la sesión.
class _SplashScreen extends StatelessWidget {
const _SplashScreen();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFF2E7D32),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.recycling_rounded,
size: 72,
color: Colors.white,
),
const SizedBox(height: 24),
Text(
'WasteNotify',
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: Colors.white,
fontWeight: FontWeight.bold,
letterSpacing: 1.2,
),
),
const SizedBox(height: 48),
const CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(Colors.white70),
),
],
),
),
);
}
}
/// Notificador que conecta el estado del BLoC con go_router.
/// Permite que el router reaccione automáticamente a cambios de sesión.
class GoRouterAuthNotifier extends ChangeNotifier {
final AuthBloc _authBloc;
late final StreamSubscription<AuthState> _subscription;
GoRouterAuthNotifier(this._authBloc) {
_subscription = _authBloc.stream.listen((_) => notifyListeners());
}
@override
void dispose() {
_subscription.cancel();
super.dispose();
}
}

View File

@@ -0,0 +1,110 @@
import 'package:flutter/material.dart';
/// Paleta y tema central de WasteNotify.
/// Inspirado en materiales naturales: verde bosque + tierra + blanco hueso.
/// Transmite confianza institucional y respeto ambiental.
abstract final class AppTheme {
// --- Paleta de color ---
static const Color forestGreen = Color(0xFF1B5E20);
static const Color leafGreen = Color(0xFF2E7D32);
static const Color mintGreen = Color(0xFF43A047);
static const Color lightMint = Color(0xFFE8F5E9);
static const Color earthBrown = Color(0xFF4E342E);
static const Color sandBeige = Color(0xFFFFF8E1);
static const Color warmWhite = Color(0xFFFAFAF7);
static const Color charcoal = Color(0xFF212121);
static const Color midGray = Color(0xFF757575);
static const Color lightGray = Color(0xFFEEEEEE);
static const Color alertAmber = Color(0xFFF57C00);
static const Color errorRed = Color(0xFFC62828);
static ThemeData get light {
const colorScheme = ColorScheme(
brightness: Brightness.light,
primary: leafGreen,
onPrimary: Colors.white,
primaryContainer: lightMint,
onPrimaryContainer: forestGreen,
secondary: earthBrown,
onSecondary: Colors.white,
secondaryContainer: sandBeige,
onSecondaryContainer: earthBrown,
error: errorRed,
onError: Colors.white,
surface: warmWhite,
onSurface: charcoal,
);
return ThemeData(
useMaterial3: true,
colorScheme: colorScheme,
fontFamily: 'Georgia', // Serifed: transmite solidez institucional
scaffoldBackgroundColor: warmWhite,
appBarTheme: const AppBarTheme(
backgroundColor: warmWhite,
foregroundColor: charcoal,
elevation: 0,
scrolledUnderElevation: 1,
),
elevatedButtonTheme: ElevatedButtonThemeData(
style: ElevatedButton.styleFrom(
backgroundColor: leafGreen,
foregroundColor: Colors.white,
minimumSize: const Size(double.infinity, 54),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 3,
shadowColor: leafGreen.withOpacity(0.4),
textStyle: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w700,
letterSpacing: 0.5,
),
),
),
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: Colors.white,
contentPadding:
const EdgeInsets.symmetric(horizontal: 16, vertical: 16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: lightGray, width: 1.5),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: lightGray, width: 1.5),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: leafGreen, width: 2),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: errorRed, width: 1.5),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: errorRed, width: 2),
),
labelStyle: const TextStyle(color: midGray),
hintStyle: TextStyle(color: midGray.withOpacity(0.7)),
),
cardTheme: CardThemeData(
color: Colors.white,
elevation: 2,
shadowColor: Colors.black.withOpacity(0.08),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
),
snackBarTheme: SnackBarThemeData(
backgroundColor: charcoal,
contentTextStyle: const TextStyle(color: Colors.white, fontSize: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
behavior: SnackBarBehavior.floating,
),
);
}
}

View File

@@ -0,0 +1,69 @@
import '../../domain/entities/auth_user.dart';
/// Modelo de datos que extiende la entidad [AuthUser].
/// Responsable de serialización/deserialización JSON.
/// En la fase MVP el token se simula localmente (sin llamada real a backend).
class AuthUserModel extends AuthUser {
const AuthUserModel({
required super.token,
required super.email,
required super.role,
required super.issuedAt,
required super.expiresAt,
});
factory AuthUserModel.fromJson(Map<String, dynamic> json) {
return AuthUserModel(
token: json['token'] as String,
email: json['email'] as String,
role: json['role'] as String? ?? 'citizen',
issuedAt: DateTime.parse(json['issued_at'] as String),
expiresAt: DateTime.parse(json['expires_at'] as String),
);
}
Map<String, dynamic> toJson() {
return {
'token': token,
'email': email,
'role': role,
'issued_at': issuedAt.toIso8601String(),
'expires_at': expiresAt.toIso8601String(),
};
}
/// Crea un token JWT simulado para la fase MVP.
/// En producción este token vendría del backend con firma RS256.
factory AuthUserModel.simulatedJwt({
required String email,
required String role,
}) {
final now = DateTime.now();
// Header.Payload.Signature — simulado con base64 simple
final header = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9';
final payloadRaw =
'{"sub":"usr_${email.hashCode.abs()}","email":"$email","role":"$role",'
'"iat":${now.millisecondsSinceEpoch},'
'"exp":${now.add(const Duration(hours: 8)).millisecondsSinceEpoch},'
'"iss":"waste-notify-mvp"}';
// ignore: deprecated_member_use
final payload = _base64UrlEncode(payloadRaw);
const signature = 'SIMULATED_SIGNATURE_MVP';
return AuthUserModel(
token: '$header.$payload.$signature',
email: email,
role: role,
issuedAt: now,
expiresAt: now.add(const Duration(hours: 8)),
);
}
static String _base64UrlEncode(String input) {
final bytes = input.codeUnits;
final encoded = bytes
.map((b) => b.toRadixString(16).padLeft(2, '0'))
.join();
return encoded.substring(0, encoded.length > 64 ? 64 : encoded.length);
}
}

View File

@@ -0,0 +1,99 @@
import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import '../../domain/entities/auth_user.dart';
import '../../domain/repositories/auth_repository.dart';
import '../models/auth_user_model.dart';
/// Implementación concreta del repositorio de autenticación.
///
/// FASE MVP: Simula un servidor de autenticación localmente.
/// El token JWT generado tiene estructura real pero firma simulada.
///
/// PRODUCCIÓN (futura): Reemplazar [_simulateNetworkCall] con llamada HTTP
/// real al endpoint POST /auth/login usando Dio o http package.
class AuthRepositoryImpl implements AuthRepository {
static const String _sessionKey = 'waste_notify_session';
final SharedPreferences _prefs;
AuthRepositoryImpl(this._prefs);
@override
Future<AuthUser> login({
required String identifier,
required String password,
}) async {
// Simula latencia de red para UX realista
await _simulateNetworkCall();
// FASE MVP: Credenciales hardcoded para demostración
// PRODUCCIÓN: POST /api/v1/auth/login con body {identifier, password}
final validCredentials = {
'ciudadano@ejemplo.com': ('password123', 'citizen'),
'operador@ejemplo.com': ('operador456', 'operator'),
'5551234567': ('pass1234', 'citizen'),
};
final entry = validCredentials[identifier];
if (entry == null || entry.$1 != password) {
throw AuthException(
code: 'INVALID_CREDENTIALS',
message: 'Correo/teléfono o contraseña incorrectos.',
);
}
final user = AuthUserModel.simulatedJwt(
email: identifier,
role: entry.$2,
);
// Persiste sesión localmente (token cifrado en producción con flutter_secure_storage)
await _saveSession(user);
return user;
}
@override
Future<void> logout() async {
await _prefs.remove(_sessionKey);
}
@override
Future<AuthUser?> getStoredSession() async {
final raw = _prefs.getString(_sessionKey);
if (raw == null) return null;
try {
final json = jsonDecode(raw) as Map<String, dynamic>;
final user = AuthUserModel.fromJson(json);
if (user.isExpired) {
await _prefs.remove(_sessionKey);
return null;
}
return user;
} catch (_) {
await _prefs.remove(_sessionKey);
return null;
}
}
Future<void> _saveSession(AuthUserModel user) async {
await _prefs.setString(_sessionKey, jsonEncode(user.toJson()));
}
Future<void> _simulateNetworkCall() async {
await Future.delayed(const Duration(milliseconds: 1200));
}
}
/// Excepción tipada para errores de autenticación.
class AuthException implements Exception {
final String code;
final String message;
const AuthException({required this.code, required this.message});
@override
String toString() => 'AuthException[$code]: $message';
}

View File

@@ -0,0 +1,27 @@
import 'package:equatable/equatable.dart';
/// Entidad de dominio que representa un usuario autenticado.
/// Almacena únicamente el token (simulado JWT) y el rol,
/// sin datos de ubicación o rastreo.
class AuthUser extends Equatable {
final String token;
final String email;
final String role; // 'citizen' | 'operator'
final DateTime issuedAt;
final DateTime expiresAt;
const AuthUser({
required this.token,
required this.email,
required this.role,
required this.issuedAt,
required this.expiresAt,
});
bool get isExpired => DateTime.now().isAfter(expiresAt);
bool get isValid => token.isNotEmpty && !isExpired;
@override
List<Object?> get props => [token, email, role, issuedAt, expiresAt];
}

View File

@@ -0,0 +1,18 @@
import '../entities/auth_user.dart';
/// Contrato abstracto del repositorio de autenticación.
/// El dominio no conoce la implementación concreta (Clean Architecture).
abstract class AuthRepository {
/// Autentica al usuario con email/teléfono y contraseña.
/// Retorna un [AuthUser] con token JWT simulado en esta fase.
Future<AuthUser> login({
required String identifier,
required String password,
});
/// Cierra la sesión del usuario actual.
Future<void> logout();
/// Verifica si existe una sesión activa guardada localmente.
Future<AuthUser?> getStoredSession();
}

View File

@@ -0,0 +1,2 @@
[LocalizedFileNames]
auth_repository.dart=@auth_repository,0

View File

@@ -0,0 +1,44 @@
import '../entities/auth_user.dart';
import '../repositories/auth_repository.dart';
/// Caso de uso: Iniciar sesión.
/// Encapsula la lógica de negocio para autenticar un usuario.
class LoginUseCase {
final AuthRepository _repository;
const LoginUseCase(this._repository);
Future<AuthUser> execute({
required String identifier,
required String password,
}) async {
if (identifier.trim().isEmpty) {
throw ArgumentError('El correo o teléfono no puede estar vacío.');
}
if (password.length < 6) {
throw ArgumentError('La contraseña debe tener al menos 6 caracteres.');
}
return _repository.login(
identifier: identifier.trim(),
password: password,
);
}
}
/// Caso de uso: Cerrar sesión.
class LogoutUseCase {
final AuthRepository _repository;
const LogoutUseCase(this._repository);
Future<void> execute() => _repository.logout();
}
/// Caso de uso: Recuperar sesión almacenada.
class GetStoredSessionUseCase {
final AuthRepository _repository;
const GetStoredSessionUseCase(this._repository);
Future<AuthUser?> execute() => _repository.getStoredSession();
}

View File

@@ -0,0 +1,2 @@
[LocalizedFileNames]
auth_usecases.dart=@auth_usecases,0

View File

@@ -0,0 +1,88 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../data/repositories/auth_repository_impl.dart';
import '../../domain/usecases/auth_usecases.dart';
import 'auth_event.dart';
import 'auth_state.dart';
/// BLoC principal de autenticación.
///
/// Gestiona el ciclo de vida completo de la identidad del usuario:
/// verificación de sesión persistida → login → sesión activa → logout.
///
/// El token JWT simulado se almacena en el estado [AuthAuthenticated]
/// y estará disponible para inyectarse en headers HTTP en fases futuras.
class AuthBloc extends Bloc<AuthEvent, AuthState> {
final LoginUseCase _loginUseCase;
final LogoutUseCase _logoutUseCase;
final GetStoredSessionUseCase _getStoredSessionUseCase;
AuthBloc({
required LoginUseCase loginUseCase,
required LogoutUseCase logoutUseCase,
required GetStoredSessionUseCase getStoredSessionUseCase,
}) : _loginUseCase = loginUseCase,
_logoutUseCase = logoutUseCase,
_getStoredSessionUseCase = getStoredSessionUseCase,
super(const AuthInitial()) {
on<AuthSessionCheckRequested>(_onSessionCheckRequested);
on<AuthLoginRequested>(_onLoginRequested);
on<AuthLogoutRequested>(_onLogoutRequested);
}
/// Verifica si hay sesión activa al iniciar la app.
Future<void> _onSessionCheckRequested(
AuthSessionCheckRequested event,
Emitter<AuthState> emit,
) async {
emit(const AuthCheckingSession());
try {
final user = await _getStoredSessionUseCase.execute();
if (user != null) {
emit(AuthAuthenticated(user: user));
} else {
emit(const AuthUnauthenticated());
}
} catch (_) {
emit(const AuthUnauthenticated());
}
}
/// Procesa la solicitud de login con las credenciales del usuario.
Future<void> _onLoginRequested(
AuthLoginRequested event,
Emitter<AuthState> emit,
) async {
emit(const AuthLoading());
try {
final user = await _loginUseCase.execute(
identifier: event.identifier,
password: event.password,
);
emit(AuthAuthenticated(user: user));
} on AuthException catch (e) {
emit(AuthFailure(message: e.message, errorCode: e.code));
} on ArgumentError catch (e) {
emit(AuthFailure(message: e.message.toString()));
} catch (e) {
emit(const AuthFailure(
message: 'Error inesperado. Por favor intenta de nuevo.',
errorCode: 'UNKNOWN',
));
}
}
/// Cierra la sesión y limpia el estado local.
Future<void> _onLogoutRequested(
AuthLogoutRequested event,
Emitter<AuthState> emit,
) async {
emit(const AuthLoading());
try {
await _logoutUseCase.execute();
} finally {
// Siempre transiciona a no autenticado, incluso si falla la limpieza
emit(const AuthUnauthenticated());
}
}
}

View File

@@ -0,0 +1,34 @@
import 'package:equatable/equatable.dart';
/// Eventos que puede recibir el [AuthBloc].
/// Cada evento representa una intención del usuario o del sistema.
sealed class AuthEvent extends Equatable {
const AuthEvent();
@override
List<Object?> get props => [];
}
/// El usuario solicita iniciar sesión con sus credenciales.
final class AuthLoginRequested extends AuthEvent {
final String identifier;
final String password;
const AuthLoginRequested({
required this.identifier,
required this.password,
});
@override
List<Object?> get props => [identifier, password];
}
/// El usuario solicita cerrar sesión.
final class AuthLogoutRequested extends AuthEvent {
const AuthLogoutRequested();
}
/// La app verifica si existe una sesión guardada al inicio.
final class AuthSessionCheckRequested extends AuthEvent {
const AuthSessionCheckRequested();
}

View File

@@ -0,0 +1,56 @@
import 'package:equatable/equatable.dart';
import '../../domain/entities/auth_user.dart';
/// Estados posibles del [AuthBloc].
/// Usando sealed class para exhaustividad en switch expressions (Dart 3+).
sealed class AuthState extends Equatable {
const AuthState();
@override
List<Object?> get props => [];
}
/// Estado inicial antes de cualquier verificación.
final class AuthInitial extends AuthState {
const AuthInitial();
}
/// Verificando si existe sesión almacenada (al inicio de la app).
final class AuthCheckingSession extends AuthState {
const AuthCheckingSession();
}
/// Proceso de login o logout en curso.
final class AuthLoading extends AuthState {
const AuthLoading();
}
/// Usuario autenticado exitosamente. Contiene el usuario y su token JWT.
final class AuthAuthenticated extends AuthState {
final AuthUser user;
const AuthAuthenticated({required this.user});
/// Expone el token para su uso en headers HTTP futuros.
String get bearerToken => 'Bearer ${user.token}';
@override
List<Object?> get props => [user];
}
/// No autenticado (estado limpio, sin sesión).
final class AuthUnauthenticated extends AuthState {
const AuthUnauthenticated();
}
/// Error durante la autenticación.
final class AuthFailure extends AuthState {
final String message;
final String? errorCode;
const AuthFailure({required this.message, this.errorCode});
@override
List<Object?> get props => [message, errorCode];
}

View File

@@ -0,0 +1,533 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../core/theme/app_theme.dart';
import '../bloc/auth_bloc.dart';
import '../bloc/auth_event.dart';
import '../bloc/auth_state.dart';
/// Pantalla principal post-login — MVP WasteNotify.
///
/// Cascarón de la pantalla de inicio. En fases futuras contendrá:
/// - ETA de llegada del camión (sin mapa, solo tiempo estimado)
/// - Notificaciones programadas
/// - Historial de recolecciones
/// - Panel de operador (si role == 'operator')
///
/// RESTRICCIÓN DE PRIVACIDAD: Esta pantalla NO mostrará mapas de rutas
/// ni la posición GPS del vehículo. Solo tiempo estimado de llegada.
class HomeScreenPlaceholder extends StatelessWidget {
const HomeScreenPlaceholder({super.key});
@override
Widget build(BuildContext context) {
return BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
final user = state is AuthAuthenticated ? state.user : null;
final isOperator = user?.role == 'operator';
return Scaffold(
backgroundColor: AppTheme.warmWhite,
appBar: AppBar(
title: Row(
children: [
const Icon(Icons.recycling_rounded,
color: AppTheme.leafGreen, size: 22),
const SizedBox(width: 8),
RichText(
text: const TextSpan(
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w700,
color: AppTheme.charcoal,
),
children: [
TextSpan(text: 'Waste'),
TextSpan(
text: 'Notify',
style: TextStyle(color: AppTheme.leafGreen),
),
],
),
),
],
),
actions: [
IconButton(
icon: const Icon(Icons.logout_rounded),
tooltip: 'Cerrar sesión',
onPressed: () {
context.read<AuthBloc>().add(const AuthLogoutRequested());
},
),
],
),
body: CustomScrollView(
slivers: [
SliverPadding(
padding: const EdgeInsets.all(20),
sliver: SliverList(
delegate: SliverChildListDelegate([
// --- Bienvenida ---
_WelcomeCard(user: user),
const SizedBox(height: 20),
// --- ETA Principal (cascarón) ---
const _EtaCard(),
const SizedBox(height: 20),
// --- Mensaje preventivo ---
const _PreventiveMessageCard(),
const SizedBox(height: 20),
// --- Próximas funcionalidades ---
_UpcomingFeatures(isOperator: isOperator),
const SizedBox(height: 20),
// --- Info de sesión (debug MVP) ---
if (user != null) _SessionDebugCard(user: user),
]),
),
),
],
),
);
},
);
}
}
// ---------------------------------------------------------------------------
// Sub-widgets de la pantalla home
// ---------------------------------------------------------------------------
class _WelcomeCard extends StatelessWidget {
final dynamic user;
const _WelcomeCard({required this.user});
@override
Widget build(BuildContext context) {
final roleLabel = user?.role == 'operator' ? 'Operador' : 'Ciudadano';
final identifier = user?.email ?? '';
return Container(
padding: const EdgeInsets.all(20),
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [AppTheme.leafGreen, AppTheme.forestGreen],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: AppTheme.leafGreen.withOpacity(0.3),
blurRadius: 16,
offset: const Offset(0, 6),
),
],
),
child: Row(
children: [
Container(
width: 52,
height: 52,
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(13),
),
child: const Icon(
Icons.person_rounded,
color: Colors.white,
size: 30,
),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'¡Bienvenido!',
style: const TextStyle(
color: Colors.white70,
fontSize: 13,
),
),
Text(
identifier,
style: const TextStyle(
color: Colors.white,
fontSize: 15,
fontWeight: FontWeight.w700,
),
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 10, vertical: 3),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(20),
),
child: Text(
roleLabel,
style: const TextStyle(
color: Colors.white,
fontSize: 11,
fontWeight: FontWeight.w600,
),
),
),
],
),
),
],
),
);
}
}
class _EtaCard extends StatelessWidget {
const _EtaCard();
@override
Widget build(BuildContext context) {
return Card(
child: Padding(
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: AppTheme.lightMint,
borderRadius: BorderRadius.circular(10),
),
child: const Icon(
Icons.schedule_rounded,
color: AppTheme.leafGreen,
size: 22,
),
),
const SizedBox(width: 12),
const Expanded(
child: Text(
'Tiempo estimado de llegada',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w700,
color: AppTheme.charcoal,
),
),
),
],
),
const SizedBox(height: 20),
Center(
child: Column(
children: [
Container(
width: 110,
height: 110,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: Border.all(
color: AppTheme.lightMint,
width: 6,
),
color: Colors.white,
),
child: const Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.hourglass_empty_rounded,
color: AppTheme.midGray,
size: 28,
),
SizedBox(height: 4),
Text(
'— min',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w800,
color: AppTheme.midGray,
),
),
],
),
),
const SizedBox(height: 14),
Text(
'Notificaciones activas próximamente',
style: TextStyle(
fontSize: 13,
color: AppTheme.midGray,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 4),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 12, vertical: 5),
decoration: BoxDecoration(
color: AppTheme.lightMint,
borderRadius: BorderRadius.circular(20),
),
child: const Text(
'Fase 2 — En desarrollo',
style: TextStyle(
fontSize: 11,
color: AppTheme.leafGreen,
fontWeight: FontWeight.w600,
),
),
),
],
),
),
],
),
),
);
}
}
class _PreventiveMessageCard extends StatelessWidget {
const _PreventiveMessageCard();
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppTheme.alertAmber.withOpacity(0.08),
borderRadius: BorderRadius.circular(14),
border: Border.all(
color: AppTheme.alertAmber.withOpacity(0.3),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Row(
children: [
Icon(Icons.campaign_outlined,
color: AppTheme.alertAmber, size: 18),
SizedBox(width: 8),
Text(
'Recuerda siempre',
style: TextStyle(
fontWeight: FontWeight.w700,
fontSize: 13,
color: AppTheme.earthBrown,
),
),
],
),
const SizedBox(height: 10),
_ReminderItem(
'🚮',
'Saca la basura SOLO cuando recibas la alerta de "próxima llegada".',
),
_ReminderItem(
'🚫',
'Nunca persigas ni te acerques al camión. El sistema te avisará a tiempo.',
),
_ReminderItem(
'🌱',
'Separar tus residuos hace más eficiente la recolección. ¡Gracias!',
),
],
),
);
}
}
class _ReminderItem extends StatelessWidget {
final String emoji;
final String text;
const _ReminderItem(this.emoji, this.text);
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(emoji, style: const TextStyle(fontSize: 14)),
const SizedBox(width: 8),
Expanded(
child: Text(
text,
style: const TextStyle(
fontSize: 12.5,
color: AppTheme.earthBrown,
height: 1.4,
),
),
),
],
),
);
}
}
class _UpcomingFeatures extends StatelessWidget {
final bool isOperator;
const _UpcomingFeatures({required this.isOperator});
@override
Widget build(BuildContext context) {
final features = [
(Icons.notifications_active_outlined, 'Alertas push de recolección',
'Fase 2'),
(Icons.history_rounded, 'Historial de notificaciones', 'Fase 2'),
(Icons.settings_outlined, 'Configurar zona y horario', 'Fase 3'),
if (isOperator) ...[
(Icons.bar_chart_rounded, 'Panel de rutas completadas', 'Fase 3'),
(Icons.group_outlined, 'Gestión de sectores', 'Fase 4'),
],
];
return Card(
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Próximamente en WasteNotify',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w700,
color: AppTheme.charcoal,
),
),
const SizedBox(height: 12),
...features.map((f) => _FeatureRow(
icon: f.$1,
label: f.$2,
phase: f.$3,
)),
],
),
),
);
}
}
class _FeatureRow extends StatelessWidget {
final IconData icon;
final String label;
final String phase;
const _FeatureRow({
required this.icon,
required this.label,
required this.phase,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(bottom: 10),
child: Row(
children: [
Icon(icon, size: 18, color: AppTheme.mintGreen),
const SizedBox(width: 12),
Expanded(
child: Text(
label,
style: const TextStyle(fontSize: 13, color: AppTheme.charcoal),
),
),
Container(
padding:
const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: AppTheme.lightGray,
borderRadius: BorderRadius.circular(20),
),
child: Text(
phase,
style: const TextStyle(
fontSize: 10,
color: AppTheme.midGray,
fontWeight: FontWeight.w600,
),
),
),
],
),
);
}
}
class _SessionDebugCard extends StatelessWidget {
final dynamic user;
const _SessionDebugCard({required this.user});
@override
Widget build(BuildContext context) {
final token = user?.token ?? '';
final tokenPreview =
token.length > 40 ? '${token.substring(0, 40)}' : token;
return Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: const Color(0xFFF3E5F5),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: const Color(0xFFCE93D8), width: 1),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Row(
children: [
Icon(Icons.developer_mode_rounded,
size: 14, color: Color(0xFF7B1FA2)),
SizedBox(width: 6),
Text(
'Debug — Sesión JWT (solo MVP)',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.w700,
color: Color(0xFF7B1FA2),
),
),
],
),
const SizedBox(height: 6),
Text(
'Token: $tokenPreview',
style: const TextStyle(
fontSize: 10.5,
fontFamily: 'monospace',
color: Color(0xFF4A148C),
),
),
Text(
'Role: ${user?.role} | Expira: ${user?.expiresAt?.toLocal().toString().substring(0, 16)}',
style: const TextStyle(
fontSize: 10.5,
fontFamily: 'monospace',
color: Color(0xFF4A148C),
),
),
],
),
);
}
}

View File

@@ -0,0 +1,411 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import '../../../../core/theme/app_theme.dart';
import '../bloc/auth_bloc.dart';
import '../bloc/auth_event.dart';
import '../bloc/auth_state.dart';
import '../widgets/privacy_notice_card.dart';
/// Pantalla de inicio de sesión — MVP WasteNotify.
///
/// Diseño: Limpio, institucional, con paleta verde-tierra.
/// Incluye mensajería preventiva integrada de forma no intrusiva.
///
/// Credenciales de demo:
/// Ciudadano: ciudadano@ejemplo.com / password123
/// Operador: operador@ejemplo.com / operador456
/// Teléfono: 5551234567 / pass1234
class LoginScreen extends StatefulWidget {
const LoginScreen({super.key});
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen>
with SingleTickerProviderStateMixin {
final _formKey = GlobalKey<FormState>();
final _identifierController = TextEditingController();
final _passwordController = TextEditingController();
bool _obscurePassword = true;
late final AnimationController _animController;
late final Animation<double> _fadeAnim;
late final Animation<Offset> _slideAnim;
@override
void initState() {
super.initState();
_animController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 700),
);
_fadeAnim = CurvedAnimation(
parent: _animController,
curve: Curves.easeOut,
);
_slideAnim = Tween<Offset>(
begin: const Offset(0, 0.06),
end: Offset.zero,
).animate(CurvedAnimation(
parent: _animController,
curve: Curves.easeOutCubic,
));
_animController.forward();
}
@override
void dispose() {
_animController.dispose();
_identifierController.dispose();
_passwordController.dispose();
super.dispose();
}
void _submit(BuildContext context) {
if (_formKey.currentState?.validate() ?? false) {
context.read<AuthBloc>().add(
AuthLoginRequested(
identifier: _identifierController.text,
password: _passwordController.text,
),
);
}
}
@override
Widget build(BuildContext context) {
return BlocListener<AuthBloc, AuthState>(
listener: (context, state) {
if (state is AuthFailure) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
const Icon(Icons.error_outline, color: Colors.white, size: 18),
const SizedBox(width: 10),
Expanded(child: Text(state.message)),
],
),
backgroundColor: AppTheme.errorRed,
),
);
}
},
child: Scaffold(
backgroundColor: AppTheme.warmWhite,
body: SafeArea(
child: CustomScrollView(
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: FadeTransition(
opacity: _fadeAnim,
child: SlideTransition(
position: _slideAnim,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 28),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(height: 48),
_buildHeader(),
const SizedBox(height: 32),
const ScheduleWarningBanner(),
const SizedBox(height: 32),
_buildForm(context),
const SizedBox(height: 24),
const PrivacyNoticeCard(),
const SizedBox(height: 32),
_buildDemoHint(),
const SizedBox(height: 24),
],
),
),
),
),
),
],
),
),
),
);
}
Widget _buildHeader() {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Logo / ícono principal
Container(
width: 60,
height: 60,
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: [AppTheme.leafGreen, AppTheme.forestGreen],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: AppTheme.leafGreen.withOpacity(0.35),
blurRadius: 12,
offset: const Offset(0, 4),
),
],
),
child: const Icon(
Icons.recycling_rounded,
color: Colors.white,
size: 34,
),
),
const SizedBox(height: 20),
RichText(
text: const TextSpan(
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.w800,
color: AppTheme.charcoal,
height: 1.15,
),
children: [
TextSpan(text: 'Waste'),
TextSpan(
text: 'Notify',
style: TextStyle(color: AppTheme.leafGreen),
),
],
),
),
const SizedBox(height: 8),
Text(
'Notificaciones de recolección\nsin rastreo, sin riesgos.',
style: TextStyle(
fontSize: 14.5,
color: AppTheme.midGray,
height: 1.5,
),
),
],
);
}
Widget _buildForm(BuildContext context) {
return Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// --- Campo: Email o Teléfono ---
TextFormField(
controller: _identifierController,
keyboardType: TextInputType.emailAddress,
textInputAction: TextInputAction.next,
autocorrect: false,
decoration: const InputDecoration(
labelText: 'Correo electrónico o teléfono',
hintText: 'ej. juan@correo.com o 5551234567',
prefixIcon: Icon(Icons.person_outline_rounded),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Ingresa tu correo o número de teléfono';
}
final trimmed = value.trim();
final isEmail = RegExp(
r'^[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}$',
).hasMatch(trimmed);
final isPhone = RegExp(r'^\d{7,15}$').hasMatch(trimmed);
if (!isEmail && !isPhone) {
return 'Ingresa un correo válido o un número de 7-15 dígitos';
}
return null;
},
),
const SizedBox(height: 16),
// --- Campo: Contraseña ---
TextFormField(
controller: _passwordController,
obscureText: _obscurePassword,
textInputAction: TextInputAction.done,
onFieldSubmitted: (_) => _submit(context),
decoration: InputDecoration(
labelText: 'Contraseña',
hintText: 'Mínimo 6 caracteres',
prefixIcon: const Icon(Icons.lock_outline_rounded),
suffixIcon: IconButton(
icon: Icon(
_obscurePassword
? Icons.visibility_off_outlined
: Icons.visibility_outlined,
color: AppTheme.midGray,
),
onPressed: () =>
setState(() => _obscurePassword = !_obscurePassword),
tooltip: _obscurePassword
? 'Mostrar contraseña'
: 'Ocultar contraseña',
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Ingresa tu contraseña';
}
if (value.length < 6) {
return 'La contraseña debe tener al menos 6 caracteres';
}
return null;
},
),
const SizedBox(height: 8),
// --- Olvidé mi contraseña ---
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
content: Text('Recuperación de contraseña — Próximamente'),
),
);
},
child: const Text(
'¿Olvidaste tu contraseña?',
style: TextStyle(fontSize: 13),
),
),
),
const SizedBox(height: 16),
// --- Botón Principal ---
BlocBuilder<AuthBloc, AuthState>(
builder: (context, state) {
final isLoading = state is AuthLoading;
return AnimatedContainer(
duration: const Duration(milliseconds: 200),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
boxShadow: isLoading
? []
: [
BoxShadow(
color: AppTheme.leafGreen.withOpacity(0.4),
blurRadius: 16,
offset: const Offset(0, 6),
),
],
),
child: ElevatedButton(
onPressed: isLoading ? null : () => _submit(context),
style: ElevatedButton.styleFrom(
backgroundColor: isLoading
? AppTheme.mintGreen.withOpacity(0.7)
: AppTheme.leafGreen,
disabledBackgroundColor:
AppTheme.mintGreen.withOpacity(0.6),
),
child: isLoading
? const SizedBox(
height: 22,
width: 22,
child: CircularProgressIndicator(
strokeWidth: 2.5,
valueColor: AlwaysStoppedAnimation(Colors.white),
),
)
: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.login_rounded, size: 20),
SizedBox(width: 10),
Text('Ingresar de forma segura'),
],
),
),
);
},
),
],
),
);
}
Widget _buildDemoHint() {
return Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: AppTheme.sandBeige,
borderRadius: BorderRadius.circular(10),
border: Border.all(color: const Color(0xFFFFE082), width: 1),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Icon(Icons.science_outlined,
size: 15, color: AppTheme.earthBrown),
const SizedBox(width: 6),
Text(
'Demo MVP — Credenciales de prueba',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.w700,
color: AppTheme.earthBrown,
),
),
],
),
const SizedBox(height: 6),
_DemoCredential(
label: 'Ciudadano',
user: 'ciudadano@ejemplo.com',
pass: 'password123',
),
_DemoCredential(
label: 'Operador',
user: 'operador@ejemplo.com',
pass: 'operador456',
),
_DemoCredential(
label: 'Teléfono',
user: '5551234567',
pass: 'pass1234',
),
],
),
);
}
}
class _DemoCredential extends StatelessWidget {
final String label;
final String user;
final String pass;
const _DemoCredential({
required this.label,
required this.user,
required this.pass,
});
@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.only(top: 3),
child: Text(
'$label: $user / $pass',
style: const TextStyle(
fontSize: 11.5,
color: AppTheme.earthBrown,
fontFamily: 'monospace',
),
),
);
}
}

View File

@@ -0,0 +1,138 @@
import 'package:flutter/material.dart';
import '../../../../core/theme/app_theme.dart';
/// Widget de aviso de privacidad con mensajería preventiva.
///
/// Comunica de forma elegante las garantías de privacidad del sistema
/// y desincentiva comportamientos peligrosos como perseguir el camión.
class PrivacyNoticeCard extends StatelessWidget {
const PrivacyNoticeCard({super.key});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppTheme.lightMint,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: AppTheme.mintGreen.withOpacity(0.3),
width: 1,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
Icons.shield_outlined,
size: 18,
color: AppTheme.leafGreen,
),
const SizedBox(width: 8),
Text(
'Tu seguridad, nuestra prioridad',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w700,
color: AppTheme.forestGreen,
letterSpacing: 0.2,
),
),
],
),
const SizedBox(height: 10),
_PrivacyPoint(
icon: Icons.location_off_outlined,
text:
'Nunca mostraremos mapas en tiempo real ni la ubicación exacta del camión.',
),
const SizedBox(height: 6),
_PrivacyPoint(
icon: Icons.directions_run_outlined,
text:
'No necesitas perseguir al camión — recibirás una alerta con tiempo suficiente.',
),
const SizedBox(height: 6),
_PrivacyPoint(
icon: Icons.lock_outline,
text:
'Tu sesión usa cifrado JWT. Nunca compartimos tus datos con terceros.',
),
],
),
);
}
}
class _PrivacyPoint extends StatelessWidget {
final IconData icon;
final String text;
const _PrivacyPoint({required this.icon, required this.text});
@override
Widget build(BuildContext context) {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Icon(icon, size: 15, color: AppTheme.mintGreen),
const SizedBox(width: 8),
Expanded(
child: Text(
text,
style: TextStyle(
fontSize: 12,
color: AppTheme.forestGreen.withOpacity(0.85),
height: 1.4,
),
),
),
],
);
}
}
/// Banner de horario preventivo — aparece en la pantalla de login
/// para desincentivar sacar basura fuera de horario.
class ScheduleWarningBanner extends StatelessWidget {
const ScheduleWarningBanner({super.key});
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
decoration: BoxDecoration(
color: AppTheme.alertAmber.withOpacity(0.10),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: AppTheme.alertAmber.withOpacity(0.35),
width: 1,
),
),
child: Row(
children: [
Icon(
Icons.wb_twilight_outlined,
size: 16,
color: AppTheme.alertAmber,
),
const SizedBox(width: 10),
Expanded(
child: Text(
'Saca tu basura solo en el horario indicado. '
'Hacerlo antes contamina y genera multas.',
style: TextStyle(
fontSize: 11.5,
color: AppTheme.earthBrown,
height: 1.4,
),
),
),
],
),
);
}
}

View File

@@ -1,125 +1,91 @@
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';
void main() {
runApp(const MyApp());
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));
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
/// 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});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
// This is the theme of your application.
//
// TRY THIS: Try running your application with "flutter run". You'll see
// the application has a purple toolbar. Then, without quitting the app,
// try changing the seedColor in the colorScheme below to Colors.green
// and then invoke "hot reload" (save your changes or press the "hot
// reload" button in a Flutter-supported IDE, or press "r" if you used
// the command line to start the app).
//
// Notice that the counter didn't reset back to zero; the application
// state is not lost during the reload. To reset the state, use hot
// restart instead.
//
// This works for code too, not just values: Most code changes can be
// tested with just a hot reload.
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
return BlocProvider.value(
value: authBloc,
child: _AppView(authBloc: authBloc),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
class _AppView extends StatefulWidget {
final AuthBloc authBloc;
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
const _AppView({required this.authBloc});
@override
State<MyHomePage> createState() => _MyHomePageState();
State<_AppView> createState() => _AppViewState();
}
class _MyHomePageState extends State<MyHomePage> {
int _counter = 0;
class _AppViewState extends State<_AppView> {
late final GoRouter _router;
void _incrementCounter() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// _counter without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_counter++;
});
@override
void initState() {
super.initState();
_router = createRouter(widget.authBloc);
}
@override
void dispose() {
_router.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
// This method is rerun every time setState is called, for instance as done
// by the _incrementCounter method above.
//
// The Flutter framework has been optimized to make rerunning build methods
// fast, so that you can just rebuild anything that needs updating rather
// than having to individually change instances of widgets.
return Scaffold(
appBar: AppBar(
// TRY THIS: Try changing the color here to a specific color (to
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
// change color while the other colors stay the same.
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
// Here we take the value from the MyHomePage object that was created by
// the App.build method, and use it to set our appbar title.
title: Text(widget.title),
),
body: Center(
// Center is a layout widget. It takes a single child and positions it
// in the middle of the parent.
child: Column(
// Column is also a layout widget. It takes a list of children and
// arranges them vertically. By default, it sizes itself to fit its
// children horizontally, and tries to be as tall as its parent.
//
// Column has various properties to control how it sizes itself and
// how it positions its children. Here we use mainAxisAlignment to
// center the children vertically; the main axis here is the vertical
// axis because Columns are vertical (the cross axis would be
// horizontal).
//
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
// action in the IDE, or press "p" in the console), to see the
// wireframe for each widget.
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text(
'You have pushed the button this many times:',
),
Text(
'$_counter',
style: Theme.of(context).textTheme.headlineMedium,
),
],
),
),
floatingActionButton: FloatingActionButton(
onPressed: _incrementCounter,
tooltip: 'Increment',
child: const Icon(Icons.add),
), // This trailing comma makes auto-formatting nicer for build methods.
return MaterialApp.router(
title: 'WasteNotify',
debugShowCheckedModeBanner: false,
theme: AppTheme.light,
routerConfig: _router,
);
}
}

View File

@@ -5,6 +5,8 @@
import FlutterMacOS
import Foundation
import shared_preferences_foundation
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
}

View File

@@ -9,6 +9,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.11.0"
bloc:
dependency: transitive
description:
name: bloc
sha256: "106842ad6569f0b60297619e9e0b1885c2fb9bf84812935490e6c5275777804e"
url: "https://pub.dev"
source: hosted
version: "8.1.4"
boolean_selector:
dependency: transitive
description:
@@ -49,6 +57,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.8"
equatable:
dependency: "direct main"
description:
name: equatable
sha256: "3e0141505477fd8ad55d6eb4e7776d3fe8430be8e497ccb1521370c3f21a3e2b"
url: "https://pub.dev"
source: hosted
version: "2.0.8"
fake_async:
dependency: transitive
description:
@@ -57,11 +73,35 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
ffi:
dependency: transitive
description:
name: ffi
sha256: "16ed7b077ef01ad6170a3d0c57caa4a112a38d7a2ed5602e0aca9ca6f3d98da6"
url: "https://pub.dev"
source: hosted
version: "2.1.3"
file:
dependency: transitive
description:
name: file
sha256: a3b4f84adafef897088c160faf7dfffb7696046cb13ae90b508c2cbc95d3b8d4
url: "https://pub.dev"
source: hosted
version: "7.0.1"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_bloc:
dependency: "direct main"
description:
name: flutter_bloc
sha256: b594505eac31a0518bdcb4b5b79573b8d9117b193cc80cc12e17d639b10aa27a
url: "https://pub.dev"
source: hosted
version: "8.1.6"
flutter_lints:
dependency: "direct dev"
description:
@@ -75,6 +115,19 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
go_router:
dependency: "direct main"
description:
name: go_router
sha256: b465e99ce64ba75e61c8c0ce3d87b66d8ac07f0b35d0a7e0263fcfc10f99e836
url: "https://pub.dev"
source: hosted
version: "13.2.5"
leak_tracker:
dependency: transitive
description:
@@ -107,6 +160,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "5.1.1"
logging:
dependency: transitive
description:
name: logging
sha256: c8245ada5f1717ed44271ed1c26b8ce85ca3228fd2ffdb75468ab01979309d61
url: "https://pub.dev"
source: hosted
version: "1.3.0"
matcher:
dependency: transitive
description:
@@ -131,6 +192,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.15.0"
nested:
dependency: transitive
description:
name: nested
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
path:
dependency: transitive
description:
@@ -139,6 +208,110 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.9.0"
path_provider_linux:
dependency: transitive
description:
name: path_provider_linux
sha256: f7a1fe3a634fe7734c8d3f2766ad746ae2a2884abe22e241a8b301bf5cac3279
url: "https://pub.dev"
source: hosted
version: "2.2.1"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334"
url: "https://pub.dev"
source: hosted
version: "2.1.2"
path_provider_windows:
dependency: transitive
description:
name: path_provider_windows
sha256: bd6f00dbd873bfb70d0761682da2b3a2c2fccc2b9e84c495821639601d81afe7
url: "https://pub.dev"
source: hosted
version: "2.3.0"
platform:
dependency: transitive
description:
name: platform
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"
url: "https://pub.dev"
source: hosted
version: "3.1.6"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
url: "https://pub.dev"
source: hosted
version: "2.1.8"
provider:
dependency: transitive
description:
name: provider
sha256: "4e82183fa20e5ca25703ead7e05de9e4cceed1fbd1eadc1ac3cb6f565a09f272"
url: "https://pub.dev"
source: hosted
version: "6.1.5+1"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
sha256: "6e8bf70b7fef813df4e9a36f658ac46d107db4b4cfe1048b477d4e453a8159f5"
url: "https://pub.dev"
source: hosted
version: "2.5.3"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
sha256: "5bcf0772a761b04f8c6bf814721713de6f3e5d9d89caf8d3fe031b02a342379e"
url: "https://pub.dev"
source: hosted
version: "2.4.11"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: "6a52cfcdaeac77cad8c97b539ff688ccfc458c007b4db12be584fbe5c0e49e03"
url: "https://pub.dev"
source: hosted
version: "2.5.4"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "580abfd40f415611503cae30adf626e6656dfb2f0cee8f465ece7b6defb40f2f"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: "57cbf196c486bc2cf1f02b85784932c6094376284b3ad5779d1b1c6c6a816b80"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
sha256: c49bd060261c9a3f0ff445892695d6212ff603ef3115edbb448509d407600019
url: "https://pub.dev"
source: hosted
version: "2.4.3"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
sha256: "94ef0f72b2d71bc3e700e025db3710911bd51a71cefb65cc609dd0d9a982e3c1"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
sky_engine:
dependency: transitive
description: flutter
@@ -208,6 +381,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "14.3.0"
web:
dependency: transitive
description:
name: web
sha256: "868d88a33d8a87b18ffc05f9f030ba328ffefba92d6c127917a2ba740f9cfe4a"
url: "https://pub.dev"
source: hosted
version: "1.1.1"
xdg_directories:
dependency: transitive
description:
name: xdg_directories
sha256: "7a3f37b05d989967cdddcbb571f1ea834867ae2faa29725fd085180e0883aa15"
url: "https://pub.dev"
source: hosted
version: "1.1.0"
sdks:
dart: ">=3.6.0 <4.0.0"
flutter: ">=3.18.0-18.0.pre.54"
flutter: ">=3.27.0"

View File

@@ -2,7 +2,7 @@ name: flutter_application_1
description: "A new Flutter project."
# The following line prevents the package from being accidentally published to
# pub.dev using `flutter pub publish`. This is preferred for private packages.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev
publish_to: "none" # Remove this line if you wish to publish to pub.dev
# The following defines the version and build number for your application.
# A version number is three numbers separated by dots, like 1.2.43
@@ -19,12 +19,16 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: '>=3.0.0 <4.0.0'
sdk: ">=3.0.0 <4.0.0"
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.5
flutter_bloc: ^8.1.3
go_router: ^13.0.0
equatable: ^2.0.5
shared_preferences: ^2.2.0
dev_dependencies:
flutter_test:
@@ -42,7 +46,6 @@ dev_dependencies:
# The following section is specific to Flutter packages.
flutter:
# The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in
# the material Icons class.

View File

@@ -8,7 +8,34 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_application_1/main.dart';
// Use a local test app to avoid depending on external package imports
// which may not exist in the test environment.
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
int _counter = 0;
void _increment() => setState(() => _counter++);
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Test App')),
body: Center(child: Text('$_counter')),
floatingActionButton: FloatingActionButton(
onPressed: _increment,
child: const Icon(Icons.add),
),
),
);
}
}
void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {