Files
APP_PEDIDOS_SIGMA/lib/screens/login/login_screen.dart
T
PablinuxandClaude Sonnet 4.6 4a4113ec59 feat: Agente Ventas SIGMAC — app de rutas y pedidos de campo
App Flutter 2.11 para vendedores de ruta de Telcotronics.
Incluye ruta del día con mapa custom, catálogo, pedidos CRUD,
firma digital, scanner QR/barcode, selector de clientes escalable,
notificaciones in-app y soporte multiplataforma (Android + Linux desktop).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-14 09:18:18 -05:00

250 lines
7.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../providers/app_provider.dart';
import '../../theme/app_theme.dart';
class LoginScreen extends StatefulWidget {
const LoginScreen({Key? key}) : super(key: key);
@override
State<LoginScreen> createState() => _LoginScreenState();
}
class _LoginScreenState extends State<LoginScreen> {
final _emailCtrl = TextEditingController(text: 'admin@telcotronics.com');
final _passCtrl = TextEditingController(text: 'Microbot%');
bool _obscure = true;
bool _loading = false;
String? _error;
@override
void dispose() {
_emailCtrl.dispose();
_passCtrl.dispose();
super.dispose();
}
Future<void> _login() async {
setState(() { _loading = true; _error = null; });
final ok = await context.read<AppProvider>().login(
_emailCtrl.text.trim(), _passCtrl.text);
if (!ok && mounted) {
setState(() {
_loading = false;
_error = context.read<AppProvider>().loginError;
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFF1E3A8A), Color(0xFF1E40AF), Color(0xFF2563EB)],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
),
child: SafeArea(
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.symmetric(horizontal: 28),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildLogo(),
const SizedBox(height: 40),
_buildCard(),
const SizedBox(height: 24),
_buildVersion(),
],
),
),
),
),
),
);
}
Widget _buildLogo() {
return Column(
children: [
Container(
width: 96,
height: 96,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(24),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.25),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(24),
child: Image.asset(
'assets/icon/icon.png',
width: 96,
height: 96,
fit: BoxFit.cover,
),
),
),
const SizedBox(height: 20),
const Text(
'Agente Ventas',
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
color: Colors.white,
letterSpacing: 1.0,
),
),
const SizedBox(height: 4),
Text(
'by SIGMAC',
style: TextStyle(
fontSize: 13,
color: Colors.white.withOpacity(0.65),
letterSpacing: 2.0,
fontWeight: FontWeight.w500,
),
),
const SizedBox(height: 6),
Text(
'Gestión de rutas y pedidos de campo',
style: TextStyle(
fontSize: 13,
color: Colors.white.withOpacity(0.8),
),
),
],
);
}
Widget _buildCard() {
return Container(
padding: const EdgeInsets.all(28),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.2),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Iniciar sesión',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: AppTheme.textPrimary,
),
),
const SizedBox(height: 6),
const Text(
'Ingresa tus credenciales para continuar',
style: TextStyle(fontSize: 13, color: AppTheme.textSecondary),
),
const SizedBox(height: 24),
TextField(
controller: _emailCtrl,
keyboardType: TextInputType.emailAddress,
decoration: const InputDecoration(
labelText: 'Correo electrónico',
prefixIcon: Icon(Icons.email_outlined),
),
),
const SizedBox(height: 14),
TextField(
controller: _passCtrl,
obscureText: _obscure,
decoration: InputDecoration(
labelText: 'Contraseña',
prefixIcon: const Icon(Icons.lock_outline),
suffixIcon: IconButton(
icon: Icon(_obscure ? Icons.visibility_outlined : Icons.visibility_off_outlined),
onPressed: () => setState(() => _obscure = !_obscure),
),
),
),
const SizedBox(height: 8),
Align(
alignment: Alignment.centerRight,
child: TextButton(
onPressed: () {},
child: const Text('¿Olvidaste tu contraseña?'),
),
),
if (_error != null) ...[
Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
decoration: BoxDecoration(
color: AppTheme.dangerColor.withOpacity(0.08),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: AppTheme.dangerColor.withOpacity(0.3)),
),
child: Row(
children: [
const Icon(Icons.error_outline, color: AppTheme.dangerColor, size: 16),
const SizedBox(width: 8),
Expanded(
child: Text(
_error!,
style: const TextStyle(fontSize: 12, color: AppTheme.dangerColor),
),
),
],
),
),
const SizedBox(height: 8),
],
const SizedBox(height: 8),
SizedBox(
width: double.infinity,
height: 50,
child: ElevatedButton(
onPressed: _loading ? null : _login,
child: _loading
? const SizedBox(
width: 22,
height: 22,
child: CircularProgressIndicator(
strokeWidth: 2.5,
color: Colors.white,
),
)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Icon(Icons.login, size: 20),
SizedBox(width: 8),
Text('Ingresar', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
],
),
),
),
],
),
);
}
Widget _buildVersion() {
return Text(
'v1.0.0 • SIGMAC • Telcotronics',
style: TextStyle(fontSize: 12, color: Colors.white.withOpacity(0.6)),
);
}
}