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,296 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../services/notification_service.dart';
|
||||
import '../../models/notificacion.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
|
||||
class NotificacionesScreen extends StatelessWidget {
|
||||
const NotificacionesScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<NotificationService>(
|
||||
builder: (context, service, _) {
|
||||
final notifs = service.notifications;
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
_buildAppBar(context, service),
|
||||
if (notifs.isEmpty)
|
||||
_buildEmptyState()
|
||||
else
|
||||
_buildList(context, service, notifs),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAppBar(BuildContext context, NotificationService service) {
|
||||
return SliverAppBar(
|
||||
pinned: true,
|
||||
backgroundColor: AppTheme.primaryColor,
|
||||
title: Row(
|
||||
children: [
|
||||
const Text(
|
||||
'Notificaciones',
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
|
||||
),
|
||||
if (service.unreadCount > 0) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'${service.unreadCount} sin leer',
|
||||
style: const TextStyle(fontSize: 11, color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
if (service.unreadCount > 0)
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.done_all, color: Colors.white70, size: 18),
|
||||
label: const Text(
|
||||
'Marcar todo',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
onPressed: service.marcarTodasLeidas,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
return SliverFillRemaining(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xFFEFF6FF),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.notifications_none_rounded,
|
||||
size: 40,
|
||||
color: Color(0xFF93C5FD),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Sin notificaciones',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'Aquí aparecerán alertas de pedidos,\nstock, rutas y más.',
|
||||
style: TextStyle(fontSize: 13, color: AppTheme.textSecondary),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildList(
|
||||
BuildContext context,
|
||||
NotificationService service,
|
||||
List<Notificacion> notifs,
|
||||
) {
|
||||
final hoy = <Notificacion>[];
|
||||
final antes = <Notificacion>[];
|
||||
final now = DateTime.now();
|
||||
|
||||
for (final n in notifs) {
|
||||
if (n.fecha.day == now.day && n.fecha.month == now.month && n.fecha.year == now.year) {
|
||||
hoy.add(n);
|
||||
} else {
|
||||
antes.add(n);
|
||||
}
|
||||
}
|
||||
|
||||
final sections = <Widget>[];
|
||||
|
||||
if (hoy.isNotEmpty) {
|
||||
sections.add(_buildSectionHeader('Hoy'));
|
||||
sections.addAll(hoy.map((n) => _buildNotifCard(context, service, n)));
|
||||
}
|
||||
if (antes.isNotEmpty) {
|
||||
sections.add(_buildSectionHeader('Anteriores'));
|
||||
sections.addAll(antes.map((n) => _buildNotifCard(context, service, n)));
|
||||
}
|
||||
|
||||
return SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
...sections,
|
||||
const SizedBox(height: 24),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader(String label) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 6),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppTheme.textSecondary,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNotifCard(
|
||||
BuildContext context,
|
||||
NotificationService service,
|
||||
Notificacion notif,
|
||||
) {
|
||||
final color = notif.tipo.color;
|
||||
final timeFmt = DateFormat('HH:mm', 'es');
|
||||
final dateFmt = DateFormat('d MMM', 'es');
|
||||
final isToday = notif.fecha.day == DateTime.now().day;
|
||||
final timeLabel = isToday ? timeFmt.format(notif.fecha) : dateFmt.format(notif.fecha);
|
||||
|
||||
return Dismissible(
|
||||
key: Key(notif.id),
|
||||
direction: DismissDirection.endToStart,
|
||||
background: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 24),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.dangerColor,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: const Icon(Icons.delete_outline, color: Colors.white, size: 24),
|
||||
),
|
||||
onDismissed: (_) => service.eliminar(notif.id),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (!notif.leida) service.marcarLeida(notif.id);
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: notif.leida ? Colors.white : const Color(0xFFEFF6FF),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: notif.leida
|
||||
? Border.all(color: Colors.transparent)
|
||||
: Border(left: BorderSide(color: color, width: 3)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.04),
|
||||
blurRadius: 6,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.12),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(notif.tipo.icono, color: color, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
notif.titulo,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: notif.leida ? FontWeight.w500 : FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
timeLabel,
|
||||
style: const TextStyle(fontSize: 11, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
notif.cuerpo,
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
notif.tipo.label,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: color,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!notif.leida) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
width: 7,
|
||||
height: 7,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Sin leer',
|
||||
style: TextStyle(fontSize: 10, color: color, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user