feat: Agente Ventas SIGMAC — app de rutas y pedidos de campo
App Flutter 2.11 para vendedores de ruta de Telcotronics. Incluye ruta del día con mapa custom, catálogo, pedidos CRUD, firma digital, scanner QR/barcode, selector de clientes escalable, notificaciones in-app y soporte multiplataforma (Android + Linux desktop). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
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 La Paz — Av. Mariscal Santa Cruz 1250',
|
||||
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 Bolivia — Bs. 24,500.00',
|
||||
fecha: DateTime.now(),
|
||||
),
|
||||
Notificacion(
|
||||
id: '${base}_4',
|
||||
tipo: TipoNotificacion.metaVentas,
|
||||
titulo: '¡Meta del día alcanzada!',
|
||||
cuerpo: 'Superaste Bs. 15,000 en ventas. ¡Excelente trabajo, Roberto!',
|
||||
fecha: DateTime.now(),
|
||||
),
|
||||
Notificacion(
|
||||
id: '${base}_5',
|
||||
tipo: TipoNotificacion.recordatorio,
|
||||
titulo: 'Recordatorio de visita',
|
||||
cuerpo: 'Gobernación La Paz — contrato de renovación anual pendiente',
|
||||
fecha: DateTime.now(),
|
||||
),
|
||||
];
|
||||
|
||||
for (final n in demos) {
|
||||
await Future.delayed(const Duration(milliseconds: 950));
|
||||
mostrar(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user