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)),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user