feat:implementacion grafica 2.0
This commit is contained in:
88
lib/features/auth/presentation/bloc/auth_bloc.dart
Normal file
88
lib/features/auth/presentation/bloc/auth_bloc.dart
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
34
lib/features/auth/presentation/bloc/auth_event.dart
Normal file
34
lib/features/auth/presentation/bloc/auth_event.dart
Normal 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();
|
||||
}
|
||||
56
lib/features/auth/presentation/bloc/auth_state.dart
Normal file
56
lib/features/auth/presentation/bloc/auth_state.dart
Normal 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];
|
||||
}
|
||||
@@ -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),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
411
lib/features/auth/presentation/screens/login_screen.dart
Normal file
411
lib/features/auth/presentation/screens/login_screen.dart
Normal 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',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
138
lib/features/auth/presentation/widgets/privacy_notice_card.dart
Normal file
138
lib/features/auth/presentation/widgets/privacy_notice_card.dart
Normal 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,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user