feat: suite de tiendas, sync reactivo, bitácora de errores y alertas whatsapp
This commit is contained in:
@@ -13,7 +13,7 @@ class PedidoDetailScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.read<AppProvider>();
|
||||
final fmt = NumberFormat.currency(locale: 'en_US', symbol: '\$', decimalDigits: 2);
|
||||
final fmt = provider.currencyFormat;
|
||||
final estadoColor = AppTheme.estadoColor(pedido.estado.label);
|
||||
final dateStr = DateFormat('d \'de\' MMMM yyyy, HH:mm', 'es').format(pedido.fecha);
|
||||
|
||||
@@ -45,6 +45,9 @@ class PedidoDetailScreen extends StatelessWidget {
|
||||
// Header card
|
||||
_buildHeaderCard(estadoColor, dateStr),
|
||||
const SizedBox(height: 14),
|
||||
// Tarjeta de estado de sincronización hacia la nube central
|
||||
_buildSyncCard(context, provider),
|
||||
const SizedBox(height: 14),
|
||||
// Cliente
|
||||
_buildClienteCard(),
|
||||
const SizedBox(height: 14),
|
||||
@@ -115,6 +118,109 @@ class PedidoDetailScreen extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
/// Construye la tarjeta informativa de estado de transmisión con la nube SIGMA
|
||||
Widget _buildSyncCard(BuildContext context, AppProvider provider) {
|
||||
final syncEstado = pedido.syncEstado;
|
||||
final isSincronizado = syncEstado == 'SINCRONIZADO';
|
||||
final isError = syncEstado == 'ERROR';
|
||||
|
||||
final bg = isSincronizado
|
||||
? const Color(0xFF10B981).withOpacity(0.08)
|
||||
: isError
|
||||
? const Color(0xFFEF4444).withOpacity(0.08)
|
||||
: const Color(0xFFF59E0B).withOpacity(0.08);
|
||||
|
||||
final border = isSincronizado
|
||||
? const Color(0xFF10B981).withOpacity(0.25)
|
||||
: isError
|
||||
? const Color(0xFFEF4444).withOpacity(0.25)
|
||||
: const Color(0xFFF59E0B).withOpacity(0.25);
|
||||
|
||||
final iconColor = isSincronizado
|
||||
? const Color(0xFF10B981)
|
||||
: isError
|
||||
? const Color(0xFFEF4444)
|
||||
: const Color(0xFFD97706);
|
||||
|
||||
final icon = isSincronizado
|
||||
? Icons.cloud_done_rounded
|
||||
: isError
|
||||
? Icons.cloud_off_rounded
|
||||
: Icons.cloud_upload_outlined;
|
||||
|
||||
final title = isSincronizado
|
||||
? 'Pedido sincronizado en la nube'
|
||||
: isError
|
||||
? 'Error al subir a la nube'
|
||||
: 'Almacenado localmente (Offline)';
|
||||
|
||||
final desc = isSincronizado
|
||||
? 'Transmitido correctamente a API-SIGMA-CLOUD y registrado en el ERP.'
|
||||
: isError
|
||||
? 'Falló la conexión o la API central rechazó la carga.'
|
||||
: 'Se sincronizará automáticamente cuando el dispositivo tenga conexión.';
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: bg,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: border),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, color: iconColor, size: 26),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(fontSize: 13, fontWeight: FontWeight.bold, color: iconColor),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
desc,
|
||||
style: const TextStyle(fontSize: 11, color: Color(0xFF475569)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!isSincronizado && provider.modoOnline) ...[
|
||||
const SizedBox(width: 8),
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: iconColor,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
side: BorderSide(color: iconColor.withOpacity(0.4)),
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
final ok = await provider.reintentarSubidaPedido(pedido.id);
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
ok
|
||||
? '¡Pedido ${pedido.id} subido con éxito a la nube!'
|
||||
: 'No se pudo subir el pedido. Revisa tu conexión a internet.',
|
||||
),
|
||||
backgroundColor: ok ? const Color(0xFF10B981) : const Color(0xFFEF4444),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text('Subir', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12)),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildClienteCard() {
|
||||
return _sectionCard(
|
||||
title: 'Cliente',
|
||||
|
||||
Reference in New Issue
Block a user