feat: add login page with 6-digit PIN authentication
Pantalla de login con 6 cajas individuales animadas, auto-avance de foco, retroceso con backspace y validación mínima de 4 dígitos. Al ingresar navega a MainPage en tab INICIO. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
dd2fb28827
commit
d28f41f3dd
+275
@@ -0,0 +1,275 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
import 'theme.dart';
|
||||||
|
import 'main_page.dart';
|
||||||
|
import 'pages/register_page.dart';
|
||||||
|
import 'widgets/app_menu_button.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
runApp(const MyApp());
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyApp extends StatelessWidget {
|
||||||
|
const MyApp({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MaterialApp(
|
||||||
|
title: 'SENTINEL ONE',
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
|
theme: ThemeData(
|
||||||
|
brightness: Brightness.dark,
|
||||||
|
scaffoldBackgroundColor: AppColors.surfaceLowest,
|
||||||
|
useMaterial3: true,
|
||||||
|
),
|
||||||
|
home: const LoginPage(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Página de Login ───────────────────────────────────────────────────────────
|
||||||
|
class LoginPage extends StatefulWidget {
|
||||||
|
const LoginPage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<LoginPage> createState() => _LoginPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LoginPageState extends State<LoginPage> {
|
||||||
|
static const int _codeLength = 6;
|
||||||
|
|
||||||
|
final List<TextEditingController> _controllers =
|
||||||
|
List.generate(_codeLength, (_) => TextEditingController());
|
||||||
|
final List<FocusNode> _focusNodes =
|
||||||
|
List.generate(_codeLength, (_) => FocusNode());
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
for (final c in _controllers) c.dispose();
|
||||||
|
for (final f in _focusNodes) f.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onDigitChanged(int index, String value) {
|
||||||
|
if (value.isNotEmpty && index < _codeLength - 1) {
|
||||||
|
_focusNodes[index + 1].requestFocus();
|
||||||
|
}
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onKeyEvent(int index, RawKeyEvent event) {
|
||||||
|
if (event is RawKeyDownEvent &&
|
||||||
|
event.logicalKey == LogicalKeyboardKey.backspace &&
|
||||||
|
_controllers[index].text.isEmpty &&
|
||||||
|
index > 0) {
|
||||||
|
_focusNodes[index - 1].requestFocus();
|
||||||
|
_controllers[index - 1].clear();
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleLogin() {
|
||||||
|
final filled = _controllers.where((c) => c.text.isNotEmpty).length;
|
||||||
|
if (filled < 4) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(content: Text('Introduce al menos 4 dígitos')),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Navigator.pushReplacement(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (_) => const MainPage(initialIndex: 0)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _clearCode() {
|
||||||
|
for (final c in _controllers) c.clear();
|
||||||
|
_focusNodes[0].requestFocus();
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final filled = _controllers.where((c) => c.text.isNotEmpty).length;
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: AppColors.surfaceLowest,
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: AppColors.surfaceLow,
|
||||||
|
elevation: 0,
|
||||||
|
automaticallyImplyLeading: false,
|
||||||
|
title: Row(children: [
|
||||||
|
const Icon(Icons.security, color: AppColors.primary, size: 20),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Text('SENTINEL ONE',
|
||||||
|
style: appHeadline(size: 16, weight: FontWeight.w900,
|
||||||
|
color: AppColors.primary, spacing: 2.0)),
|
||||||
|
]),
|
||||||
|
actions: const [AppMenuButton()],
|
||||||
|
),
|
||||||
|
body: SafeArea(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||||
|
child: ConstrainedBox(
|
||||||
|
constraints: BoxConstraints(
|
||||||
|
minHeight: MediaQuery.of(context).size.height -
|
||||||
|
MediaQuery.of(context).padding.top,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const SizedBox(height: 48),
|
||||||
|
// Logo
|
||||||
|
Container(
|
||||||
|
width: 72, height: 72,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
color: AppColors.primaryContainer,
|
||||||
|
boxShadow: [BoxShadow(
|
||||||
|
color: AppColors.primary.withOpacity(0.3),
|
||||||
|
blurRadius: 24, spreadRadius: 4)],
|
||||||
|
),
|
||||||
|
child: const Icon(Icons.security,
|
||||||
|
size: 36, color: AppColors.primary),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Text('SENTINEL ONE',
|
||||||
|
style: GoogleFonts.manrope(
|
||||||
|
fontSize: 22,
|
||||||
|
fontWeight: FontWeight.w900,
|
||||||
|
color: AppColors.primary,
|
||||||
|
letterSpacing: 2.5)),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text('Sistema de Seguridad Electrónica',
|
||||||
|
style: GoogleFonts.inter(
|
||||||
|
fontSize: 13,
|
||||||
|
color: AppColors.onSurfaceVariant)),
|
||||||
|
const SizedBox(height: 48),
|
||||||
|
// Código de acceso
|
||||||
|
Container(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: AppColors.surfaceHigh,
|
||||||
|
borderRadius: BorderRadius.circular(16)),
|
||||||
|
child: Column(children: [
|
||||||
|
Text('CÓDIGO DE ACCESO',
|
||||||
|
style: GoogleFonts.inter(
|
||||||
|
fontSize: 11,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: AppColors.onSurfaceVariant,
|
||||||
|
letterSpacing: 2.0)),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: List.generate(
|
||||||
|
_codeLength, (i) => _digitBox(i)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text('$filled / 4-6 dígitos',
|
||||||
|
style: GoogleFonts.inter(
|
||||||
|
fontSize: 11,
|
||||||
|
color: AppColors.outline)),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
child: ElevatedButton(
|
||||||
|
onPressed: filled >= 4 ? _handleLogin : null,
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
primary: AppColors.primary,
|
||||||
|
onPrimary: AppColors.primaryContainer,
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(12)),
|
||||||
|
elevation: 0,
|
||||||
|
),
|
||||||
|
child: Text('INGRESAR',
|
||||||
|
style: GoogleFonts.inter(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
letterSpacing: 1.5,
|
||||||
|
color: filled >= 4
|
||||||
|
? AppColors.primaryContainer
|
||||||
|
: AppColors.onSurfaceVariant)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
TextButton.icon(
|
||||||
|
onPressed: _clearCode,
|
||||||
|
icon: const Icon(Icons.backspace_outlined,
|
||||||
|
size: 16, color: AppColors.onSurfaceVariant),
|
||||||
|
label: Text('Limpiar',
|
||||||
|
style: GoogleFonts.inter(
|
||||||
|
color: AppColors.onSurfaceVariant, fontSize: 13)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (_) => const RegisterPage()),
|
||||||
|
),
|
||||||
|
child: Text('¿No tienes cuenta? Regístrate',
|
||||||
|
style: GoogleFonts.inter(
|
||||||
|
color: AppColors.primary, fontSize: 13)),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 48),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _digitBox(int index) {
|
||||||
|
final isFilled = _controllers[index].text.isNotEmpty;
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||||
|
child: RawKeyboardListener(
|
||||||
|
focusNode: FocusNode(),
|
||||||
|
onKey: (e) => _onKeyEvent(index, e),
|
||||||
|
child: SizedBox(
|
||||||
|
width: 44,
|
||||||
|
child: TextFormField(
|
||||||
|
controller: _controllers[index],
|
||||||
|
focusNode: _focusNodes[index],
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
keyboardType: TextInputType.number,
|
||||||
|
obscureText: true,
|
||||||
|
maxLength: 1,
|
||||||
|
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||||
|
style: GoogleFonts.inter(
|
||||||
|
fontSize: 20,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: AppColors.primary),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
counterText: '',
|
||||||
|
contentPadding: const EdgeInsets.symmetric(vertical: 14),
|
||||||
|
enabledBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: BorderSide(
|
||||||
|
color: isFilled
|
||||||
|
? AppColors.primary
|
||||||
|
: AppColors.outlineVariant,
|
||||||
|
width: isFilled ? 2 : 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
focusedBorder: OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
borderSide: const BorderSide(
|
||||||
|
color: AppColors.primary, width: 2),
|
||||||
|
),
|
||||||
|
filled: true,
|
||||||
|
fillColor: isFilled
|
||||||
|
? AppColors.primaryContainer.withOpacity(0.3)
|
||||||
|
: AppColors.surfaceHighest,
|
||||||
|
),
|
||||||
|
onChanged: (v) => _onDigitChanged(index, v),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user