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,315 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
import '../../models/pedido.dart';
|
||||
|
||||
class PedidoDetailScreen extends StatelessWidget {
|
||||
final Pedido pedido;
|
||||
|
||||
const PedidoDetailScreen({Key? key, required this.pedido}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.read<AppProvider>();
|
||||
final fmt = NumberFormat.currency(locale: 'es_BO', symbol: 'Bs.', decimalDigits: 2);
|
||||
final estadoColor = AppTheme.estadoColor(pedido.estado.label);
|
||||
final dateStr = DateFormat('d \'de\' MMMM yyyy, HH:mm', 'es').format(pedido.fecha);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
appBar: AppBar(
|
||||
title: Text(pedido.id, style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
actions: [
|
||||
PopupMenuButton<EstadoPedido>(
|
||||
icon: const Icon(Icons.more_vert),
|
||||
itemBuilder: (_) => EstadoPedido.values.map((e) {
|
||||
return PopupMenuItem(
|
||||
value: e,
|
||||
child: Text(e.label),
|
||||
);
|
||||
}).toList(),
|
||||
onSelected: (estado) {
|
||||
provider.cambiarEstadoPedido(pedido.id, estado);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header card
|
||||
_buildHeaderCard(estadoColor, dateStr),
|
||||
const SizedBox(height: 14),
|
||||
// Cliente
|
||||
_buildClienteCard(),
|
||||
const SizedBox(height: 14),
|
||||
// Productos
|
||||
_buildProductosCard(fmt),
|
||||
const SizedBox(height: 14),
|
||||
// Totals
|
||||
_buildTotalesCard(fmt),
|
||||
if (pedido.notas.isNotEmpty) ...[
|
||||
const SizedBox(height: 14),
|
||||
_buildNotasCard(),
|
||||
],
|
||||
if (pedido.firmaBase64 != null) ...[
|
||||
const SizedBox(height: 14),
|
||||
_buildFirmaCard(),
|
||||
],
|
||||
const SizedBox(height: 80),
|
||||
],
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: _buildBottomBar(context, provider, estadoColor, fmt),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildHeaderCard(Color estadoColor, String dateStr) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: estadoColor.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: estadoColor.withOpacity(0.3)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: estadoColor.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(Icons.receipt_long, color: estadoColor, size: 28),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(pedido.id,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 18, color: AppTheme.textPrimary)),
|
||||
const SizedBox(height: 3),
|
||||
Text(dateStr, style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: estadoColor,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Text(
|
||||
pedido.estado.label,
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildClienteCard() {
|
||||
return _sectionCard(
|
||||
title: 'Cliente',
|
||||
icon: Icons.store_outlined,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(pedido.cliente.nombre,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 15, color: AppTheme.textPrimary)),
|
||||
const SizedBox(height: 4),
|
||||
Text(pedido.cliente.razonSocial,
|
||||
style: const TextStyle(fontSize: 13, color: AppTheme.textSecondary)),
|
||||
const SizedBox(height: 8),
|
||||
_infoRow(Icons.location_on_outlined, pedido.cliente.direccion),
|
||||
const SizedBox(height: 4),
|
||||
_infoRow(Icons.phone_outlined, pedido.cliente.telefono),
|
||||
const SizedBox(height: 4),
|
||||
_infoRow(Icons.badge_outlined, 'NIT: ${pedido.cliente.nit}'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProductosCard(NumberFormat fmt) {
|
||||
return _sectionCard(
|
||||
title: 'Productos (${pedido.items.length})',
|
||||
icon: Icons.inventory_2_outlined,
|
||||
child: Column(
|
||||
children: pedido.items.map((item) => Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(item.producto.emoji, style: const TextStyle(fontSize: 22)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(item.producto.nombre,
|
||||
style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500)),
|
||||
Text('${fmt.format(item.precioUnitario)} × ${item.cantidad} ${item.producto.unidad}',
|
||||
style: const TextStyle(fontSize: 11, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
fmt.format(item.subtotal),
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 13, color: AppTheme.textPrimary),
|
||||
),
|
||||
],
|
||||
),
|
||||
)).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTotalesCard(NumberFormat fmt) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryColor,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
_totalRow('Subtotal', fmt.format(pedido.subtotal), Colors.white70, Colors.white),
|
||||
const SizedBox(height: 8),
|
||||
_totalRow('Descuento', '0%', Colors.white70, Colors.white),
|
||||
const Divider(color: Colors.white24, height: 20),
|
||||
_totalRow('TOTAL', fmt.format(pedido.total), Colors.white, Colors.white,
|
||||
isTotal: true),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _totalRow(String label, String valor, Color labelColor, Color valueColor, {bool isTotal = false}) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(label, style: TextStyle(color: labelColor, fontSize: isTotal ? 16 : 13, fontWeight: isTotal ? FontWeight.bold : FontWeight.normal)),
|
||||
Text(valor, style: TextStyle(color: valueColor, fontSize: isTotal ? 20 : 13, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNotasCard() {
|
||||
return _sectionCard(
|
||||
title: 'Notas',
|
||||
icon: Icons.notes_outlined,
|
||||
child: Text(pedido.notas, style: const TextStyle(fontSize: 13, color: AppTheme.textPrimary)),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFirmaCard() {
|
||||
return _sectionCard(
|
||||
title: 'Firma del cliente',
|
||||
icon: Icons.draw_outlined,
|
||||
child: Container(
|
||||
height: 100,
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.bgColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
Icon(Icons.check_circle, color: AppTheme.successColor, size: 20),
|
||||
SizedBox(width: 8),
|
||||
Text('Pedido firmado', style: TextStyle(color: AppTheme.successColor, fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottomBar(BuildContext context, AppProvider provider, Color estadoColor, NumberFormat fmt) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 24),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 8, offset: Offset(0, -2))],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
icon: const Icon(Icons.print_outlined),
|
||||
label: const Text('Imprimir'),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
icon: const Icon(Icons.share_outlined),
|
||||
label: const Text('Compartir'),
|
||||
onPressed: () {},
|
||||
),
|
||||
),
|
||||
if (pedido.estado == EstadoPedido.confirmado) ...[
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.local_shipping_outlined, size: 18),
|
||||
label: const Text('Marcar entregado', style: TextStyle(fontSize: 12)),
|
||||
onPressed: () {
|
||||
provider.cambiarEstadoPedido(pedido.id, EstadoPedido.entregado);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _sectionCard({required String title, required IconData icon, required Widget child}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.04), blurRadius: 6)],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(icon, size: 17, color: AppTheme.primaryColor),
|
||||
const SizedBox(width: 6),
|
||||
Text(title, style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
],
|
||||
),
|
||||
const Divider(height: 16),
|
||||
child,
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _infoRow(IconData icon, String text) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 14, color: AppTheme.textSecondary),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(text, style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,515 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
import '../../models/cliente.dart';
|
||||
import '../firma/firma_screen.dart';
|
||||
import '../scanner/scanner_helper.dart';
|
||||
import '../clientes/cliente_selector_screen.dart';
|
||||
|
||||
class PedidoFormScreen extends StatefulWidget {
|
||||
const PedidoFormScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<PedidoFormScreen> createState() => _PedidoFormScreenState();
|
||||
}
|
||||
|
||||
class _PedidoFormScreenState extends State<PedidoFormScreen> {
|
||||
final _notasCtrl = TextEditingController();
|
||||
final _searchCtrl = TextEditingController();
|
||||
String _productoQuery = '';
|
||||
bool _showSearch = false;
|
||||
|
||||
final _fmt = NumberFormat.currency(locale: 'es_BO', symbol: 'Bs.', decimalDigits: 2);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final provider = context.read<AppProvider>();
|
||||
_notasCtrl.text = provider.notasPedido;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_notasCtrl.dispose();
|
||||
_searchCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<AppProvider>();
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
appBar: AppBar(
|
||||
title: const Text('Nuevo Pedido', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_outline),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
title: const Text('Cancelar pedido'),
|
||||
content: const Text('¿Descartar el pedido en curso?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('No')),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
provider.limpiarCarrito();
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context);
|
||||
},
|
||||
child: const Text('Sí, descartar', style: TextStyle(color: AppTheme.dangerColor)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildClienteSection(context, provider),
|
||||
const SizedBox(height: 16),
|
||||
_buildProductoSearch(context, provider),
|
||||
if (_showSearch) _buildSearchResults(context, provider),
|
||||
const SizedBox(height: 16),
|
||||
_buildCarrito(context, provider),
|
||||
const SizedBox(height: 16),
|
||||
_buildNotasSection(context, provider),
|
||||
const SizedBox(height: 80),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBottomBar(context, provider),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildClienteSection(BuildContext context, AppProvider provider) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Cliente', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
const SizedBox(height: 8),
|
||||
if (provider.clienteSeleccionado != null)
|
||||
_buildClienteCard(provider.clienteSeleccionado!)
|
||||
else
|
||||
_buildClienteSelector(context, provider),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildClienteCard(Cliente cliente) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppTheme.primaryColor.withOpacity(0.3)),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.04), blurRadius: 6)],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(Icons.store, color: AppTheme.primaryColor, size: 24),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(cliente.nombre, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14)),
|
||||
Text(cliente.direccion, style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary), maxLines: 1, overflow: TextOverflow.ellipsis),
|
||||
Text('NIT: ${cliente.nit}', style: const TextStyle(fontSize: 11, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.check_circle, color: AppTheme.successColor, size: 22),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildClienteSelector(BuildContext context, AppProvider provider) {
|
||||
return Material(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
elevation: 1,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
onTap: () => _abrirSelectorCliente(context, provider),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: const Color(0xFFCBD5E1)),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.store_outlined, color: AppTheme.textSecondary),
|
||||
SizedBox(width: 12),
|
||||
Text('Seleccionar cliente...', style: TextStyle(color: AppTheme.textSecondary)),
|
||||
Spacer(),
|
||||
Icon(Icons.arrow_drop_down, color: AppTheme.textSecondary),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _abrirSelectorCliente(BuildContext context, AppProvider provider) async {
|
||||
final cliente = await Navigator.push<Cliente>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => ClienteSelectorScreen(clientes: provider.clientes),
|
||||
),
|
||||
);
|
||||
if (cliente != null) provider.seleccionarCliente(cliente);
|
||||
}
|
||||
|
||||
Widget _buildProductoSearch(BuildContext context, AppProvider provider) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Agregar productos', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _searchCtrl,
|
||||
onTap: () => setState(() => _showSearch = true),
|
||||
onChanged: (v) => setState(() => _productoQuery = v),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Buscar producto o SKU...',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: _showSearch
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
_searchCtrl.clear();
|
||||
setState(() {
|
||||
_productoQuery = '';
|
||||
_showSearch = false;
|
||||
});
|
||||
},
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Material(
|
||||
color: AppTheme.primaryColor,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
onTap: () async {
|
||||
final resultado = await abrirScanner(context, titulo: 'Escanear producto');
|
||||
if (resultado == null || !mounted) return;
|
||||
final coincidencias = provider.productos.where(
|
||||
(p) => p.sku.toLowerCase() == resultado.toLowerCase() ||
|
||||
p.nombre.toLowerCase().contains(resultado.toLowerCase()),
|
||||
).toList();
|
||||
final producto = coincidencias.isEmpty ? null : coincidencias.first;
|
||||
if (producto != null) {
|
||||
provider.agregarAlCarrito(producto);
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text('${producto.nombre} agregado al pedido'),
|
||||
backgroundColor: AppTheme.successColor,
|
||||
duration: const Duration(seconds: 2),
|
||||
));
|
||||
} else {
|
||||
// Si no coincide exacto, poner en el campo de búsqueda
|
||||
_searchCtrl.text = resultado;
|
||||
setState(() {
|
||||
_productoQuery = resultado;
|
||||
_showSearch = true;
|
||||
});
|
||||
}
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.all(14),
|
||||
child: Icon(Icons.qr_code_scanner, color: Colors.white, size: 22),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSearchResults(BuildContext context, AppProvider provider) {
|
||||
final results = provider.productos.where((p) {
|
||||
if (_productoQuery.isEmpty) return true;
|
||||
return p.nombre.toLowerCase().contains(_productoQuery.toLowerCase()) ||
|
||||
p.sku.toLowerCase().contains(_productoQuery.toLowerCase());
|
||||
}).take(6).toList();
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(top: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.08), blurRadius: 8)],
|
||||
),
|
||||
child: Column(
|
||||
children: results.map((p) {
|
||||
final enCarrito = provider.carrito.where((i) => i.producto.id == p.id);
|
||||
final qty = enCarrito.isNotEmpty ? enCarrito.first.cantidad : 0;
|
||||
return ListTile(
|
||||
dense: true,
|
||||
leading: Text(p.emoji, style: const TextStyle(fontSize: 24)),
|
||||
title: Text(p.nombre, style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500)),
|
||||
subtitle: Text(_fmt.format(p.precio), style: const TextStyle(fontSize: 12, color: AppTheme.primaryColor)),
|
||||
trailing: qty == 0
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.add_circle, color: AppTheme.primaryColor),
|
||||
onPressed: () => provider.agregarAlCarrito(p),
|
||||
)
|
||||
: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.remove_circle_outline, size: 20),
|
||||
onPressed: () => provider.actualizarCantidad(p.id, qty - 1),
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
child: Text('$qty', style: const TextStyle(fontWeight: FontWeight.bold)),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add_circle, size: 20, color: AppTheme.primaryColor),
|
||||
onPressed: () => provider.agregarAlCarrito(p),
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCarrito(BuildContext context, AppProvider provider) {
|
||||
if (provider.carrito.isEmpty) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 32),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: const Color(0xFFE2E8F0), style: BorderStyle.solid),
|
||||
),
|
||||
child: Center(
|
||||
child: Column(
|
||||
children: const [
|
||||
Icon(Icons.shopping_cart_outlined, size: 40, color: AppTheme.textSecondary),
|
||||
SizedBox(height: 8),
|
||||
Text('Carrito vacío', style: TextStyle(color: AppTheme.textSecondary)),
|
||||
Text('Busca y agrega productos arriba', style: TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Carrito (${provider.carrito.length} productos)',
|
||||
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
TextButton.icon(
|
||||
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),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.04), blurRadius: 6)],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
...provider.carrito.map((item) => Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(bottom: BorderSide(color: Colors.grey.shade100)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(item.producto.emoji, style: const TextStyle(fontSize: 20)),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(item.producto.nombre, style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500)),
|
||||
Text('${_fmt.format(item.precioUnitario)} x ${item.cantidad}',
|
||||
style: const TextStyle(fontSize: 11, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_counterBtn(Icons.remove, () => provider.actualizarCantidad(item.producto.id, item.cantidad - 1)),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: Text('${item.cantidad}', style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14)),
|
||||
),
|
||||
_counterBtn(Icons.add, () => provider.agregarAlCarrito(item.producto)),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_fmt.format(item.subtotal),
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 13, color: AppTheme.primaryColor),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.close, size: 16, color: AppTheme.textSecondary),
|
||||
padding: EdgeInsets.zero,
|
||||
constraints: const BoxConstraints(),
|
||||
onPressed: () => provider.quitarDelCarrito(item.producto.id),
|
||||
),
|
||||
],
|
||||
),
|
||||
)).toList(),
|
||||
// Totals
|
||||
Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryColor.withOpacity(0.04),
|
||||
borderRadius: const BorderRadius.vertical(bottom: Radius.circular(12)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('${provider.cantidadCarrito} unidades', style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
const Text('Total a pagar:', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w500)),
|
||||
],
|
||||
),
|
||||
Text(
|
||||
_fmt.format(provider.totalCarrito),
|
||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: AppTheme.primaryColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNotasSection(BuildContext context, AppProvider provider) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Notas del pedido', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
controller: _notasCtrl,
|
||||
onChanged: provider.setNotasPedido,
|
||||
maxLines: 3,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Instrucciones especiales, horario de entrega...',
|
||||
alignLabelWithHint: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottomBar(BuildContext context, AppProvider provider) {
|
||||
final canConfirm = provider.clienteSeleccionado != null && provider.carrito.isNotEmpty;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 24),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.08), blurRadius: 12, offset: const Offset(0, -4))],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('Total del pedido:', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500)),
|
||||
Text(
|
||||
_fmt.format(provider.totalCarrito),
|
||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: AppTheme.primaryColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.draw_outlined, size: 22),
|
||||
label: const Text('Confirmar y Firmar', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
onPressed: canConfirm
|
||||
? () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const FirmaScreen()),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _counterBtn(IconData icon, VoidCallback onTap) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(3),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Icon(icon, size: 16, color: AppTheme.primaryColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,279 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
import '../../models/pedido.dart';
|
||||
import 'pedido_form_screen.dart';
|
||||
import 'pedido_detail_screen.dart';
|
||||
|
||||
class PedidosScreen extends StatefulWidget {
|
||||
const PedidosScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<PedidosScreen> createState() => _PedidosScreenState();
|
||||
}
|
||||
|
||||
class _PedidosScreenState extends State<PedidosScreen> with SingleTickerProviderStateMixin {
|
||||
late TabController _tab;
|
||||
final _fmt = NumberFormat.currency(locale: 'es_BO', symbol: 'Bs.', decimalDigits: 2);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tab = TabController(length: 4, vsync: this);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tab.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<AppProvider>();
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
appBar: AppBar(
|
||||
title: const Text('Pedidos', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
actions: [
|
||||
IconButton(icon: const Icon(Icons.search), onPressed: () {}),
|
||||
IconButton(icon: const Icon(Icons.filter_list), onPressed: () {}),
|
||||
],
|
||||
bottom: TabBar(
|
||||
controller: _tab,
|
||||
indicatorColor: Colors.white,
|
||||
indicatorWeight: 3,
|
||||
isScrollable: true,
|
||||
tabs: _buildTabs(provider),
|
||||
),
|
||||
),
|
||||
body: TabBarView(
|
||||
controller: _tab,
|
||||
children: [
|
||||
_buildList(context, provider.pedidos, provider),
|
||||
_buildList(
|
||||
context,
|
||||
provider.pedidos.where((p) => p.estado == EstadoPedido.pendiente).toList(),
|
||||
provider),
|
||||
_buildList(
|
||||
context,
|
||||
provider.pedidos.where((p) => p.estado == EstadoPedido.confirmado).toList(),
|
||||
provider),
|
||||
_buildList(
|
||||
context,
|
||||
provider.pedidos.where((p) => p.estado == EstadoPedido.entregado).toList(),
|
||||
provider),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const PedidoFormScreen()),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Nuevo pedido'),
|
||||
backgroundColor: AppTheme.primaryColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Widget> _buildTabs(AppProvider provider) {
|
||||
final todos = provider.pedidos.length;
|
||||
final pend = provider.pedidos.where((p) => p.estado == EstadoPedido.pendiente).length;
|
||||
final conf = provider.pedidos.where((p) => p.estado == EstadoPedido.confirmado).length;
|
||||
final entr = provider.pedidos.where((p) => p.estado == EstadoPedido.entregado).length;
|
||||
|
||||
return [
|
||||
Tab(text: 'Todos ($todos)'),
|
||||
Tab(text: 'Pendiente ($pend)'),
|
||||
Tab(text: 'Confirmado ($conf)'),
|
||||
Tab(text: 'Entregado ($entr)'),
|
||||
];
|
||||
}
|
||||
|
||||
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),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPedidoCard(BuildContext context, Pedido pedido, AppProvider provider) {
|
||||
final estadoColor = AppTheme.estadoColor(pedido.estado.label);
|
||||
final timeStr = DateFormat('d MMM, HH:mm', 'es').format(pedido.fecha);
|
||||
|
||||
return Dismissible(
|
||||
key: Key(pedido.id),
|
||||
direction: DismissDirection.endToStart,
|
||||
background: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.dangerColor,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
Icon(Icons.delete_outline, color: Colors.white, size: 28),
|
||||
SizedBox(height: 4),
|
||||
Text('Eliminar', style: TextStyle(color: Colors.white, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
),
|
||||
confirmDismiss: (dir) async {
|
||||
return await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Eliminar pedido'),
|
||||
content: Text('¿Eliminar el pedido ${pedido.id}?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('Cancelar')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
child: const Text('Eliminar', style: TextStyle(color: AppTheme.dangerColor)),
|
||||
),
|
||||
],
|
||||
),
|
||||
) ?? false;
|
||||
},
|
||||
onDismissed: (_) => provider.eliminarPedido(pedido.id),
|
||||
child: GestureDetector(
|
||||
onTap: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => PedidoDetailScreen(pedido: pedido)),
|
||||
),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: estadoColor.withOpacity(0.2)),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.04), blurRadius: 6, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: estadoColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(Icons.receipt_outlined, color: estadoColor, size: 20),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
pedido.id,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: AppTheme.textPrimary),
|
||||
),
|
||||
Text(timeStr, style: const TextStyle(fontSize: 11, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
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 Divider(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.store_outlined, size: 14, color: AppTheme.textSecondary),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
pedido.cliente.nombre,
|
||||
style: const TextStyle(fontSize: 13, color: AppTheme.textPrimary, fontWeight: FontWeight.w500),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.inventory_2_outlined, size: 14, color: AppTheme.textSecondary),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'${pedido.totalItems} productos · ${pedido.items.length} líneas',
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
_fmt.format(pedido.total),
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.primaryColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (pedido.notas.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.bgColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.notes, size: 13, color: AppTheme.textSecondary),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
pedido.notas,
|
||||
style: const TextStyle(fontSize: 11, color: AppTheme.textSecondary),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user