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',
|
||||
|
||||
@@ -21,7 +21,7 @@ class _PedidoFormScreenState extends State<PedidoFormScreen> {
|
||||
String _productoQuery = '';
|
||||
bool _showSearch = false;
|
||||
|
||||
final _fmt = NumberFormat.currency(locale: 'en_US', symbol: '\$', decimalDigits: 2);
|
||||
NumberFormat get _fmt => context.watch<AppProvider>().currencyFormat;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -349,7 +349,7 @@ class _PedidoFormScreenState extends State<PedidoFormScreen> {
|
||||
icon: const Icon(Icons.delete_outline, size: 16),
|
||||
label: const Text('Limpiar', style: TextStyle(fontSize: 12)),
|
||||
onPressed: provider.limpiarCarrito,
|
||||
style: TextButton.styleFrom(primary: AppTheme.dangerColor),
|
||||
style: TextButton.styleFrom(foregroundColor: AppTheme.dangerColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -6,6 +6,8 @@ import '../../theme/app_theme.dart';
|
||||
import '../../models/pedido.dart';
|
||||
import 'pedido_form_screen.dart';
|
||||
import 'pedido_detail_screen.dart';
|
||||
// Botón interactivo de sincronización para AppBar
|
||||
import '../../widgets/sync_status_button.dart';
|
||||
|
||||
class PedidosScreen extends StatefulWidget {
|
||||
const PedidosScreen({Key? key}) : super(key: key);
|
||||
@@ -16,7 +18,7 @@ class PedidosScreen extends StatefulWidget {
|
||||
|
||||
class _PedidosScreenState extends State<PedidosScreen> with SingleTickerProviderStateMixin {
|
||||
late TabController _tab;
|
||||
final _fmt = NumberFormat.currency(locale: 'en_US', symbol: '\$', decimalDigits: 2);
|
||||
NumberFormat get _fmt => context.watch<AppProvider>().currencyFormat;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -39,6 +41,8 @@ class _PedidosScreenState extends State<PedidosScreen> with SingleTickerProvider
|
||||
appBar: AppBar(
|
||||
title: const Text('Pedidos', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
actions: [
|
||||
// Botón reactivo de sincronización para comprobar y forzar subidas
|
||||
const SyncStatusButton(),
|
||||
IconButton(icon: const Icon(Icons.search), onPressed: () {}),
|
||||
IconButton(icon: const Icon(Icons.filter_list), onPressed: () {}),
|
||||
],
|
||||
@@ -97,23 +101,48 @@ class _PedidosScreenState extends State<PedidosScreen> with SingleTickerProvider
|
||||
}
|
||||
|
||||
Widget _buildList(BuildContext context, List<Pedido> pedidos, AppProvider provider) {
|
||||
if (pedidos.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.receipt_long_outlined, size: 64, color: Colors.grey.shade300),
|
||||
const SizedBox(height: 12),
|
||||
const Text('No hay pedidos', style: TextStyle(color: AppTheme.textSecondary, fontSize: 15)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 80),
|
||||
itemCount: pedidos.length,
|
||||
itemBuilder: (context, i) => _buildPedidoCard(context, pedidos[i], provider),
|
||||
// Soportar pull-to-refresh en lista de pedidos para sincronización en tiempo real
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
final res = await provider.sincronizarManual();
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(res.mensaje),
|
||||
duration: const Duration(seconds: 3),
|
||||
backgroundColor: res.ok ? const Color(0xFF10B981) : const Color(0xFFF59E0B),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: pedidos.isEmpty
|
||||
? ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: [
|
||||
SizedBox(height: MediaQuery.of(context).size.height * 0.25),
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.receipt_long_outlined, size: 64, color: Colors.grey.shade300),
|
||||
const SizedBox(height: 12),
|
||||
const Text('No hay pedidos', style: TextStyle(color: AppTheme.textSecondary, fontSize: 15)),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'Desliza hacia abajo para actualizar',
|
||||
style: TextStyle(color: Colors.grey.shade400, fontSize: 12),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
: ListView.builder(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 80),
|
||||
itemCount: pedidos.length,
|
||||
itemBuilder: (context, i) => _buildPedidoCard(context, pedidos[i], provider),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -198,16 +227,24 @@ class _PedidosScreenState extends State<PedidosScreen> with SingleTickerProvider
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: estadoColor.withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
pedido.estado.label,
|
||||
style: TextStyle(fontSize: 11, color: estadoColor, fontWeight: FontWeight.w700),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: estadoColor.withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
pedido.estado.label,
|
||||
style: TextStyle(fontSize: 11, color: estadoColor, fontWeight: FontWeight.w700),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
// Badge visual del estado de sincronización hacia API-SIGMA-CLOUD
|
||||
_buildSyncBadge(pedido.syncEstado),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -276,4 +313,69 @@ class _PedidosScreenState extends State<PedidosScreen> with SingleTickerProvider
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Construye el indicador visual de sincronización para cada tarjeta de pedido
|
||||
Widget _buildSyncBadge(String syncEstado) {
|
||||
if (syncEstado == 'SINCRONIZADO') {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF10B981).withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: const [
|
||||
Icon(Icons.cloud_done_rounded, size: 12, color: Color(0xFF10B981)),
|
||||
SizedBox(width: 3),
|
||||
Text(
|
||||
'Nube',
|
||||
style: TextStyle(fontSize: 10, color: Color(0xFF10B981), fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
if (syncEstado == 'ERROR') {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEF4444).withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: const [
|
||||
Icon(Icons.error_outline_rounded, size: 12, color: Color(0xFFEF4444)),
|
||||
SizedBox(width: 3),
|
||||
Text(
|
||||
'Error sync',
|
||||
style: TextStyle(fontSize: 10, color: Color(0xFFEF4444), fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// PENDIENTE
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFF59E0B).withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: const [
|
||||
Icon(Icons.cloud_upload_outlined, size: 12, color: Color(0xFFD97706)),
|
||||
SizedBox(width: 3),
|
||||
Text(
|
||||
'Pendiente',
|
||||
style: TextStyle(fontSize: 10, color: Color(0xFFD97706), fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user