feat: commit inicial — Central Monitoreo v1.0.0
- OperadorLoginPage con auth WebControl 2 pasos (empresas → login) - ShellPage: sidebar 220px + IndexedStack + header con estado API - DashboardPage: stat cards, feed alarmas, clientes, incidentes (timer 30s) - ApiAuthService: flujo real con email + paswd + dba → token + apiKey - DB SQLite v1: 7 tablas + 7 DAOs completos - theme.dart: AppColors, appHeadline (Manrope), appLabel (Inter) - Logo app: escudo radar neón (SVG + PNG 512px) en lib/recursos/ - desplegar.sh: build release Linux + upload a siax-system.net - agents.md: estado completo + objetivos futuros documentados Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
+266
@@ -0,0 +1,266 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
|
||||
import 'theme.dart';
|
||||
import 'services/api_auth_service.dart';
|
||||
import 'shell_page.dart';
|
||||
|
||||
Future<void> main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
sqfliteFfiInit();
|
||||
databaseFactory = databaseFactoryFfi;
|
||||
|
||||
final autenticado = await ApiAuthService.instance.isAuthenticated();
|
||||
runApp(CentroMonitoreoApp(inicioAutenticado: autenticado));
|
||||
}
|
||||
|
||||
class CentroMonitoreoApp extends StatelessWidget {
|
||||
final bool inicioAutenticado;
|
||||
const CentroMonitoreoApp({Key? key, required this.inicioAutenticado})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Centro de Monitoreo',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
brightness: Brightness.dark,
|
||||
scaffoldBackgroundColor: AppColors.surfaceLowest,
|
||||
canvasColor: AppColors.surfaceLow,
|
||||
cardColor: AppColors.surfaceHigh,
|
||||
dialogBackgroundColor: AppColors.surfaceHigh,
|
||||
dividerColor: AppColors.outlineVariant,
|
||||
colorScheme: const ColorScheme.dark(
|
||||
primary: AppColors.primary,
|
||||
onPrimary: AppColors.primaryContainer,
|
||||
secondary: AppColors.secondary,
|
||||
surface: AppColors.surface,
|
||||
onSurface: AppColors.onSurface,
|
||||
error: AppColors.error,
|
||||
onError: AppColors.onError,
|
||||
),
|
||||
),
|
||||
initialRoute: inicioAutenticado ? '/shell' : '/login',
|
||||
routes: {
|
||||
'/login': (_) => const OperadorLoginPage(),
|
||||
'/shell': (_) => const ShellPage(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Login Page ───────────────────────────────────────────────────────────────
|
||||
|
||||
class OperadorLoginPage extends StatefulWidget {
|
||||
const OperadorLoginPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<OperadorLoginPage> createState() => _OperadorLoginPageState();
|
||||
}
|
||||
|
||||
class _OperadorLoginPageState extends State<OperadorLoginPage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _ctrlUser = TextEditingController();
|
||||
final _ctrlPass = TextEditingController();
|
||||
bool _cargando = false;
|
||||
bool _verPass = false;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_ctrlUser.dispose();
|
||||
_ctrlPass.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _login() async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
setState(() { _cargando = true; _error = null; });
|
||||
|
||||
final ok = await ApiAuthService.instance.login(
|
||||
_ctrlUser.text.trim(),
|
||||
_ctrlPass.text,
|
||||
);
|
||||
|
||||
if (!mounted) return;
|
||||
if (ok) {
|
||||
Navigator.of(context).pushReplacementNamed('/shell');
|
||||
} else {
|
||||
setState(() {
|
||||
_cargando = false;
|
||||
_error = 'Credenciales incorrectas o sin conexión con WebControl.';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.surfaceLowest,
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
primary: false,
|
||||
padding: const EdgeInsets.all(32),
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 400),
|
||||
child: Column(children: [
|
||||
// Logo
|
||||
Image.asset(
|
||||
'lib/recursos/logo_app.png',
|
||||
width: 96,
|
||||
height: 96,
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text('CENTRO DE MONITOREO',
|
||||
style: appHeadline(
|
||||
size: 18,
|
||||
weight: FontWeight.w800,
|
||||
color: AppColors.primary,
|
||||
spacing: 2.0)),
|
||||
const SizedBox(height: 6),
|
||||
Text('Acceso para operadores autorizados',
|
||||
style: appLabel(size: 12, color: AppColors.outline)),
|
||||
const SizedBox(height: 40),
|
||||
|
||||
// Card de login
|
||||
Container(
|
||||
padding: const EdgeInsets.all(32),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColors.outlineVariant, width: 1),
|
||||
),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.stretch, children: [
|
||||
Text('Iniciar sesión',
|
||||
style: appHeadline(size: 16, weight: FontWeight.w700)),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Usuario
|
||||
_campo(
|
||||
controller: _ctrlUser,
|
||||
label: 'Usuario',
|
||||
icono: Icons.person_outline,
|
||||
validator: (v) =>
|
||||
(v == null || v.trim().isEmpty) ? 'Ingresa tu usuario' : null,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Contraseña
|
||||
_campo(
|
||||
controller: _ctrlPass,
|
||||
label: 'Contraseña',
|
||||
icono: Icons.lock_outline,
|
||||
obscure: !_verPass,
|
||||
sufijo: IconButton(
|
||||
icon: Icon(
|
||||
_verPass ? Icons.visibility_off : Icons.visibility,
|
||||
color: AppColors.outline,
|
||||
size: 18,
|
||||
),
|
||||
onPressed: () => setState(() => _verPass = !_verPass),
|
||||
),
|
||||
validator: (v) =>
|
||||
(v == null || v.isEmpty) ? 'Ingresa tu contraseña' : null,
|
||||
onSubmit: (_) => _login(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
|
||||
// Error
|
||||
if (_error != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Text(_error!,
|
||||
style: appLabel(size: 12, color: AppColors.error)),
|
||||
),
|
||||
|
||||
// Botón
|
||||
SizedBox(
|
||||
height: 48,
|
||||
child: ElevatedButton(
|
||||
onPressed: _cargando ? null : _login,
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: AppColors.primary,
|
||||
onPrimary: AppColors.primaryContainer,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
child: _cargando
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
color: AppColors.primaryContainer),
|
||||
)
|
||||
: Text('INGRESAR',
|
||||
style: appHeadline(
|
||||
size: 13,
|
||||
weight: FontWeight.w800,
|
||||
color: AppColors.primaryContainer,
|
||||
spacing: 1.2)),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 32),
|
||||
Text('Telcotronics · WebControl',
|
||||
style: appLabel(size: 11, color: AppColors.outlineVariant)),
|
||||
]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _campo({
|
||||
required TextEditingController controller,
|
||||
required String label,
|
||||
required IconData icono,
|
||||
bool obscure = false,
|
||||
Widget? sufijo,
|
||||
String? Function(String?)? validator,
|
||||
void Function(String)? onSubmit,
|
||||
}) =>
|
||||
TextFormField(
|
||||
controller: controller,
|
||||
obscureText: obscure,
|
||||
style: appLabel(size: 13, color: AppColors.onSurface),
|
||||
onFieldSubmitted: onSubmit,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
labelStyle: appLabel(size: 12, color: AppColors.outline),
|
||||
prefixIcon: Icon(icono, color: AppColors.outline, size: 18),
|
||||
suffixIcon: sufijo,
|
||||
filled: true,
|
||||
fillColor: AppColors.surfaceHigh,
|
||||
contentPadding:
|
||||
const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: AppColors.outlineVariant),
|
||||
),
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: AppColors.outlineVariant),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: AppColors.primary, width: 1.5),
|
||||
),
|
||||
errorBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: AppColors.error),
|
||||
),
|
||||
focusedErrorBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
borderSide: const BorderSide(color: AppColors.error, width: 1.5),
|
||||
),
|
||||
),
|
||||
validator: validator,
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user