233 lines
6.2 KiB
Dart
233 lines
6.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'domicilios.dart';
|
|
|
|
class LoginScreen extends StatefulWidget {
|
|
const LoginScreen({super.key});
|
|
|
|
@override
|
|
State<LoginScreen> createState() => _LoginScreenState();
|
|
}
|
|
|
|
class _LoginScreenState extends State<LoginScreen> {
|
|
final _formKey = GlobalKey<FormState>();
|
|
|
|
final TextEditingController emailController =
|
|
TextEditingController();
|
|
|
|
final TextEditingController passwordController =
|
|
TextEditingController();
|
|
|
|
bool ocultarPassword = true;
|
|
|
|
void iniciarSesion() {
|
|
if (_formKey.currentState!.validate()) {
|
|
|
|
// Simulación de login exitoso
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(
|
|
content: Text('Inicio de sesión exitoso'),
|
|
backgroundColor: Colors.green,
|
|
),
|
|
);
|
|
|
|
// Navegar a la pantalla principal
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) =>
|
|
const GestionDomiciliosScreen(),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.white,
|
|
|
|
body: Center(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(25),
|
|
|
|
child: Form(
|
|
key: _formKey,
|
|
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
// Logo
|
|
CircleAvatar(
|
|
radius: 50,
|
|
backgroundColor: Colors.green.shade100,
|
|
|
|
child: Icon(
|
|
Icons.recycling,
|
|
size: 60,
|
|
color: Colors.green.shade700,
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
const Text(
|
|
'EcoRecolección',
|
|
style: TextStyle(
|
|
fontSize: 28,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
Text(
|
|
'Inicia sesión para continuar',
|
|
style: TextStyle(
|
|
color: Colors.grey.shade600,
|
|
fontSize: 16,
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 40),
|
|
|
|
// Campo correo
|
|
TextFormField(
|
|
controller: emailController,
|
|
|
|
decoration: InputDecoration(
|
|
labelText: 'Correo Electrónico',
|
|
hintText: 'ejemplo@correo.com',
|
|
|
|
prefixIcon: const Icon(Icons.email),
|
|
|
|
border: OutlineInputBorder(
|
|
borderRadius:
|
|
BorderRadius.circular(15),
|
|
),
|
|
),
|
|
|
|
validator: (value) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Ingresa tu correo';
|
|
}
|
|
|
|
if (!value.contains('@')) {
|
|
return 'Correo inválido';
|
|
}
|
|
|
|
return null;
|
|
},
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
// Campo contraseña
|
|
TextFormField(
|
|
controller: passwordController,
|
|
obscureText: ocultarPassword,
|
|
|
|
decoration: InputDecoration(
|
|
labelText: 'Contraseña',
|
|
|
|
prefixIcon:
|
|
const Icon(Icons.lock),
|
|
|
|
suffixIcon: IconButton(
|
|
icon: Icon(
|
|
ocultarPassword
|
|
? Icons.visibility_off
|
|
: Icons.visibility,
|
|
),
|
|
|
|
onPressed: () {
|
|
setState(() {
|
|
ocultarPassword =
|
|
!ocultarPassword;
|
|
});
|
|
},
|
|
),
|
|
|
|
border: OutlineInputBorder(
|
|
borderRadius:
|
|
BorderRadius.circular(15),
|
|
),
|
|
),
|
|
|
|
validator: (value) {
|
|
if (value == null || value.isEmpty) {
|
|
return 'Ingresa tu contraseña';
|
|
}
|
|
|
|
if (value.length < 6) {
|
|
return 'Mínimo 6 caracteres';
|
|
}
|
|
|
|
return null;
|
|
},
|
|
),
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
// Botón iniciar sesión
|
|
SizedBox(
|
|
width: double.infinity,
|
|
height: 55,
|
|
|
|
child: ElevatedButton(
|
|
onPressed: iniciarSesion,
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: Colors.green,
|
|
foregroundColor: Colors.white,
|
|
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius:
|
|
BorderRadius.circular(15),
|
|
),
|
|
),
|
|
|
|
child: const Text(
|
|
'Iniciar Sesión',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 20),
|
|
|
|
// Registro
|
|
Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.center,
|
|
|
|
children: [
|
|
const Text(
|
|
'¿No tienes cuenta?',
|
|
),
|
|
|
|
TextButton(
|
|
onPressed: () {},
|
|
|
|
child: const Text(
|
|
'Registrarse',
|
|
style: TextStyle(
|
|
color: Colors.green,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
} |