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,840 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
import '../../models/cliente.dart';
|
||||
import '../../models/parada_ruta.dart';
|
||||
import '../../widgets/route_map_painter.dart';
|
||||
import '../clientes/cliente_form_screen.dart';
|
||||
import '../pedidos/pedido_form_screen.dart';
|
||||
|
||||
class RutasScreen extends StatefulWidget {
|
||||
const RutasScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<RutasScreen> createState() => _RutasScreenState();
|
||||
}
|
||||
|
||||
class _RutasScreenState extends State<RutasScreen> with SingleTickerProviderStateMixin {
|
||||
late TabController _tabController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 2, vsync: this);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<AppProvider>();
|
||||
final ruta = provider.ruta;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
appBar: AppBar(
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Ruta del Día', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 17)),
|
||||
Text(ruta.zona, style: const TextStyle(fontSize: 12, fontWeight: FontWeight.normal, color: Colors.white70)),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: Chip(
|
||||
label: Text(
|
||||
'${ruta.visitadas}/${ruta.paradas.length}',
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 12),
|
||||
),
|
||||
backgroundColor: Colors.white.withOpacity(0.2),
|
||||
padding: EdgeInsets.zero,
|
||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||
),
|
||||
),
|
||||
],
|
||||
bottom: TabBar(
|
||||
controller: _tabController,
|
||||
indicatorColor: Colors.white,
|
||||
indicatorWeight: 3,
|
||||
tabs: const [
|
||||
Tab(icon: Icon(Icons.map_outlined, size: 18), text: 'Mapa'),
|
||||
Tab(icon: Icon(Icons.list_alt, size: 18), text: 'Paradas'),
|
||||
],
|
||||
),
|
||||
),
|
||||
body: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
_buildMapView(context, provider),
|
||||
_buildListView(context, provider),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => _showAgregarParadaSheet(context, provider),
|
||||
icon: const Icon(Icons.add_location_alt_outlined),
|
||||
label: const Text('Agregar parada'),
|
||||
backgroundColor: AppTheme.accentColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMapView(BuildContext context, AppProvider provider) {
|
||||
final ruta = provider.ruta;
|
||||
return Column(
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(color: Colors.black.withOpacity(0.1), blurRadius: 12, offset: const Offset(0, 4)),
|
||||
],
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: Stack(
|
||||
children: [
|
||||
CustomPaint(
|
||||
painter: RouteMapPainter(ruta.paradas),
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
// Map legend
|
||||
Positioned(
|
||||
top: 12,
|
||||
right: 12,
|
||||
child: _buildLegend(),
|
||||
),
|
||||
// Controls
|
||||
Positioned(
|
||||
bottom: 12,
|
||||
right: 12,
|
||||
child: Column(
|
||||
children: [
|
||||
_mapButton(Icons.add, () {}),
|
||||
const SizedBox(height: 8),
|
||||
_mapButton(Icons.remove, () {}),
|
||||
const SizedBox(height: 8),
|
||||
_mapButton(Icons.my_location, () {}),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 16),
|
||||
itemCount: ruta.paradas.length,
|
||||
itemBuilder: (context, i) => _buildParadaMini(context, ruta.paradas[i], provider),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLegend() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.92),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.1), blurRadius: 4)],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_legendItem(AppTheme.successColor, 'Visitado'),
|
||||
const SizedBox(height: 4),
|
||||
_legendItem(AppTheme.accentColor, 'Actual'),
|
||||
const SizedBox(height: 4),
|
||||
_legendItem(AppTheme.primaryColor.withOpacity(0.5), 'Pendiente'),
|
||||
const SizedBox(height: 4),
|
||||
_legendItem(Colors.blue, 'Mi ubicación'),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _legendItem(Color color, String label) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(width: 10, height: 10, decoration: BoxDecoration(color: color, shape: BoxShape.circle)),
|
||||
const SizedBox(width: 6),
|
||||
Text(label, style: const TextStyle(fontSize: 10, color: AppTheme.textPrimary)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _mapButton(IconData icon, VoidCallback onTap) {
|
||||
return Material(
|
||||
color: Colors.white,
|
||||
elevation: 2,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
onTap: onTap,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Icon(icon, size: 20, color: AppTheme.primaryColor),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildParadaMini(BuildContext context, ParadaRuta parada, AppProvider provider) {
|
||||
final isVisited = parada.estado == EstadoParada.visitado;
|
||||
final color = isVisited ? AppTheme.successColor : AppTheme.primaryColor;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: color.withOpacity(0.3)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 14,
|
||||
backgroundColor: color.withOpacity(0.15),
|
||||
child: Text('${parada.orden}', style: TextStyle(color: color, fontWeight: FontWeight.bold, fontSize: 12)),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
parada.cliente.nombre,
|
||||
style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (isVisited)
|
||||
const Icon(Icons.check_circle, color: AppTheme.successColor, size: 18)
|
||||
else
|
||||
TextButton(
|
||||
style: TextButton.styleFrom(padding: const EdgeInsets.symmetric(horizontal: 8), minimumSize: Size.zero),
|
||||
onPressed: () => _tabController.animateTo(1),
|
||||
child: const Text('Ir', style: TextStyle(fontSize: 12)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildListView(BuildContext context, AppProvider provider) {
|
||||
final ruta = provider.ruta;
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 90),
|
||||
itemCount: ruta.paradas.length,
|
||||
itemBuilder: (context, i) {
|
||||
final parada = ruta.paradas[i];
|
||||
final puedeEliminar = parada.estado == EstadoParada.pendiente;
|
||||
return Dismissible(
|
||||
key: Key(parada.id),
|
||||
direction: puedeEliminar ? DismissDirection.endToStart : DismissDirection.none,
|
||||
background: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.dangerColor,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
Icon(Icons.delete_outline, color: Colors.white, size: 26),
|
||||
SizedBox(height: 4),
|
||||
Text('Quitar', style: TextStyle(color: Colors.white, fontSize: 11)),
|
||||
],
|
||||
),
|
||||
),
|
||||
confirmDismiss: (_) async => await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('Quitar parada'),
|
||||
content: Text('¿Quitar a ${parada.cliente.nombre} de la ruta de hoy?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('Cancelar')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
child: const Text('Quitar', style: TextStyle(color: AppTheme.dangerColor)),
|
||||
),
|
||||
],
|
||||
),
|
||||
) ?? false,
|
||||
onDismissed: (_) {
|
||||
provider.eliminarParada(parada.id);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('${parada.cliente.nombre} quitado de la ruta'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: _buildParadaCard(context, parada, provider),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildParadaCard(BuildContext context, ParadaRuta parada, AppProvider provider) {
|
||||
final isVisited = parada.estado == EstadoParada.visitado;
|
||||
final isSaltado = parada.estado == EstadoParada.saltado;
|
||||
final color = isVisited
|
||||
? AppTheme.successColor
|
||||
: isSaltado
|
||||
? AppTheme.dangerColor
|
||||
: AppTheme.primaryColor;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: color.withOpacity(0.25)),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.04), blurRadius: 6, offset: const Offset(0, 2))],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: 36,
|
||||
height: 36,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.15),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: isVisited
|
||||
? const Icon(Icons.check, color: AppTheme.successColor, size: 20)
|
||||
: Center(
|
||||
child: Text(
|
||||
'${parada.orden}',
|
||||
style: TextStyle(color: color, fontWeight: FontWeight.bold, fontSize: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
parada.cliente.nombre,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 14, color: AppTheme.textPrimary),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
isVisited ? 'Visitado' : isSaltado ? 'Saltado' : 'Pendiente',
|
||||
style: TextStyle(fontSize: 10, color: color, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.location_on_outlined, size: 13, color: AppTheme.textSecondary),
|
||||
const SizedBox(width: 2),
|
||||
Expanded(
|
||||
child: Text(
|
||||
parada.cliente.direccion,
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.access_time, size: 13, color: AppTheme.textSecondary),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
isVisited
|
||||
? 'Visitado a las ${parada.horaVisita}'
|
||||
: 'Estimado: ${parada.horaEstimada}',
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 3),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.category_outlined, size: 13, color: AppTheme.textSecondary),
|
||||
const SizedBox(width: 2),
|
||||
Text(
|
||||
parada.cliente.categoria,
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (!isVisited && !isSaltado)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(14, 0, 14, 14),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
icon: const Icon(Icons.phone, size: 16),
|
||||
label: const Text('Llamar', style: TextStyle(fontSize: 13)),
|
||||
onPressed: () {},
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: OutlinedButton.icon(
|
||||
icon: const Icon(Icons.directions, size: 16),
|
||||
label: const Text('Navegar', style: TextStyle(fontSize: 13)),
|
||||
onPressed: () {},
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.add_shopping_cart, size: 16),
|
||||
label: const Text('Tomar pedido', style: TextStyle(fontSize: 12)),
|
||||
onPressed: () {
|
||||
provider.seleccionarCliente(parada.cliente);
|
||||
provider.marcarParadaVisitada(parada.id);
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const PedidoFormScreen()),
|
||||
);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAgregarParadaSheet(BuildContext context, AppProvider provider) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
||||
),
|
||||
builder: (ctx) => _AgregarParadaSheet(provider: provider),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────
|
||||
// Bottom sheet: seleccionar cliente registrado O crear nuevo
|
||||
// ─────────────────────────────────────────────────────────
|
||||
|
||||
class _AgregarParadaSheet extends StatefulWidget {
|
||||
final AppProvider provider;
|
||||
const _AgregarParadaSheet({Key? key, required this.provider}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<_AgregarParadaSheet> createState() => _AgregarParadaSheetState();
|
||||
}
|
||||
|
||||
class _AgregarParadaSheetState extends State<_AgregarParadaSheet>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late TabController _tab;
|
||||
Cliente? _clienteElegido;
|
||||
final _horaCtrl = TextEditingController();
|
||||
final _searchCtrl = TextEditingController();
|
||||
String _query = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tab = TabController(length: 2, vsync: this);
|
||||
final now = DateTime.now();
|
||||
final h = now.hour.toString().padLeft(2, '0');
|
||||
final m = ((now.minute ~/ 15 + 1) * 15 % 60).toString().padLeft(2, '0');
|
||||
_horaCtrl.text = '$h:$m';
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tab.dispose();
|
||||
_horaCtrl.dispose();
|
||||
_searchCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final todosDisponibles = widget.provider.clientesSinParada
|
||||
.where((c) => _query.isEmpty || c.nombre.toLowerCase().contains(_query.toLowerCase()) ||
|
||||
c.nit.toLowerCase().contains(_query.toLowerCase()))
|
||||
.toList();
|
||||
final hayMas = todosDisponibles.length > 50;
|
||||
final disponibles = hayMas ? todosDisponibles.take(50).toList() : todosDisponibles;
|
||||
|
||||
return DraggableScrollableSheet(
|
||||
expand: false,
|
||||
initialChildSize: 0.75,
|
||||
minChildSize: 0.5,
|
||||
maxChildSize: 0.95,
|
||||
builder: (_, scrollCtrl) => Column(
|
||||
children: [
|
||||
// Handle + header
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 12, 20, 0),
|
||||
child: Column(
|
||||
children: [
|
||||
Center(
|
||||
child: Container(
|
||||
width: 40, height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade300,
|
||||
borderRadius: BorderRadius.circular(2),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.accentColor.withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(Icons.add_location_alt, color: AppTheme.accentColor, size: 22),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Text('Agregar parada',
|
||||
style: TextStyle(fontSize: 17, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
Text('Selecciona un cliente o registra uno nuevo',
|
||||
style: TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
// Tabs
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.bgColor,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tab,
|
||||
indicator: BoxDecoration(
|
||||
color: AppTheme.primaryColor,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: AppTheme.textSecondary,
|
||||
labelStyle: const TextStyle(fontWeight: FontWeight.w600, fontSize: 13),
|
||||
tabs: const [
|
||||
Tab(text: 'Cliente registrado'),
|
||||
Tab(text: 'Cliente nuevo'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tab,
|
||||
children: [
|
||||
// ── TAB 1: cliente registrado ──
|
||||
_buildRegistradosTab(disponibles, scrollCtrl, hayMas),
|
||||
// ── TAB 2: cliente nuevo ──
|
||||
_buildNuevoTab(scrollCtrl),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRegistradosTab(List<Cliente> disponibles, ScrollController scrollCtrl, bool hayMas) {
|
||||
return Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 6),
|
||||
child: TextField(
|
||||
controller: _searchCtrl,
|
||||
onChanged: (v) => setState(() => _query = v),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Buscar cliente...',
|
||||
prefixIcon: const Icon(Icons.search, size: 20),
|
||||
suffixIcon: _query.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear, size: 18),
|
||||
onPressed: () {
|
||||
_searchCtrl.clear();
|
||||
setState(() => _query = '');
|
||||
},
|
||||
)
|
||||
: null,
|
||||
isDense: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (disponibles.isEmpty)
|
||||
Expanded(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.store_outlined, size: 48, color: Colors.grey.shade300),
|
||||
const SizedBox(height: 10),
|
||||
const Text('No hay clientes disponibles',
|
||||
style: TextStyle(color: AppTheme.textSecondary)),
|
||||
const SizedBox(height: 4),
|
||||
const Text('Todos ya están en la ruta o\ncambia el filtro de búsqueda',
|
||||
style: TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
textAlign: TextAlign.center),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
controller: scrollCtrl,
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
itemCount: disponibles.length + (hayMas ? 1 : 0),
|
||||
itemBuilder: (_, i) {
|
||||
if (i == disponibles.length) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||||
child: Text(
|
||||
'Hay más clientes — refina la búsqueda para verlos',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey.shade500),
|
||||
),
|
||||
);
|
||||
}
|
||||
final c = disponibles[i];
|
||||
final selected = _clienteElegido?.id == c.id;
|
||||
return GestureDetector(
|
||||
onTap: () => setState(() => _clienteElegido = c),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 150),
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? AppTheme.primaryColor.withOpacity(0.07) : Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: selected ? AppTheme.primaryColor : const Color(0xFFE2E8F0),
|
||||
width: selected ? 1.5 : 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: selected
|
||||
? AppTheme.primaryColor.withOpacity(0.15)
|
||||
: const Color(0xFFF1F5F9),
|
||||
child: Icon(Icons.store, size: 20,
|
||||
color: selected ? AppTheme.primaryColor : AppTheme.textSecondary),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(c.nombre,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: selected ? AppTheme.primaryColor : AppTheme.textPrimary,
|
||||
)),
|
||||
const SizedBox(height: 2),
|
||||
Text(c.categoria,
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
color: selected ? AppTheme.primaryColor.withOpacity(0.7) : AppTheme.textSecondary,
|
||||
)),
|
||||
Text(c.direccion,
|
||||
style: const TextStyle(fontSize: 11, color: AppTheme.textSecondary),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (selected)
|
||||
const Icon(Icons.check_circle, color: AppTheme.primaryColor, size: 22),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
// Footer
|
||||
if (_clienteElegido != null)
|
||||
_buildFooter(context),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNuevoTab(ScrollController scrollCtrl) {
|
||||
return SingleChildScrollView(
|
||||
controller: scrollCtrl,
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
children: [
|
||||
// Info banner
|
||||
Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryColor.withOpacity(0.06),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppTheme.primaryColor.withOpacity(0.2)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.info_outline, color: AppTheme.primaryColor, size: 18),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'El nuevo cliente quedará registrado en el sistema y se agregará como parada a tu ruta de hoy.',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppTheme.primaryColor.withOpacity(0.85),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.person_add_alt_1_outlined, size: 22),
|
||||
label: const Text('Abrir formulario de registro',
|
||||
style: TextStyle(fontSize: 15, fontWeight: FontWeight.w600)),
|
||||
onPressed: () async {
|
||||
Navigator.pop(context); // cierra el sheet
|
||||
final nuevoCliente = await Navigator.push<Cliente>(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const ClienteFormScreen(),
|
||||
),
|
||||
);
|
||||
// Si se creó con agregarARuta = true, el provider ya lo hizo.
|
||||
// Si no, el cliente quedó registrado pero no en ruta.
|
||||
if (nuevoCliente != null) {
|
||||
// nada extra que hacer — el provider ya notificó
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFooter(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 16, 20),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
border: Border(top: BorderSide(color: Color(0xFFE2E8F0))),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Cliente seleccionado: ${_clienteElegido!.nombre}',
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _horaCtrl,
|
||||
keyboardType: TextInputType.datetime,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Hora estimada',
|
||||
prefixIcon: Icon(Icons.access_time, size: 18),
|
||||
isDense: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: ElevatedButton.icon(
|
||||
icon: const Icon(Icons.add_location_alt_outlined, size: 18),
|
||||
label: const Text('Agregar a ruta'),
|
||||
onPressed: () {
|
||||
final hora = _horaCtrl.text.trim().isEmpty ? '—' : _horaCtrl.text.trim();
|
||||
widget.provider.agregarParadaARuta(_clienteElegido!, hora);
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('✓ ${_clienteElegido!.nombre} agregado a la ruta'),
|
||||
backgroundColor: AppTheme.successColor,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user