213 lines
9.0 KiB
Dart
213 lines
9.0 KiB
Dart
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';
|
|
|
|
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: Form(
|
|
key: _formKey,
|
|
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.stretch,
|
|
children: [
|
|
const SizedBox(height: 48),
|
|
_buildHeader(),
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
'Sistema Municipal de Recolección Residencial\nCelaya, Guanajuato',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontSize: 12, color: Colors.grey.shade600, height: 1.3),
|
|
),
|
|
const SizedBox(height: 32),
|
|
// Asegúrate de que este widget esté definido en tu proyecto o cámbialo por un placeholder
|
|
// const ScheduleWarningBanner(),
|
|
const SizedBox(height: 32),
|
|
|
|
// --- CAMPO: EMAIL / IDENTIFICADOR ---
|
|
TextFormField(
|
|
controller: _identifierController,
|
|
keyboardType: TextInputType.emailAddress,
|
|
decoration: const InputDecoration(
|
|
labelText: 'Correo Electrónico o Teléfono',
|
|
prefixIcon: Icon(Icons.email_outlined),
|
|
border: OutlineInputBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(12))),
|
|
),
|
|
validator: (value) =>
|
|
(value == null || value.trim().isEmpty)
|
|
? 'Por favor, ingresa tus datos de acceso'
|
|
: null,
|
|
),
|
|
const SizedBox(height: 20),
|
|
|
|
// --- CAMPO: CONTRASEÑA ---
|
|
TextFormField(
|
|
controller: _passwordController,
|
|
obscureText: _obscurePassword,
|
|
decoration: InputDecoration(
|
|
labelText: 'Contraseña de Acceso',
|
|
prefixIcon: const Icon(Icons.lock_outline_rounded),
|
|
suffixIcon: IconButton(
|
|
icon: Icon(_obscurePassword ? Icons.visibility_off : Icons.visibility),
|
|
onPressed: () => setState(() => _obscurePassword = !_obscurePassword),
|
|
),
|
|
border: const OutlineInputBorder(
|
|
borderRadius: BorderRadius.all(Radius.circular(12))),
|
|
),
|
|
validator: (value) => (value == null || value.isEmpty)
|
|
? 'Por favor, introduce tu contraseña'
|
|
: null,
|
|
),
|
|
const SizedBox(height: 32),
|
|
|
|
// --- CONTENEDOR REACTIVO DE BOTONES ---
|
|
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.3),
|
|
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),
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
),
|
|
child: isLoading
|
|
? const CircularProgressIndicator(color: Colors.white)
|
|
: const Text('Iniciar Sesión', style: TextStyle(color: Colors.white)),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(height: 24),
|
|
const PrivacyNoticeCard(),
|
|
const SizedBox(height: 32),
|
|
_buildDemoHint(),
|
|
const SizedBox(height: 24),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Métodos auxiliares creados como placeholders para evitar errores de compilación
|
|
Widget _buildHeader() => const Center(child: Text("WasteNotify", style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold)));
|
|
Widget _buildDemoHint() => const Center(child: Text("Demo: ciudadano@ejemplo.com / password123", style: TextStyle(fontSize: 12)));
|
|
}
|