Files
APP_PEDIDOS_SIGMA/lib/services/notification_service.dart
T
PablinuxandClaude Sonnet 4.6 abe310699d fix: corrige moneda de Bs./Bolivia a USD/Ecuador en toda la app
Reemplaza todos los NumberFormat con locale en_US y símbolo $ en
los 6 screens que mostraban precios. Actualiza mock_data con
referencias a Ecuador/Quito/+593 y strings demo de notificaciones.

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

131 lines
3.8 KiB
Dart

import 'package:flutter/material.dart';
import '../models/notificacion.dart';
import '../widgets/notification_banner.dart';
class NotificationService extends ChangeNotifier {
final GlobalKey<NavigatorState> navigatorKey;
final List<Notificacion> _notifications = [];
NotificationService({required this.navigatorKey});
List<Notificacion> get notifications => List.unmodifiable(_notifications);
int get unreadCount => _notifications.where((n) => !n.leida).length;
void mostrar(Notificacion notif) {
_notifications.insert(0, notif);
notifyListeners();
_showBanner(notif);
}
void marcarTodasLeidas() {
for (final n in _notifications) {
n.leida = true;
}
notifyListeners();
}
void marcarLeida(String id) {
final idx = _notifications.indexWhere((n) => n.id == id);
if (idx >= 0) {
_notifications[idx].leida = true;
notifyListeners();
}
}
void eliminar(String id) {
_notifications.removeWhere((n) => n.id == id);
notifyListeners();
}
void _showBanner(Notificacion notif) {
final overlay = navigatorKey.currentState?.overlay;
if (overlay == null) return;
OverlayEntry? entry;
entry = OverlayEntry(
builder: (_) => NotificationBanner(
notificacion: notif,
onDismiss: () => entry?.remove(),
),
);
overlay.insert(entry);
}
// ── Disparadores de conveniencia ─────────────────────────────
void notifPedidoConfirmado(String id, String cliente) {
mostrar(Notificacion(
id: '${DateTime.now().millisecondsSinceEpoch}',
tipo: TipoNotificacion.pedidoConfirmado,
titulo: 'Pedido confirmado',
cuerpo: '$id firmado y confirmado — $cliente',
fecha: DateTime.now(),
));
}
void notifParadaVisitada(String cliente) {
mostrar(Notificacion(
id: '${DateTime.now().millisecondsSinceEpoch}',
tipo: TipoNotificacion.pedidoEntregado,
titulo: 'Visita completada',
cuerpo: 'Parada en $cliente marcada como visitada',
fecha: DateTime.now(),
));
}
void notifStockBajo(String producto, int stock) {
mostrar(Notificacion(
id: '${DateTime.now().millisecondsSinceEpoch}',
tipo: TipoNotificacion.stockBajo,
titulo: 'Stock bajo',
cuerpo: '$producto — solo $stock unidades disponibles',
fecha: DateTime.now(),
));
}
Future<void> dispararDemo() async {
final base = DateTime.now().millisecondsSinceEpoch;
final demos = [
Notificacion(
id: '${base}_1',
tipo: TipoNotificacion.paradaProxima,
titulo: 'Próxima parada en 15 min',
cuerpo: 'InfoSystems — Av. Naciones Unidas, Quito',
fecha: DateTime.now(),
),
Notificacion(
id: '${base}_2',
tipo: TipoNotificacion.stockBajo,
titulo: 'Stock bajo',
cuerpo: 'Router TP-Link AX3000 — solo 3 unidades disponibles',
fecha: DateTime.now(),
),
Notificacion(
id: '${base}_3',
tipo: TipoNotificacion.pedidoConfirmado,
titulo: 'Pedido confirmado',
cuerpo: 'TTC-0047 firmado por TechZone — \$24,500.00',
fecha: DateTime.now(),
),
Notificacion(
id: '${base}_4',
tipo: TipoNotificacion.metaVentas,
titulo: '¡Meta del día alcanzada!',
cuerpo: 'Superaste \$15,000 en ventas. ¡Excelente trabajo!',
fecha: DateTime.now(),
),
Notificacion(
id: '${base}_5',
tipo: TipoNotificacion.recordatorio,
titulo: 'Recordatorio de visita',
cuerpo: 'Gobernación de Pichincha — contrato de renovación anual pendiente',
fecha: DateTime.now(),
),
];
for (final n in demos) {
await Future.delayed(const Duration(milliseconds: 950));
mostrar(n);
}
}
}