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,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