feat: suite de tiendas, sync reactivo, bitácora de errores y alertas whatsapp
This commit is contained in:
@@ -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