Files
seguridad_electronica/lib/pages/control_acceso_page.dart
T
PablinuxandClaude Sonnet 4.6 1184ab5fe2 feat: add SQLite data layer, local auth and security settings
- Add offline-first SQLite architecture with DatabaseHelper singleton,
  12 CREATE TABLE statements and full seed data on first launch
- Add 10 models (fromMap/toMap) and 12 DAOs with CRUD + getPendientes()
- Add ApiAuthService (JWT via SharedPreferences) and Sincronizador skeleton
- Move login auth from SQLite to SharedPreferences with SHA-256 PIN hash;
  default PIN 123456, platform-independent (no native plugin required)
- Add seguridad_page.dart: change PIN form (current → new → confirm)
- Add Cerrar Sesión with confirmation dialog and full stack clear
- Redesign settings_page.dart with AppColors dark theme; add Sistema
  section with "Inicializar base de datos" and "Inicializar sincronización"
- Fix Linux desktop: sqflite_common_ffi with platform detection in DatabaseHelper
- Fix ScrollController conflict on Linux: primary: false on all IndexedStack pages
- Update plan_proyecto.md with session 2–3 progress and auth roadmap

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-14 01:56:13 -05:00

485 lines
18 KiB
Dart

//agregar un boton para registrar usuarios y dale acceso por tiempo y areas
import 'package:flutter/material.dart';
import '../theme.dart';
class ControlAccesoPage extends StatefulWidget {
const ControlAccesoPage({Key? key}) : super(key: key);
@override
State<ControlAccesoPage> createState() => _ControlAccesoPageState();
}
class _ControlAccesoPageState extends State<ControlAccesoPage> {
bool _lobbyBloqueado = true;
bool _muelleBloqueado = false;
bool _serverBloqueado = true;
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
primary: false,
padding: const EdgeInsets.fromLTRB(24, 24, 24, 24),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_encabezado(),
const SizedBox(height: 32),
_gridEntradas(),
const SizedBox(height: 40),
_registroAcceso(),
const SizedBox(height: 24),
_snapshotCamara(),
],
),
);
}
// ── Encabezado ──────────────────────────────────────────────────────────────
Widget _encabezado() => Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
Container(
width: 8,
height: 8,
decoration: const BoxDecoration(
shape: BoxShape.circle, color: AppColors.primary),
),
const SizedBox(width: 8),
Text('SISTEMA ACTIVO',
style: appLabel(
size: 10,
weight: FontWeight.bold,
color: AppColors.primary,
spacing: 2.0)),
]),
const SizedBox(height: 4),
Text('CONTROL DE ACCESO',
style: appHeadline(size: 28, weight: FontWeight.w800)),
],
);
// ── Grid de entradas ────────────────────────────────────────────────────────
Widget _gridEntradas() => Column(children: [
_cardLobbyPrincipal(),
const SizedBox(height: 16),
Row(children: [
Expanded(child: _cardMuelleCarga()),
const SizedBox(width: 16),
Expanded(child: _cardCentrosDatos()),
]),
]);
Widget _cardLobbyPrincipal() => ClipRRect(
borderRadius: BorderRadius.circular(12),
child: IntrinsicHeight(
child: Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Container(width: 4, color: AppColors.primary),
Expanded(
child: Container(
color: AppColors.surfaceHigh,
padding: const EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Entrada 01',
style: appLabel(size: 10, spacing: 2.0)),
const SizedBox(height: 4),
Text('Lobby Principal',
style: appHeadline(size: 17)),
]),
_badgeEstado(_lobbyBloqueado),
],
),
const SizedBox(height: 20),
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: () =>
setState(() => _lobbyBloqueado = !_lobbyBloqueado),
icon: Icon(
_lobbyBloqueado ? Icons.lock_open : Icons.lock,
size: 16),
label: Text(
_lobbyBloqueado
? 'DESBLOQUEO REMOTO'
: 'BLOQUEAR PUERTA',
style: appLabel(
size: 13,
weight: FontWeight.bold,
color: AppColors.primaryContainer)),
style: ElevatedButton.styleFrom(
primary: AppColors.primary,
onPrimary: AppColors.primaryContainer,
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8)),
elevation: 0,
),
),
),
],
),
),
),
]),
),
);
Widget _cardMuelleCarga() => ClipRRect(
borderRadius: BorderRadius.circular(12),
child: IntrinsicHeight(
child: Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Container(width: 4, color: AppColors.tertiary),
Expanded(
child: Container(
color: AppColors.surfaceLow,
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Puerta 04', style: appLabel(size: 10, spacing: 2.0)),
const SizedBox(height: 4),
Text('Muelle de Carga', style: appHeadline(size: 14)),
const SizedBox(height: 12),
_badgeEstado(_muelleBloqueado),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () => setState(
() => _muelleBloqueado = !_muelleBloqueado),
style: ElevatedButton.styleFrom(
primary: AppColors.surfaceHighest,
onPrimary: AppColors.onSurface,
padding: const EdgeInsets.symmetric(vertical: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8)),
elevation: 0,
),
child: Text(
_muelleBloqueado
? 'DESBLOQUEAR'
: 'ASEGURAR PUERTA',
style: appLabel(
size: 11,
weight: FontWeight.bold,
color: AppColors.onSurface)),
),
),
],
),
),
),
]),
),
);
Widget _cardCentrosDatos() => ClipRRect(
borderRadius: BorderRadius.circular(12),
child: IntrinsicHeight(
child: Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
Container(width: 4, color: AppColors.primary),
Expanded(
child: Container(
color: AppColors.surfaceLow,
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('Seguro 01', style: appLabel(size: 10, spacing: 2.0)),
const SizedBox(height: 4),
Text('Centro de Datos', style: appHeadline(size: 14)),
const SizedBox(height: 12),
_badgeEstado(_serverBloqueado),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () => setState(
() => _serverBloqueado = !_serverBloqueado),
style: ElevatedButton.styleFrom(
primary: AppColors.surfaceHighest,
onPrimary: AppColors.onSurface,
padding: const EdgeInsets.symmetric(vertical: 10),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8)),
elevation: 0,
),
child: Text(
_serverBloqueado ? 'DESBLOQUEO REMOTO' : 'BLOQUEAR',
style: appLabel(
size: 11,
weight: FontWeight.bold,
color: AppColors.onSurface)),
),
),
],
),
),
),
]),
),
);
Widget _badgeEstado(bool bloqueado) => Container(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: bloqueado
? AppColors.primaryContainer
: AppColors.tertiaryContainer,
borderRadius: BorderRadius.circular(99)),
child: Row(mainAxisSize: MainAxisSize.min, children: [
Icon(bloqueado ? Icons.lock : Icons.lock_open,
size: 14,
color: bloqueado ? AppColors.primary : AppColors.tertiary),
const SizedBox(width: 6),
Text(bloqueado ? 'BLOQUEADO' : 'DESBLOQUEADO',
style: appLabel(
size: 10,
weight: FontWeight.bold,
color: bloqueado ? AppColors.primary : AppColors.tertiary)),
]),
);
// ── Registro de acceso ──────────────────────────────────────────────────────
Widget _registroAcceso() => Column(
children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text('Registro de Acceso',
style: appHeadline(size: 20, weight: FontWeight.bold)),
GestureDetector(
onTap: () {},
child: Row(children: [
const Icon(Icons.filter_list,
color: AppColors.primary, size: 20),
const SizedBox(width: 6),
Text('FILTRAR',
style: appLabel(
size: 10,
weight: FontWeight.bold,
color: AppColors.primary,
spacing: 2.0)),
]),
),
]),
const SizedBox(height: 24),
_entradaLog(
iniciales: 'MV',
colorAvatar: AppColors.primary,
nombre: 'Marcus Vance',
hora: '14:22:04',
descripcion: 'Lobby Principal • Entrada Autorizada',
descColor: AppColors.onSurfaceVariant,
estadoOk: true,
),
const SizedBox(height: 24),
_entradaLog(
iniciales: 'ER',
colorAvatar: AppColors.tertiary,
nombre: 'Elena Rodríguez',
hora: '13:45:12',
descripcion: 'Centro de Datos • Acceso Denegado (Falla de Auth)',
descColor: AppColors.tertiary,
estadoOk: false,
),
const SizedBox(height: 24),
_entradaLog(
iniciales: 'ST',
colorAvatar: AppColors.primary,
nombre: 'Equipo de Seguridad (R0)',
hora: '12:30:00',
descripcion: 'Muelle de Carga • Apertura Remota',
descColor: AppColors.onSurfaceVariant,
estadoOk: true,
),
],
);
Widget _entradaLog({
required String iniciales,
required Color colorAvatar,
required String nombre,
required String hora,
required String descripcion,
required Color descColor,
required bool estadoOk,
}) =>
Row(crossAxisAlignment: CrossAxisAlignment.start, children: [
Stack(clipBehavior: Clip.none, children: [
Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: colorAvatar.withOpacity(0.15),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: colorAvatar.withOpacity(0.3)),
),
child: Center(
child: Text(iniciales,
style: appHeadline(
size: 16, weight: FontWeight.bold, color: colorAvatar)),
),
),
Positioned(
bottom: -4,
right: -4,
child: Container(
width: 20,
height: 20,
decoration: BoxDecoration(
color: estadoOk ? AppColors.primary : AppColors.tertiary,
borderRadius: BorderRadius.circular(6),
border: Border.all(color: AppColors.surfaceLowest, width: 2),
),
child: Icon(
estadoOk ? Icons.check : Icons.warning,
size: 11,
color: estadoOk
? AppColors.primaryContainer
: AppColors.tertiaryContainer,
),
),
),
]),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Text(nombre, style: appHeadline(size: 14)),
Text(hora, style: appLabel(size: 10)),
]),
const SizedBox(height: 4),
Text(descripcion, style: appLabel(size: 13, color: descColor)),
],
)),
]);
// ── Snapshot de cámara ──────────────────────────────────────────────────────
Widget _snapshotCamara() => Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: AppColors.surfaceLow,
borderRadius: BorderRadius.circular(12)),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(children: [
const Icon(Icons.photo_camera,
color: AppColors.primary, size: 18),
const SizedBox(width: 8),
Text('FOTO ENTRADA 01',
style: appLabel(
size: 10, weight: FontWeight.bold, spacing: 2.0)),
]),
const SizedBox(height: 12),
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: SizedBox(
height: 160,
width: double.infinity,
child: Stack(children: [
Container(
decoration: const BoxDecoration(
gradient: RadialGradient(
center: Alignment(0.3, -0.2),
radius: 1.5,
colors: [Color(0xFF0D1F2D), Color(0xFF050A0E)],
),
),
),
CustomPaint(
size: const Size(double.infinity, 160),
painter: _GridPainterGreen()),
// Figuras decorativas CCTV
Positioned(
left: 40,
top: 20,
child: _cctv_box(
80, 60, AppColors.primary.withOpacity(0.15))),
Positioned(
right: 60,
top: 40,
child: _cctv_box(
50, 40, AppColors.primary.withOpacity(0.08))),
// Overlay oscuro inferior
Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.bottomCenter,
end: Alignment.topCenter,
colors: [
Colors.black.withOpacity(0.6),
Colors.transparent
],
),
),
),
Positioned(
top: 8,
left: 8,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 8, vertical: 3),
decoration: BoxDecoration(
color: AppColors.error.withOpacity(0.85),
borderRadius: BorderRadius.circular(4)),
child: Text('● GRABANDO EN VIVO',
style: appLabel(
size: 9,
weight: FontWeight.bold,
color: Colors.white,
spacing: 0.5)),
),
),
Positioned(
bottom: 8,
right: 8,
child: Text('CAM_01_LOBBY_H264',
style: appLabel(size: 9, color: Colors.white54)),
),
]),
),
),
],
),
);
Widget _cctv_box(double w, double h, Color color) => Container(
width: w,
height: h,
decoration: BoxDecoration(
border: Border.all(color: color, width: 1),
color: color.withOpacity(0.05),
),
);
}
class _GridPainterGreen extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
final p = Paint()
..color = const Color(0xFF0B3D2E).withOpacity(0.6)
..strokeWidth = 0.5;
for (double x = 0; x <= size.width; x += 18) {
canvas.drawLine(Offset(x, 0), Offset(x, size.height), p);
}
for (double y = 0; y <= size.height; y += 18) {
canvas.drawLine(Offset(0, y), Offset(size.width, y), p);
}
}
@override
bool shouldRepaint(covariant CustomPainter o) => false;
}