feat: servicios WhatsApp, Bitácora WebControl, SQLite v4, UI y store listing
This commit is contained in:
@@ -6,6 +6,7 @@ import '../theme.dart';
|
||||
import '../db/dao/usuarios_dao.dart';
|
||||
import '../db/dao/zonas_dao.dart';
|
||||
import '../models/zona.dart';
|
||||
import '../services/whatsapp_alert_service.dart';
|
||||
|
||||
class RegistrarUsuarioPage extends StatefulWidget {
|
||||
const RegistrarUsuarioPage({Key? key}) : super(key: key);
|
||||
@@ -18,6 +19,8 @@ class _RegistrarUsuarioPageState extends State<RegistrarUsuarioPage> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _nombreCtrl = TextEditingController();
|
||||
final _pinCtrl = TextEditingController();
|
||||
// Controlador para el número de teléfono con código de país para alertas WhatsApp
|
||||
final _telefonoCtrl = TextEditingController();
|
||||
final _dao = UsuariosDao();
|
||||
final _zonasDao = ZonasDao();
|
||||
|
||||
@@ -55,6 +58,7 @@ class _RegistrarUsuarioPageState extends State<RegistrarUsuarioPage> {
|
||||
void dispose() {
|
||||
_nombreCtrl.dispose();
|
||||
_pinCtrl.dispose();
|
||||
_telefonoCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -114,6 +118,12 @@ class _RegistrarUsuarioPageState extends State<RegistrarUsuarioPage> {
|
||||
.where((z) => _zonasSeleccionadas.contains(z.id))
|
||||
.map((z) => z.codigo)
|
||||
.join(',');
|
||||
// Normaliza y valida el teléfono según estándar E.164
|
||||
final telRaw = _telefonoCtrl.text.trim();
|
||||
final telefonoNormalizado = telRaw.isEmpty
|
||||
? null
|
||||
: WhatsAppAlertService.normalizarTelefono(telRaw);
|
||||
|
||||
await _dao.registrar(
|
||||
nombre: _nombreCtrl.text.trim(),
|
||||
iniciales: _calcularIniciales(_nombreCtrl.text),
|
||||
@@ -122,6 +132,7 @@ class _RegistrarUsuarioPageState extends State<RegistrarUsuarioPage> {
|
||||
areas: areas,
|
||||
fechaInicio: _fechaInicio.toIso8601String(),
|
||||
fechaFin: _fechaFin?.toIso8601String(),
|
||||
telefono: telefonoNormalizado,
|
||||
);
|
||||
if (!mounted) return;
|
||||
Navigator.pop(context, true);
|
||||
@@ -185,6 +196,9 @@ class _RegistrarUsuarioPageState extends State<RegistrarUsuarioPage> {
|
||||
_campoNombre(),
|
||||
const SizedBox(height: 16),
|
||||
_campoPin(),
|
||||
const SizedBox(height: 16),
|
||||
// Campo para asociar el WhatsApp del usuario con validación Regex de país
|
||||
_campoTelefono(),
|
||||
const SizedBox(height: 28),
|
||||
_seccion('Nivel de acceso'),
|
||||
const SizedBox(height: 12),
|
||||
@@ -264,6 +278,28 @@ class _RegistrarUsuarioPageState extends State<RegistrarUsuarioPage> {
|
||||
},
|
||||
);
|
||||
|
||||
// ── Campo Teléfono WhatsApp (opcional con validación estricta E.164) ──────
|
||||
Widget _campoTelefono() => TextFormField(
|
||||
controller: _telefonoCtrl,
|
||||
style: appLabel(size: 15, color: AppColors.onSurface),
|
||||
keyboardType: TextInputType.phone,
|
||||
decoration: _inputDeco(
|
||||
label: 'WhatsApp alertas (ej. +5939XXXXXXXX)',
|
||||
icon: Icons.phone_android,
|
||||
),
|
||||
validator: (v) {
|
||||
if (v == null || v.trim().isEmpty) return null;
|
||||
final limpio = WhatsAppAlertService.normalizarTelefono(v);
|
||||
if (limpio.startsWith('0')) {
|
||||
return 'No debe iniciar con 0. Incluye código país (ej. +593...)';
|
||||
}
|
||||
if (!WhatsAppAlertService.esNumeroValido(limpio)) {
|
||||
return 'Código de país obligatorio (ej. +5939XXXXXXXX)';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
|
||||
InputDecoration _inputDeco({
|
||||
required String label,
|
||||
required IconData icon,
|
||||
|
||||
Reference in New Issue
Block a user