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,317 @@
|
||||
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/producto.dart';
|
||||
import '../scanner/scanner_helper.dart';
|
||||
|
||||
class CatalogoScreen extends StatefulWidget {
|
||||
const CatalogoScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<CatalogoScreen> createState() => _CatalogoScreenState();
|
||||
}
|
||||
|
||||
class _CatalogoScreenState extends State<CatalogoScreen> {
|
||||
final _searchCtrl = TextEditingController();
|
||||
String _categoriaSeleccionada = 'Todos';
|
||||
String _query = '';
|
||||
|
||||
final _categorias = ['Todos', 'Redes & Conectividad', 'Telefonía & Móviles', 'Cómputo & Periféricos', 'Seguridad & Vigilancia', 'Servicios'];
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<AppProvider>();
|
||||
final fmt = NumberFormat.currency(locale: 'es_BO', symbol: 'Bs.', decimalDigits: 2);
|
||||
|
||||
final filtrados = provider.productos.where((p) {
|
||||
final matchCat = _categoriaSeleccionada == 'Todos' || p.categoria == _categoriaSeleccionada;
|
||||
final matchQuery = _query.isEmpty ||
|
||||
p.nombre.toLowerCase().contains(_query.toLowerCase()) ||
|
||||
p.sku.toLowerCase().contains(_query.toLowerCase());
|
||||
return matchCat && matchQuery;
|
||||
}).toList();
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
appBar: AppBar(
|
||||
title: const Text('Catálogo de Productos', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 12),
|
||||
child: Stack(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.shopping_cart_outlined),
|
||||
onPressed: () {},
|
||||
),
|
||||
if (provider.cantidadCarrito > 0)
|
||||
Positioned(
|
||||
right: 6,
|
||||
top: 6,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: const BoxDecoration(color: Colors.red, shape: BoxShape.circle),
|
||||
child: Text(
|
||||
'${provider.cantidadCarrito}',
|
||||
style: const TextStyle(color: Colors.white, fontSize: 9, fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Container(
|
||||
color: AppTheme.primaryColor,
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 12),
|
||||
child: TextField(
|
||||
controller: _searchCtrl,
|
||||
onChanged: (v) => setState(() => _query = v),
|
||||
style: const TextStyle(color: Colors.white),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Buscar producto o SKU...',
|
||||
hintStyle: const TextStyle(color: Colors.white60),
|
||||
prefixIcon: const Icon(Icons.search, color: Colors.white70),
|
||||
suffixIcon: _query.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear, color: Colors.white70),
|
||||
onPressed: () {
|
||||
_searchCtrl.clear();
|
||||
setState(() => _query = '');
|
||||
},
|
||||
)
|
||||
: IconButton(
|
||||
tooltip: 'Escanear código',
|
||||
icon: const Icon(Icons.qr_code_scanner, color: Colors.white70),
|
||||
onPressed: () async {
|
||||
final resultado = await abrirScanner(context, titulo: 'Buscar producto');
|
||||
if (resultado != null && mounted) {
|
||||
_searchCtrl.text = resultado;
|
||||
setState(() => _query = resultado);
|
||||
}
|
||||
},
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Colors.white.withOpacity(0.15),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide.none,
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: Colors.white54),
|
||||
),
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Categories
|
||||
Container(
|
||||
height: 44,
|
||||
color: Colors.white,
|
||||
child: ListView.builder(
|
||||
scrollDirection: Axis.horizontal,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||
itemCount: _categorias.length,
|
||||
itemBuilder: (context, i) {
|
||||
final cat = _categorias[i];
|
||||
final selected = cat == _categoriaSeleccionada;
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(right: 8),
|
||||
child: FilterChip(
|
||||
label: Text(cat),
|
||||
selected: selected,
|
||||
onSelected: (_) => setState(() => _categoriaSeleccionada = cat),
|
||||
selectedColor: AppTheme.primaryColor,
|
||||
checkmarkColor: Colors.white,
|
||||
labelStyle: TextStyle(
|
||||
color: selected ? Colors.white : AppTheme.textPrimary,
|
||||
fontSize: 12,
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.normal,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
// Count
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
'${filtrados.length} productos',
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Grid
|
||||
Expanded(
|
||||
child: GridView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 80),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 2,
|
||||
childAspectRatio: 0.72,
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
),
|
||||
itemCount: filtrados.length,
|
||||
itemBuilder: (context, i) => _buildProductCard(context, filtrados[i], provider, fmt),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProductCard(BuildContext context, Producto producto, AppProvider provider, NumberFormat fmt) {
|
||||
final enCarrito = provider.carrito.where((i) => i.producto.id == producto.id);
|
||||
final cantidadEnCarrito = enCarrito.isNotEmpty ? enCarrito.first.cantidad : 0;
|
||||
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.06), blurRadius: 8, offset: const Offset(0, 3))],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Product image placeholder
|
||||
Container(
|
||||
height: 110,
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryColor.withOpacity(0.06),
|
||||
borderRadius: const BorderRadius.vertical(top: Radius.circular(14)),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Center(
|
||||
child: Text(producto.emoji, style: const TextStyle(fontSize: 52)),
|
||||
),
|
||||
if (producto.stock < 20)
|
||||
Positioned(
|
||||
top: 8,
|
||||
left: 8,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.dangerColor,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: const Text('Bajo stock', style: TextStyle(color: Colors.white, fontSize: 8, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
producto.nombre,
|
||||
style: const TextStyle(fontWeight: FontWeight.w600, fontSize: 12, color: AppTheme.textPrimary),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'SKU: ${producto.sku}',
|
||||
style: const TextStyle(fontSize: 10, color: AppTheme.textSecondary),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
fmt.format(producto.precio),
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 13, color: AppTheme.primaryColor),
|
||||
),
|
||||
Text(
|
||||
'Mayor: ${fmt.format(producto.precioMayorista)}',
|
||||
style: const TextStyle(fontSize: 9, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
cantidadEnCarrito == 0
|
||||
? SizedBox(
|
||||
width: double.infinity,
|
||||
height: 32,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => provider.agregarAlCarrito(producto),
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: EdgeInsets.zero,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
Icon(Icons.add, size: 16),
|
||||
SizedBox(width: 4),
|
||||
Text('Agregar', style: TextStyle(fontSize: 12)),
|
||||
],
|
||||
),
|
||||
),
|
||||
)
|
||||
: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_counterBtn(Icons.remove, () => provider.actualizarCantidad(producto.id, cantidadEnCarrito - 1)),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
'$cantidadEnCarrito',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, color: AppTheme.primaryColor),
|
||||
),
|
||||
),
|
||||
_counterBtn(Icons.add, () => provider.agregarAlCarrito(producto)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _counterBtn(IconData icon, VoidCallback onTap) {
|
||||
return InkWell(
|
||||
onTap: onTap,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryColor,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Icon(icon, size: 16, color: Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,369 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
import '../../models/cliente.dart';
|
||||
|
||||
class ClienteFormScreen extends StatefulWidget {
|
||||
final Cliente? clienteEditar;
|
||||
|
||||
const ClienteFormScreen({Key? key, this.clienteEditar}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ClienteFormScreen> createState() => _ClienteFormScreenState();
|
||||
}
|
||||
|
||||
class _ClienteFormScreenState extends State<ClienteFormScreen> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
final _nombreCtrl = TextEditingController();
|
||||
final _razonSocialCtrl = TextEditingController();
|
||||
final _nitCtrl = TextEditingController();
|
||||
final _telefonoCtrl = TextEditingController();
|
||||
final _direccionCtrl = TextEditingController();
|
||||
final _referenciaCtrl = TextEditingController();
|
||||
|
||||
String _categoria = 'Minorista';
|
||||
bool _agregarARuta = true;
|
||||
bool _guardando = false;
|
||||
|
||||
final _categorias = ['Minorista', 'Mayorista', 'Distribuidor', 'Empresa', 'Institución', 'Gobierno'];
|
||||
|
||||
bool get esEdicion => widget.clienteEditar != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
if (esEdicion) {
|
||||
final c = widget.clienteEditar!;
|
||||
_nombreCtrl.text = c.nombre;
|
||||
_razonSocialCtrl.text = c.razonSocial;
|
||||
_nitCtrl.text = c.nit;
|
||||
_telefonoCtrl.text = c.telefono;
|
||||
_direccionCtrl.text = c.direccion;
|
||||
_categoria = c.categoria;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_nombreCtrl.dispose();
|
||||
_razonSocialCtrl.dispose();
|
||||
_nitCtrl.dispose();
|
||||
_telefonoCtrl.dispose();
|
||||
_direccionCtrl.dispose();
|
||||
_referenciaCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
esEdicion ? 'Editar cliente' : 'Nuevo punto de distribución',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
body: Form(
|
||||
key: _formKey,
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
_buildSectionHeader(Icons.store, 'Datos del negocio'),
|
||||
const SizedBox(height: 12),
|
||||
_buildCard(children: [
|
||||
_buildField(
|
||||
controller: _nombreCtrl,
|
||||
label: 'Nombre comercial *',
|
||||
hint: 'Ej. Tienda Don Pepe',
|
||||
icon: Icons.storefront_outlined,
|
||||
validator: _required,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildField(
|
||||
controller: _razonSocialCtrl,
|
||||
label: 'Razón social',
|
||||
hint: 'Ej. José García S.R.L.',
|
||||
icon: Icons.business_outlined,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildField(
|
||||
controller: _nitCtrl,
|
||||
label: 'NIT / CI',
|
||||
hint: 'Número de identificación tributaria',
|
||||
icon: Icons.badge_outlined,
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
]),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
_buildSectionHeader(Icons.category_outlined, 'Categoría del cliente'),
|
||||
const SizedBox(height: 12),
|
||||
_buildCard(children: [
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: _categorias.map((cat) {
|
||||
final selected = _categoria == cat;
|
||||
return GestureDetector(
|
||||
onTap: () => setState(() => _categoria = cat),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 180),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: selected ? AppTheme.primaryColor : const Color(0xFFF1F5F9),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: selected ? AppTheme.primaryColor : const Color(0xFFCBD5E1),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
_iconForCategoria(cat),
|
||||
size: 16,
|
||||
color: selected ? Colors.white : AppTheme.textSecondary,
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
cat,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: selected ? FontWeight.w600 : FontWeight.normal,
|
||||
color: selected ? Colors.white : AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
]),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
_buildSectionHeader(Icons.contact_phone_outlined, 'Contacto'),
|
||||
const SizedBox(height: 12),
|
||||
_buildCard(children: [
|
||||
_buildField(
|
||||
controller: _telefonoCtrl,
|
||||
label: 'Teléfono / Celular *',
|
||||
hint: 'Ej. +591 70000000',
|
||||
icon: Icons.phone_outlined,
|
||||
keyboardType: TextInputType.phone,
|
||||
validator: _required,
|
||||
),
|
||||
]),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
_buildSectionHeader(Icons.location_on_outlined, 'Ubicación'),
|
||||
const SizedBox(height: 12),
|
||||
_buildCard(children: [
|
||||
_buildField(
|
||||
controller: _direccionCtrl,
|
||||
label: 'Dirección *',
|
||||
hint: 'Calle, número, zona o barrio',
|
||||
icon: Icons.home_outlined,
|
||||
validator: _required,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
_buildField(
|
||||
controller: _referenciaCtrl,
|
||||
label: 'Referencia',
|
||||
hint: 'Ej. Frente al parque, edificio azul...',
|
||||
icon: Icons.signpost_outlined,
|
||||
maxLines: 2,
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
// Simulated GPS pin button
|
||||
OutlinedButton.icon(
|
||||
icon: const Icon(Icons.my_location, size: 18),
|
||||
label: const Text('Usar mi ubicación actual'),
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('GPS: función disponible con permisos de ubicación'),
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
},
|
||||
style: OutlinedButton.styleFrom(
|
||||
minimumSize: const Size(double.infinity, 44),
|
||||
),
|
||||
),
|
||||
]),
|
||||
|
||||
if (!esEdicion) ...[
|
||||
const SizedBox(height: 20),
|
||||
_buildSectionHeader(Icons.route_outlined, 'Ruta del día'),
|
||||
const SizedBox(height: 12),
|
||||
_buildCard(children: [
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: const Text(
|
||||
'Agregar a la ruta de hoy',
|
||||
style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
|
||||
),
|
||||
subtitle: const Text(
|
||||
'El punto se añade como parada pendiente',
|
||||
style: TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
value: _agregarARuta,
|
||||
onChanged: (v) => setState(() => _agregarARuta = v),
|
||||
activeColor: AppTheme.primaryColor,
|
||||
),
|
||||
]),
|
||||
],
|
||||
|
||||
const SizedBox(height: 28),
|
||||
_buildSubmitButton(context),
|
||||
const SizedBox(height: 40),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader(IconData icon, String titulo) {
|
||||
return Row(
|
||||
children: [
|
||||
Icon(icon, size: 16, color: AppTheme.primaryColor),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
titulo,
|
||||
style: const TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppTheme.primaryColor,
|
||||
letterSpacing: 0.3,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCard({required List<Widget> children}) {
|
||||
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: 8, offset: const Offset(0, 2)),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: children,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildField({
|
||||
required TextEditingController controller,
|
||||
required String label,
|
||||
required String hint,
|
||||
required IconData icon,
|
||||
TextInputType keyboardType = TextInputType.text,
|
||||
int maxLines = 1,
|
||||
String? Function(String?)? validator,
|
||||
}) {
|
||||
return TextFormField(
|
||||
controller: controller,
|
||||
keyboardType: keyboardType,
|
||||
maxLines: maxLines,
|
||||
validator: validator,
|
||||
decoration: InputDecoration(
|
||||
labelText: label,
|
||||
hintText: hint,
|
||||
prefixIcon: Icon(icon, size: 20),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSubmitButton(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: ElevatedButton.icon(
|
||||
icon: _guardando
|
||||
? const SizedBox(
|
||||
width: 20,
|
||||
height: 20,
|
||||
child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2.5),
|
||||
)
|
||||
: Icon(esEdicion ? Icons.save_outlined : Icons.add_location_alt_outlined, size: 22),
|
||||
label: Text(
|
||||
_guardando
|
||||
? 'Guardando...'
|
||||
: esEdicion
|
||||
? 'Guardar cambios'
|
||||
: 'Registrar punto de distribución',
|
||||
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600),
|
||||
),
|
||||
onPressed: _guardando ? null : () => _submit(context),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _submit(BuildContext context) async {
|
||||
if (!_formKey.currentState!.validate()) return;
|
||||
|
||||
setState(() => _guardando = true);
|
||||
await Future.delayed(const Duration(milliseconds: 600));
|
||||
|
||||
final provider = context.read<AppProvider>();
|
||||
|
||||
final cliente = Cliente(
|
||||
id: 'c_${DateTime.now().millisecondsSinceEpoch}',
|
||||
nombre: _nombreCtrl.text.trim(),
|
||||
razonSocial: _razonSocialCtrl.text.trim().isEmpty
|
||||
? _nombreCtrl.text.trim()
|
||||
: _razonSocialCtrl.text.trim(),
|
||||
nit: _nitCtrl.text.trim().isEmpty ? '—' : _nitCtrl.text.trim(),
|
||||
telefono: _telefonoCtrl.text.trim(),
|
||||
direccion: _direccionCtrl.text.trim(),
|
||||
categoria: _categoria,
|
||||
lat: -16.5,
|
||||
lng: -68.1,
|
||||
);
|
||||
|
||||
if (esEdicion) {
|
||||
provider.actualizarCliente(cliente);
|
||||
} else {
|
||||
provider.agregarCliente(cliente, agregarARuta: _agregarARuta);
|
||||
}
|
||||
|
||||
if (mounted) {
|
||||
Navigator.pop(context, cliente);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
esEdicion
|
||||
? '✓ ${cliente.nombre} actualizado'
|
||||
: '✓ ${cliente.nombre} registrado${_agregarARuta ? ' y agregado a la ruta' : ''}',
|
||||
),
|
||||
backgroundColor: AppTheme.successColor,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String? _required(String? v) =>
|
||||
(v == null || v.trim().isEmpty) ? 'Este campo es obligatorio' : null;
|
||||
|
||||
IconData _iconForCategoria(String cat) {
|
||||
switch (cat) {
|
||||
case 'Mayorista': return Icons.warehouse_outlined;
|
||||
case 'Distribuidor': return Icons.local_shipping_outlined;
|
||||
case 'Empresa': return Icons.business_outlined;
|
||||
case 'Institución': return Icons.school_outlined;
|
||||
case 'Gobierno': return Icons.account_balance_outlined;
|
||||
default: return Icons.store_outlined;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,299 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../../models/cliente.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
|
||||
const int _kMaxResultados = 50;
|
||||
|
||||
/// Pantalla de búsqueda de clientes. Retorna el [Cliente] seleccionado o null.
|
||||
///
|
||||
/// Uso:
|
||||
/// ```dart
|
||||
/// final cliente = await Navigator.push<Cliente>(
|
||||
/// context,
|
||||
/// MaterialPageRoute(builder: (_) => ClienteSelectorScreen(clientes: provider.clientes)),
|
||||
/// );
|
||||
/// ```
|
||||
class ClienteSelectorScreen extends StatefulWidget {
|
||||
final List<Cliente> clientes;
|
||||
final String titulo;
|
||||
|
||||
const ClienteSelectorScreen({
|
||||
Key? key,
|
||||
required this.clientes,
|
||||
this.titulo = 'Seleccionar cliente',
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ClienteSelectorScreen> createState() => _ClienteSelectorScreenState();
|
||||
}
|
||||
|
||||
class _ClienteSelectorScreenState extends State<ClienteSelectorScreen> {
|
||||
final _searchCtrl = TextEditingController();
|
||||
final _focusNode = FocusNode();
|
||||
Timer? _debounce;
|
||||
|
||||
String _query = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// Autofocus al abrir
|
||||
WidgetsBinding.instance!.addPostFrameCallback((_) => _focusNode.requestFocus());
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_debounce?.cancel();
|
||||
_searchCtrl.dispose();
|
||||
_focusNode.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onSearchChanged(String value) {
|
||||
_debounce?.cancel();
|
||||
_debounce = Timer(const Duration(milliseconds: 250), () {
|
||||
setState(() => _query = value.trim());
|
||||
});
|
||||
}
|
||||
|
||||
List<Cliente> get _filtrados {
|
||||
if (_query.isEmpty) return const [];
|
||||
final q = _query.toLowerCase();
|
||||
return widget.clientes.where((c) {
|
||||
return c.nombre.toLowerCase().contains(q) ||
|
||||
c.nit.toLowerCase().contains(q) ||
|
||||
c.direccion.toLowerCase().contains(q) ||
|
||||
c.categoria.toLowerCase().contains(q);
|
||||
}).take(_kMaxResultados + 1).toList(); // +1 para detectar si hay más
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final resultados = _filtrados;
|
||||
final hayMas = resultados.length > _kMaxResultados;
|
||||
final visibles = hayMas ? resultados.take(_kMaxResultados).toList() : resultados;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
appBar: AppBar(
|
||||
titleSpacing: 0,
|
||||
title: TextField(
|
||||
controller: _searchCtrl,
|
||||
focusNode: _focusNode,
|
||||
onChanged: _onSearchChanged,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 15),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Buscar por nombre, NIT o dirección...',
|
||||
hintStyle: TextStyle(color: Colors.white.withOpacity(0.55), fontSize: 14),
|
||||
border: InputBorder.none,
|
||||
prefixIcon: const Icon(Icons.search, color: Colors.white70, size: 22),
|
||||
suffixIcon: _searchCtrl.text.isNotEmpty
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear, color: Colors.white70, size: 20),
|
||||
onPressed: () {
|
||||
_searchCtrl.clear();
|
||||
setState(() => _query = '');
|
||||
_focusNode.requestFocus();
|
||||
},
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
body: _buildBody(visibles, hayMas),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBody(List<Cliente> visibles, bool hayMas) {
|
||||
if (_query.isEmpty) {
|
||||
return _buildEstadoInicial();
|
||||
}
|
||||
if (visibles.isEmpty) {
|
||||
return _buildSinResultados();
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
_buildContador(visibles.length, hayMas),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
|
||||
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
|
||||
itemCount: visibles.length + (hayMas ? 1 : 0),
|
||||
itemBuilder: (ctx, i) {
|
||||
if (i == visibles.length) return _buildMasResultados();
|
||||
return _buildClienteTile(visibles[i]);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEstadoInicial() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.search, size: 64, color: Colors.grey.shade300),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'${widget.clientes.length} clientes disponibles',
|
||||
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w500, color: AppTheme.textSecondary),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
const Text(
|
||||
'Escribe para buscar',
|
||||
style: TextStyle(fontSize: 13, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSinResultados() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.store_outlined, size: 56, color: Colors.grey.shade300),
|
||||
const SizedBox(height: 14),
|
||||
Text(
|
||||
'Sin resultados para "$_query"',
|
||||
style: const TextStyle(fontSize: 14, color: AppTheme.textSecondary),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
const Text(
|
||||
'Prueba con nombre, NIT o dirección',
|
||||
style: TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildContador(int cantidad, bool hayMas) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 16, 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
hayMas
|
||||
? 'Mostrando $_kMaxResultados de más resultados — refina la búsqueda'
|
||||
: '$cantidad resultado${cantidad == 1 ? '' : 's'}',
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildClienteTile(Cliente c) {
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 6),
|
||||
elevation: 0,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
side: const BorderSide(color: Color(0xFFE2E8F0)),
|
||||
),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
onTap: () => Navigator.pop(context, c),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 12),
|
||||
child: Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 20,
|
||||
backgroundColor: AppTheme.primaryColor.withOpacity(0.1),
|
||||
child: const Icon(Icons.store, size: 20, color: AppTheme.primaryColor),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildTextoResaltado(c.nombre, _query,
|
||||
const TextStyle(fontWeight: FontWeight.w600, fontSize: 14, color: AppTheme.textPrimary)),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
c.direccion,
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Row(
|
||||
children: [
|
||||
_buildChip(c.categoria),
|
||||
if (c.nit.isNotEmpty) ...[
|
||||
const SizedBox(width: 6),
|
||||
Text('NIT ${c.nit}',
|
||||
style: const TextStyle(fontSize: 10, color: AppTheme.textSecondary)),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const Icon(Icons.chevron_right, color: AppTheme.textSecondary, size: 20),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildMasResultados() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Hay más resultados — refina la búsqueda para verlos',
|
||||
style: TextStyle(fontSize: 12, color: Colors.grey.shade500),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildChip(String texto) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryColor.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(texto, style: const TextStyle(fontSize: 10, color: AppTheme.primaryColor, fontWeight: FontWeight.w500)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Resalta el texto que coincide con la búsqueda en negrita
|
||||
Widget _buildTextoResaltado(String texto, String query, TextStyle baseStyle) {
|
||||
if (query.isEmpty) return Text(texto, style: baseStyle, maxLines: 1, overflow: TextOverflow.ellipsis);
|
||||
final lower = texto.toLowerCase();
|
||||
final idx = lower.indexOf(query.toLowerCase());
|
||||
if (idx < 0) return Text(texto, style: baseStyle, maxLines: 1, overflow: TextOverflow.ellipsis);
|
||||
|
||||
return RichText(
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
text: TextSpan(
|
||||
style: baseStyle,
|
||||
children: [
|
||||
if (idx > 0) TextSpan(text: texto.substring(0, idx)),
|
||||
TextSpan(
|
||||
text: texto.substring(idx, idx + query.length),
|
||||
style: baseStyle.copyWith(
|
||||
backgroundColor: AppTheme.primaryColor.withOpacity(0.18),
|
||||
color: AppTheme.primaryColor,
|
||||
),
|
||||
),
|
||||
if (idx + query.length < texto.length)
|
||||
TextSpan(text: texto.substring(idx + query.length)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,322 @@
|
||||
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 '../../widgets/signature_pad.dart';
|
||||
|
||||
class FirmaScreen extends StatefulWidget {
|
||||
const FirmaScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<FirmaScreen> createState() => _FirmaScreenState();
|
||||
}
|
||||
|
||||
class _FirmaScreenState extends State<FirmaScreen> {
|
||||
final _padKey = GlobalKey<SignaturePadState>();
|
||||
bool _firmado = false;
|
||||
bool _guardando = false;
|
||||
|
||||
final _fmt = NumberFormat.currency(locale: 'es_BO', symbol: 'Bs.', decimalDigits: 2);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<AppProvider>();
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
appBar: AppBar(
|
||||
title: const Text('Firma del Cliente', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
children: [
|
||||
_buildResumenPedido(provider),
|
||||
const SizedBox(height: 16),
|
||||
_buildSignatureArea(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_buildBottomBar(context, provider),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildResumenPedido(AppProvider provider) {
|
||||
final cliente = provider.clienteSeleccionado;
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFF1E3A8A), Color(0xFF2563EB)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: const [
|
||||
Icon(Icons.receipt_long, color: Colors.white70, size: 16),
|
||||
SizedBox(width: 6),
|
||||
Text('Resumen del pedido', style: TextStyle(color: Colors.white70, fontSize: 13)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Cliente:', style: TextStyle(color: Colors.white60, fontSize: 11)),
|
||||
Text(
|
||||
cliente?.nombre ?? '—',
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 15),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text('Dirección:', style: TextStyle(color: Colors.white60, fontSize: 11)),
|
||||
Text(
|
||||
cliente?.direccion ?? '—',
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 12),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
const Text('Total:', style: TextStyle(color: Colors.white70, fontSize: 13)),
|
||||
Text(
|
||||
_fmt.format(provider.totalCarrito),
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 24),
|
||||
),
|
||||
Text(
|
||||
'${provider.cantidadCarrito} unidades',
|
||||
style: const TextStyle(color: Colors.white60, fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(color: Colors.white24, height: 20),
|
||||
Text(
|
||||
'${provider.carrito.length} producto(s): '
|
||||
'${provider.carrito.map((i) => i.producto.nombre.split(' ').first).take(3).join(', ')}'
|
||||
'${provider.carrito.length > 3 ? '...' : ''}',
|
||||
style: const TextStyle(color: Colors.white60, fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSignatureArea(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Text('Firma de conformidad', style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
Text('El cliente firma confirmando el pedido', style: TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.refresh, size: 16),
|
||||
label: const Text('Limpiar'),
|
||||
onPressed: () {
|
||||
_padKey.currentState?.clear();
|
||||
setState(() => _firmado = false);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Container(
|
||||
height: 220,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
boxShadow: [BoxShadow(color: Colors.black.withOpacity(0.08), blurRadius: 10, offset: const Offset(0, 4))],
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
SignaturePad(
|
||||
key: _padKey,
|
||||
onChanged: (strokes) {
|
||||
setState(() => _firmado = strokes.isNotEmpty);
|
||||
},
|
||||
),
|
||||
if (!_firmado)
|
||||
Positioned.fill(
|
||||
child: IgnorePointer(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.draw_outlined, size: 40, color: Colors.grey.shade300),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Firmar aquí',
|
||||
style: TextStyle(fontSize: 16, color: Colors.grey.shade400, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
const Divider(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: const [
|
||||
Text('Nombre del firmante:', style: TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
Text('Responsable de recepción', style: TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (_firmado)
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 8),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.successColor.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: AppTheme.successColor.withOpacity(0.3)),
|
||||
),
|
||||
child: Row(
|
||||
children: const [
|
||||
Icon(Icons.check_circle_outline, color: AppTheme.successColor, size: 16),
|
||||
SizedBox(width: 8),
|
||||
Text('Firma registrada', style: TextStyle(color: AppTheme.successColor, fontSize: 12, fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildBottomBar(BuildContext context, AppProvider provider) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(16, 12, 16, 28),
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 8, offset: Offset(0, -2))],
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Volver al pedido'),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: ElevatedButton.icon(
|
||||
icon: _guardando
|
||||
? const SizedBox(width: 18, height: 18, child: CircularProgressIndicator(color: Colors.white, strokeWidth: 2))
|
||||
: const Icon(Icons.check_circle_outline, size: 22),
|
||||
label: Text(_guardando ? 'Guardando...' : 'Confirmar pedido',
|
||||
style: const TextStyle(fontSize: 15, fontWeight: FontWeight.w600)),
|
||||
onPressed: (!_firmado || _guardando)
|
||||
? null
|
||||
: () async {
|
||||
setState(() => _guardando = true);
|
||||
final pedido = await provider.confirmarPedido(firmaBase64: 'signed');
|
||||
if (mounted) {
|
||||
_showSuccess(context, pedido.id);
|
||||
}
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (!_firmado)
|
||||
const Text(
|
||||
'El cliente debe firmar para confirmar el pedido',
|
||||
style: TextStyle(fontSize: 11, color: AppTheme.textSecondary),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showSuccess(BuildContext context, String pedidoId) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => AlertDialog(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 72,
|
||||
height: 72,
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xFFDCFCE7),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.check, color: AppTheme.successColor, size: 40),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text('¡Pedido confirmado!',
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'$pedidoId ha sido registrado correctamente.',
|
||||
style: const TextStyle(color: AppTheme.textSecondary, fontSize: 13),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context)
|
||||
..pop()
|
||||
..pop()
|
||||
..pop();
|
||||
},
|
||||
child: const Text('Volver al inicio'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,539 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import '../../services/notification_service.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
import '../../widgets/stat_card.dart';
|
||||
import '../../models/pedido.dart';
|
||||
import '../notificaciones/notificaciones_screen.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
const HomeScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<AppProvider>();
|
||||
final notifService = context.watch<NotificationService>();
|
||||
final fmt = NumberFormat.currency(locale: 'es_BO', symbol: 'Bs.', decimalDigits: 2);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
body: RefreshIndicator(
|
||||
onRefresh: () async => await Future.delayed(const Duration(milliseconds: 600)),
|
||||
child: CustomScrollView(
|
||||
slivers: [
|
||||
_buildSliverAppBar(context, provider, notifService),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
const SizedBox(height: 16),
|
||||
_buildStatsGrid(context, provider, fmt),
|
||||
const SizedBox(height: 20),
|
||||
_buildRutaCard(context, provider),
|
||||
const SizedBox(height: 20),
|
||||
_buildRecentOrders(context, provider, fmt),
|
||||
const SizedBox(height: 20),
|
||||
_buildQuickActions(context, notifService),
|
||||
const SizedBox(height: 80),
|
||||
]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSliverAppBar(
|
||||
BuildContext context,
|
||||
AppProvider provider,
|
||||
NotificationService notifService,
|
||||
) {
|
||||
final hour = DateTime.now().hour;
|
||||
final greeting = hour < 12 ? 'Buenos días' : hour < 18 ? 'Buenas tardes' : 'Buenas noches';
|
||||
final dateStr = DateFormat('EEEE, d \'de\' MMMM', 'es').format(DateTime.now());
|
||||
final unread = notifService.unreadCount;
|
||||
|
||||
return SliverAppBar(
|
||||
expandedHeight: 160,
|
||||
floating: false,
|
||||
pinned: true,
|
||||
backgroundColor: AppTheme.primaryColor,
|
||||
actions: [
|
||||
Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.notifications_outlined, color: Colors.white, size: 26),
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => const NotificacionesScreen()),
|
||||
),
|
||||
),
|
||||
if (unread > 0)
|
||||
Positioned(
|
||||
top: 10,
|
||||
right: 10,
|
||||
child: Container(
|
||||
width: 17,
|
||||
height: 17,
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFFEF4444),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: AppTheme.primaryColor, width: 1.5),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
unread > 9 ? '9+' : '$unread',
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.bold,
|
||||
height: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
background: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Color(0xFF1E3A8A), Color(0xFF2563EB)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 60, 0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 22,
|
||||
backgroundColor: Colors.white.withOpacity(0.2),
|
||||
child: Text(
|
||||
provider.vendedor.avatarInitials,
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 16),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'$greeting,',
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 13),
|
||||
),
|
||||
Text(
|
||||
provider.vendedor.nombre,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 17, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.calendar_today, color: Colors.white60, size: 14),
|
||||
const SizedBox(width: 6),
|
||||
Text(
|
||||
dateStr,
|
||||
style: const TextStyle(color: Colors.white70, fontSize: 13),
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.location_on, color: Colors.white, size: 14),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
provider.vendedor.zona,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 12, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
greeting,
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
titlePadding: const EdgeInsets.only(left: 16, bottom: 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatsGrid(BuildContext context, AppProvider provider, NumberFormat fmt) {
|
||||
final ruta = provider.ruta;
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Resumen del día',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
const SizedBox(height: 12),
|
||||
GridView.count(
|
||||
crossAxisCount: 2,
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
crossAxisSpacing: 12,
|
||||
mainAxisSpacing: 12,
|
||||
childAspectRatio: 1.5,
|
||||
children: [
|
||||
StatCard(
|
||||
titulo: 'Pedidos hoy',
|
||||
valor: '${provider.pedidosHoy}',
|
||||
subtitulo: 'confirmados',
|
||||
icono: Icons.receipt_long,
|
||||
color: AppTheme.primaryColor,
|
||||
),
|
||||
StatCard(
|
||||
titulo: 'Ventas del día',
|
||||
valor: fmt.format(provider.ventasTotalesHoy),
|
||||
subtitulo: 'total acumulado',
|
||||
icono: Icons.attach_money,
|
||||
color: AppTheme.successColor,
|
||||
),
|
||||
StatCard(
|
||||
titulo: 'Clientes visitados',
|
||||
valor: '${ruta.visitadas}/${ruta.paradas.length}',
|
||||
subtitulo: 'en la ruta',
|
||||
icono: Icons.store,
|
||||
color: AppTheme.accentColor,
|
||||
),
|
||||
StatCard(
|
||||
titulo: 'Paradas restantes',
|
||||
valor: '${ruta.pendientes}',
|
||||
subtitulo: 'por visitar',
|
||||
icono: Icons.flag_outlined,
|
||||
color: AppTheme.warningColor,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRutaCard(BuildContext context, AppProvider provider) {
|
||||
final ruta = provider.ruta;
|
||||
final proxima = ruta.paradas.where((p) => p.estado.name == 'pendiente').isNotEmpty
|
||||
? ruta.paradas.firstWhere((p) => p.estado.name == 'pendiente')
|
||||
: null;
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFF0F172A), Color(0xFF1E3A8A)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.route, color: Colors.white, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
ruta.nombre,
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 15),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.15),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'${ruta.visitadas}/${ruta.paradas.length} paradas',
|
||||
style: const TextStyle(color: Colors.white, fontSize: 12),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
child: LinearProgressIndicator(
|
||||
value: ruta.paradas.isEmpty ? 0 : ruta.visitadas / ruta.paradas.length,
|
||||
backgroundColor: Colors.white.withOpacity(0.2),
|
||||
valueColor: const AlwaysStoppedAnimation<Color>(Color(0xFF34D399)),
|
||||
minHeight: 6,
|
||||
),
|
||||
),
|
||||
if (proxima != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.navigation, color: Color(0xFF34D399), size: 16),
|
||||
const SizedBox(width: 6),
|
||||
const Text('Próxima parada:', style: TextStyle(color: Colors.white60, fontSize: 12)),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
proxima.cliente.nombre,
|
||||
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.w600, fontSize: 13),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
proxima.horaEstimada,
|
||||
style: const TextStyle(color: Color(0xFFFBBF24), fontSize: 13, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRecentOrders(BuildContext context, AppProvider provider, NumberFormat fmt) {
|
||||
final recientes = provider.pedidos.take(3).toList();
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('Pedidos recientes',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text('Ver todos'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
...recientes.map((pedido) => _buildOrderTile(context, pedido, fmt)).toList(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildOrderTile(BuildContext context, Pedido pedido, NumberFormat fmt) {
|
||||
final estadoColor = AppTheme.estadoColor(pedido.estado.label);
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(color: Colors.black.withOpacity(0.04), blurRadius: 6, offset: const Offset(0, 2)),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: estadoColor.withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Icon(Icons.receipt_outlined, color: estadoColor, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(pedido.id,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 13, color: AppTheme.textPrimary)),
|
||||
Text(pedido.cliente.nombre,
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(fmt.format(pedido.total),
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 13, color: AppTheme.textPrimary)),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: estadoColor.withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
pedido.estado.label,
|
||||
style: TextStyle(fontSize: 10, color: estadoColor, fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildQuickActions(BuildContext context, NotificationService notifService) {
|
||||
final staticActions = [
|
||||
{'icon': Icons.add_shopping_cart, 'label': 'Nuevo\nPedido', 'color': AppTheme.primaryColor},
|
||||
{'icon': Icons.map_outlined, 'label': 'Ver\nRuta', 'color': AppTheme.successColor},
|
||||
{'icon': Icons.inventory_2_outlined, 'label': 'Catálogo', 'color': AppTheme.accentColor},
|
||||
];
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Acciones rápidas',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: AppTheme.textPrimary)),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
...staticActions.map((a) {
|
||||
final color = a['color'] as Color;
|
||||
return Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () {},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(color: color.withOpacity(0.1), blurRadius: 8, offset: const Offset(0, 3)),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(a['icon'] as IconData, color: color, size: 26),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
a['label'] as String,
|
||||
style: TextStyle(fontSize: 11, color: color, fontWeight: FontWeight.w600),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
Expanded(
|
||||
child: GestureDetector(
|
||||
onTap: () => notifService.dispararDemo(),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color(0xFF7C3AED).withOpacity(0.15),
|
||||
blurRadius: 8,
|
||||
offset: const Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: const [
|
||||
Icon(Icons.notifications_active, color: Color(0xFF7C3AED), size: 26),
|
||||
SizedBox(height: 6),
|
||||
Text(
|
||||
'Demo\nNotif.',
|
||||
style: TextStyle(fontSize: 11, color: Color(0xFF7C3AED), fontWeight: FontWeight.w600),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildNotifDemoCard(context, notifService),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNotifDemoCard(BuildContext context, NotificationService notifService) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [Color(0xFF4C1D95), Color(0xFF7C3AED)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 44,
|
||||
height: 44,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.15),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.notifications_active, color: Colors.white, size: 22),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: const [
|
||||
Text(
|
||||
'Demo de notificaciones',
|
||||
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 14),
|
||||
),
|
||||
SizedBox(height: 2),
|
||||
Text(
|
||||
'Pulsa para disparar 5 notificaciones de muestra con banner animado',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
ElevatedButton(
|
||||
onPressed: () => notifService.dispararDemo(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.white,
|
||||
onPrimary: const Color(0xFF7C3AED),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
elevation: 0,
|
||||
),
|
||||
child: const Text('Probar', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 13)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../providers/app_provider.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
const LoginScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
final _emailCtrl = TextEditingController(text: 'admin@telcotronics.com');
|
||||
final _passCtrl = TextEditingController(text: 'Microbot%');
|
||||
bool _obscure = true;
|
||||
bool _loading = false;
|
||||
String? _error;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_emailCtrl.dispose();
|
||||
_passCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _login() async {
|
||||
setState(() { _loading = true; _error = null; });
|
||||
final ok = await context.read<AppProvider>().login(
|
||||
_emailCtrl.text.trim(), _passCtrl.text);
|
||||
if (!ok && mounted) {
|
||||
setState(() {
|
||||
_loading = false;
|
||||
_error = context.read<AppProvider>().loginError;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Color(0xFF1E3A8A), Color(0xFF1E40AF), Color(0xFF2563EB)],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 28),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
_buildLogo(),
|
||||
const SizedBox(height: 40),
|
||||
_buildCard(),
|
||||
const SizedBox(height: 24),
|
||||
_buildVersion(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLogo() {
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
width: 96,
|
||||
height: 96,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.25),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
child: Image.asset(
|
||||
'assets/icon/icon.png',
|
||||
width: 96,
|
||||
height: 96,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
const Text(
|
||||
'Agente Ventas',
|
||||
style: TextStyle(
|
||||
fontSize: 32,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
letterSpacing: 1.0,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'by SIGMAC',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Colors.white.withOpacity(0.65),
|
||||
letterSpacing: 2.0,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
'Gestión de rutas y pedidos de campo',
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Colors.white.withOpacity(0.8),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCard() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(28),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.2),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text(
|
||||
'Iniciar sesión',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
const Text(
|
||||
'Ingresa tus credenciales para continuar',
|
||||
style: TextStyle(fontSize: 13, color: AppTheme.textSecondary),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
TextField(
|
||||
controller: _emailCtrl,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Correo electrónico',
|
||||
prefixIcon: Icon(Icons.email_outlined),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextField(
|
||||
controller: _passCtrl,
|
||||
obscureText: _obscure,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Contraseña',
|
||||
prefixIcon: const Icon(Icons.lock_outline),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(_obscure ? Icons.visibility_outlined : Icons.visibility_off_outlined),
|
||||
onPressed: () => setState(() => _obscure = !_obscure),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: TextButton(
|
||||
onPressed: () {},
|
||||
child: const Text('¿Olvidaste tu contraseña?'),
|
||||
),
|
||||
),
|
||||
if (_error != null) ...[
|
||||
Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.dangerColor.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: AppTheme.dangerColor.withOpacity(0.3)),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.error_outline, color: AppTheme.dangerColor, size: 16),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_error!,
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.dangerColor),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
],
|
||||
const SizedBox(height: 8),
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: _loading ? null : _login,
|
||||
child: _loading
|
||||
? const SizedBox(
|
||||
width: 22,
|
||||
height: 22,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2.5,
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [
|
||||
Icon(Icons.login, size: 20),
|
||||
SizedBox(width: 8),
|
||||
Text('Ingresar', style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildVersion() {
|
||||
return Text(
|
||||
'v1.0.0 • SIGMAC • Telcotronics',
|
||||
style: TextStyle(fontSize: 12, color: Colors.white.withOpacity(0.6)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme/app_theme.dart';
|
||||
import 'home/home_screen.dart';
|
||||
import 'rutas/rutas_screen.dart';
|
||||
import 'pedidos/pedidos_screen.dart';
|
||||
import 'catalogo/catalogo_screen.dart';
|
||||
import 'perfil/perfil_screen.dart';
|
||||
|
||||
class MainShell extends StatefulWidget {
|
||||
const MainShell({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<MainShell> createState() => _MainShellState();
|
||||
}
|
||||
|
||||
class _MainShellState extends State<MainShell> {
|
||||
int _currentIndex = 0;
|
||||
|
||||
final _screens = const [
|
||||
HomeScreen(),
|
||||
RutasScreen(),
|
||||
PedidosScreen(),
|
||||
CatalogoScreen(),
|
||||
PerfilScreen(),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: IndexedStack(
|
||||
index: _currentIndex,
|
||||
children: _screens,
|
||||
),
|
||||
bottomNavigationBar: Container(
|
||||
decoration: const BoxDecoration(
|
||||
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 10, offset: Offset(0, -2))],
|
||||
),
|
||||
child: BottomNavigationBar(
|
||||
currentIndex: _currentIndex,
|
||||
onTap: (i) => setState(() => _currentIndex = i),
|
||||
type: BottomNavigationBarType.fixed,
|
||||
backgroundColor: Colors.white,
|
||||
selectedItemColor: AppTheme.primaryColor,
|
||||
unselectedItemColor: const Color(0xFF94A3B8),
|
||||
selectedFontSize: 11,
|
||||
unselectedFontSize: 11,
|
||||
items: const [
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.home_outlined),
|
||||
activeIcon: Icon(Icons.home_rounded),
|
||||
label: 'Inicio',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.route_outlined),
|
||||
activeIcon: Icon(Icons.route_rounded),
|
||||
label: 'Mi Ruta',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.receipt_long_outlined),
|
||||
activeIcon: Icon(Icons.receipt_long_rounded),
|
||||
label: 'Pedidos',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.inventory_2_outlined),
|
||||
activeIcon: Icon(Icons.inventory_2_rounded),
|
||||
label: 'Catálogo',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.person_outline_rounded),
|
||||
activeIcon: Icon(Icons.person_rounded),
|
||||
label: 'Perfil',
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import '../../services/notification_service.dart';
|
||||
import '../../models/notificacion.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
|
||||
class NotificacionesScreen extends StatelessWidget {
|
||||
const NotificacionesScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Consumer<NotificationService>(
|
||||
builder: (context, service, _) {
|
||||
final notifs = service.notifications;
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
_buildAppBar(context, service),
|
||||
if (notifs.isEmpty)
|
||||
_buildEmptyState()
|
||||
else
|
||||
_buildList(context, service, notifs),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildAppBar(BuildContext context, NotificationService service) {
|
||||
return SliverAppBar(
|
||||
pinned: true,
|
||||
backgroundColor: AppTheme.primaryColor,
|
||||
title: Row(
|
||||
children: [
|
||||
const Text(
|
||||
'Notificaciones',
|
||||
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
|
||||
),
|
||||
if (service.unreadCount > 0) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(
|
||||
'${service.unreadCount} sin leer',
|
||||
style: const TextStyle(fontSize: 11, color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
if (service.unreadCount > 0)
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.done_all, color: Colors.white70, size: 18),
|
||||
label: const Text(
|
||||
'Marcar todo',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 12),
|
||||
),
|
||||
onPressed: service.marcarTodasLeidas,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
return SliverFillRemaining(
|
||||
child: Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 80,
|
||||
height: 80,
|
||||
decoration: const BoxDecoration(
|
||||
color: Color(0xFFEFF6FF),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.notifications_none_rounded,
|
||||
size: 40,
|
||||
color: Color(0xFF93C5FD),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Sin notificaciones',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'Aquí aparecerán alertas de pedidos,\nstock, rutas y más.',
|
||||
style: TextStyle(fontSize: 13, color: AppTheme.textSecondary),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildList(
|
||||
BuildContext context,
|
||||
NotificationService service,
|
||||
List<Notificacion> notifs,
|
||||
) {
|
||||
final hoy = <Notificacion>[];
|
||||
final antes = <Notificacion>[];
|
||||
final now = DateTime.now();
|
||||
|
||||
for (final n in notifs) {
|
||||
if (n.fecha.day == now.day && n.fecha.month == now.month && n.fecha.year == now.year) {
|
||||
hoy.add(n);
|
||||
} else {
|
||||
antes.add(n);
|
||||
}
|
||||
}
|
||||
|
||||
final sections = <Widget>[];
|
||||
|
||||
if (hoy.isNotEmpty) {
|
||||
sections.add(_buildSectionHeader('Hoy'));
|
||||
sections.addAll(hoy.map((n) => _buildNotifCard(context, service, n)));
|
||||
}
|
||||
if (antes.isNotEmpty) {
|
||||
sections.add(_buildSectionHeader('Anteriores'));
|
||||
sections.addAll(antes.map((n) => _buildNotifCard(context, service, n)));
|
||||
}
|
||||
|
||||
return SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
...sections,
|
||||
const SizedBox(height: 24),
|
||||
]),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSectionHeader(String label) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 6),
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: AppTheme.textSecondary,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildNotifCard(
|
||||
BuildContext context,
|
||||
NotificationService service,
|
||||
Notificacion notif,
|
||||
) {
|
||||
final color = notif.tipo.color;
|
||||
final timeFmt = DateFormat('HH:mm', 'es');
|
||||
final dateFmt = DateFormat('d MMM', 'es');
|
||||
final isToday = notif.fecha.day == DateTime.now().day;
|
||||
final timeLabel = isToday ? timeFmt.format(notif.fecha) : dateFmt.format(notif.fecha);
|
||||
|
||||
return Dismissible(
|
||||
key: Key(notif.id),
|
||||
direction: DismissDirection.endToStart,
|
||||
background: Container(
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 24),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.dangerColor,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
child: const Icon(Icons.delete_outline, color: Colors.white, size: 24),
|
||||
),
|
||||
onDismissed: (_) => service.eliminar(notif.id),
|
||||
child: GestureDetector(
|
||||
onTap: () {
|
||||
if (!notif.leida) service.marcarLeida(notif.id);
|
||||
},
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: notif.leida ? Colors.white : const Color(0xFFEFF6FF),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: notif.leida
|
||||
? Border.all(color: Colors.transparent)
|
||||
: Border(left: BorderSide(color: color, width: 3)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.04),
|
||||
blurRadius: 6,
|
||||
offset: const Offset(0, 2),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.12),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(notif.tipo.icono, color: color, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
notif.titulo,
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
fontWeight: notif.leida ? FontWeight.w500 : FontWeight.bold,
|
||||
color: AppTheme.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
timeLabel,
|
||||
style: const TextStyle(fontSize: 11, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
notif.cuerpo,
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(
|
||||
notif.tipo.label,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: color,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!notif.leida) ...[
|
||||
const SizedBox(width: 8),
|
||||
Container(
|
||||
width: 7,
|
||||
height: 7,
|
||||
decoration: BoxDecoration(
|
||||
color: color,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'Sin leer',
|
||||
style: TextStyle(fontSize: 10, color: color, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
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 PerfilScreen extends StatelessWidget {
|
||||
const PerfilScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final provider = context.watch<AppProvider>();
|
||||
final vendedor = provider.vendedor;
|
||||
final fmt = NumberFormat.currency(locale: 'es_BO', symbol: 'Bs.', decimalDigits: 2);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
body: CustomScrollView(
|
||||
slivers: [
|
||||
_buildSliverHeader(context, vendedor, provider),
|
||||
SliverPadding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildListDelegate([
|
||||
_buildStatsRow(provider, fmt),
|
||||
const SizedBox(height: 20),
|
||||
_buildRutaProgress(provider),
|
||||
const SizedBox(height: 20),
|
||||
_buildPedidosResumen(context, provider, fmt),
|
||||
const SizedBox(height: 20),
|
||||
_buildInfoCard(vendedor),
|
||||
const SizedBox(height: 20),
|
||||
_buildConfigSection(context),
|
||||
const SizedBox(height: 20),
|
||||
_buildLogoutBtn(context, provider),
|
||||
const SizedBox(height: 40),
|
||||
]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSliverHeader(BuildContext context, vendedor, AppProvider provider) {
|
||||
return SliverAppBar(
|
||||
expandedHeight: 200,
|
||||
pinned: true,
|
||||
backgroundColor: AppTheme.primaryColor,
|
||||
flexibleSpace: FlexibleSpaceBar(
|
||||
background: Container(
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [Color(0xFF1E3A8A), Color(0xFF2563EB)],
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 40,
|
||||
backgroundColor: Colors.white.withOpacity(0.2),
|
||||
child: Text(
|
||||
vendedor.avatarInitials,
|
||||
style: const TextStyle(fontSize: 28, fontWeight: FontWeight.bold, color: Colors.white),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(vendedor.nombre,
|
||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold, color: Colors.white)),
|
||||
const SizedBox(height: 4),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.location_on, color: Colors.white70, size: 14),
|
||||
const SizedBox(width: 4),
|
||||
Text(vendedor.zona,
|
||||
style: const TextStyle(color: Colors.white, fontSize: 12, fontWeight: FontWeight.w500)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(vendedor.nombre, style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
titlePadding: const EdgeInsets.only(left: 16, bottom: 12),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildStatsRow(AppProvider provider, NumberFormat fmt) {
|
||||
final stats = [
|
||||
{'label': 'Pedidos hoy', 'value': '${provider.pedidosHoy}', 'color': AppTheme.primaryColor},
|
||||
{'label': 'Ventas hoy', 'value': fmt.format(provider.ventasTotalesHoy), 'color': AppTheme.successColor},
|
||||
{
|
||||
'label': 'Clientes',
|
||||
'value': '${provider.ruta.visitadas}/${provider.ruta.paradas.length}',
|
||||
'color': AppTheme.accentColor
|
||||
},
|
||||
];
|
||||
|
||||
return Row(
|
||||
children: stats.map((s) {
|
||||
final color = s['color'] as Color;
|
||||
return Expanded(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 4),
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
boxShadow: [BoxShadow(color: color.withOpacity(0.1), blurRadius: 8)],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(s['value'] as String,
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: color)),
|
||||
const SizedBox(height: 4),
|
||||
Text(s['label'] as String,
|
||||
style: const TextStyle(fontSize: 10, color: AppTheme.textSecondary), textAlign: TextAlign.center),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildRutaProgress(AppProvider provider) {
|
||||
final ruta = provider.ruta;
|
||||
final progress = ruta.paradas.isEmpty ? 0.0 : ruta.visitadas / ruta.paradas.length;
|
||||
|
||||
return _card(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text('Progreso de ruta', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14)),
|
||||
Text('${(progress * 100).toInt()}% completado',
|
||||
style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: LinearProgressIndicator(
|
||||
value: progress,
|
||||
backgroundColor: AppTheme.bgColor,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
progress == 1.0 ? AppTheme.successColor : AppTheme.primaryColor,
|
||||
),
|
||||
minHeight: 10,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
_progressChip(Icons.check_circle, '${ruta.visitadas} visitadas', AppTheme.successColor),
|
||||
_progressChip(Icons.pending, '${ruta.pendientes} pendientes', AppTheme.warningColor),
|
||||
_progressChip(Icons.location_on, '${ruta.paradas.length} total', AppTheme.primaryColor),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _progressChip(IconData icon, String label, Color color) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(icon, size: 14, color: color),
|
||||
const SizedBox(width: 4),
|
||||
Text(label, style: TextStyle(fontSize: 11, color: color, fontWeight: FontWeight.w500)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildPedidosResumen(BuildContext context, AppProvider provider, NumberFormat fmt) {
|
||||
final estados = {
|
||||
EstadoPedido.confirmado: provider.pedidos.where((p) => p.estado == EstadoPedido.confirmado).length,
|
||||
EstadoPedido.entregado: provider.pedidos.where((p) => p.estado == EstadoPedido.entregado).length,
|
||||
EstadoPedido.pendiente: provider.pedidos.where((p) => p.estado == EstadoPedido.pendiente).length,
|
||||
EstadoPedido.cancelado: provider.pedidos.where((p) => p.estado == EstadoPedido.cancelado).length,
|
||||
};
|
||||
|
||||
return _card(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Resumen de pedidos', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14)),
|
||||
const SizedBox(height: 12),
|
||||
...estados.entries.map((e) {
|
||||
final color = AppTheme.estadoColor(e.key.label);
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(width: 10, height: 10, decoration: BoxDecoration(color: color, shape: BoxShape.circle)),
|
||||
const SizedBox(width: 10),
|
||||
Text(e.key.label, style: const TextStyle(fontSize: 13)),
|
||||
const Spacer(),
|
||||
Text('${e.value}', style: TextStyle(fontWeight: FontWeight.bold, color: color)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoCard(vendedor) {
|
||||
return _card(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Información de contacto', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14)),
|
||||
const SizedBox(height: 12),
|
||||
_infoTile(Icons.email_outlined, 'Correo', vendedor.email),
|
||||
_infoTile(Icons.phone_outlined, 'Teléfono', vendedor.telefono),
|
||||
_infoTile(Icons.map_outlined, 'Zona', vendedor.zona),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _infoTile(IconData icon, String label, String value) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 10),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 18, color: AppTheme.primaryColor),
|
||||
const SizedBox(width: 10),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(label, style: const TextStyle(fontSize: 10, color: AppTheme.textSecondary)),
|
||||
Text(value, style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w500)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildConfigSection(BuildContext context) {
|
||||
final opciones = [
|
||||
{'icon': Icons.notifications_outlined, 'label': 'Notificaciones', 'trailing': true},
|
||||
{'icon': Icons.language, 'label': 'Idioma', 'value': 'Español'},
|
||||
{'icon': Icons.help_outline, 'label': 'Ayuda y soporte', 'arrow': true},
|
||||
{'icon': Icons.info_outline, 'label': 'Acerca de la app', 'value': 'v1.0.0'},
|
||||
];
|
||||
|
||||
return _card(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('Configuración', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 14)),
|
||||
const SizedBox(height: 8),
|
||||
...opciones.map((o) => ListTile(
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(o['icon'] as IconData, color: AppTheme.primaryColor, size: 22),
|
||||
title: Text(o['label'] as String, style: const TextStyle(fontSize: 13)),
|
||||
trailing: o['trailing'] == true
|
||||
? Switch(value: true, onChanged: (_) {}, activeColor: AppTheme.primaryColor)
|
||||
: o['arrow'] == true
|
||||
? const Icon(Icons.chevron_right, color: AppTheme.textSecondary)
|
||||
: Text(o['value'] as String? ?? '', style: const TextStyle(fontSize: 12, color: AppTheme.textSecondary)),
|
||||
onTap: () {},
|
||||
)).toList(),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildLogoutBtn(BuildContext context, AppProvider provider) {
|
||||
return SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: OutlinedButton.icon(
|
||||
icon: const Icon(Icons.logout, color: AppTheme.dangerColor),
|
||||
label: const Text('Cerrar sesión', style: TextStyle(color: AppTheme.dangerColor, fontWeight: FontWeight.w600)),
|
||||
style: OutlinedButton.styleFrom(
|
||||
side: const BorderSide(color: AppTheme.dangerColor),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
title: const Text('Cerrar sesión'),
|
||||
content: const Text('¿Seguro que deseas salir?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(context), child: const Text('Cancelar')),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
provider.logout();
|
||||
},
|
||||
child: const Text('Salir', style: TextStyle(color: AppTheme.dangerColor)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _card({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: child,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import 'dart:io' show Platform;
|
||||
import 'package:flutter/foundation.dart' show kIsWeb;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'scanner_screen.dart';
|
||||
|
||||
/// Abre el scanner de cámara en móvil/web, o un diálogo de entrada manual en Linux/Windows.
|
||||
/// Retorna el valor escaneado/ingresado, o null si el usuario canceló.
|
||||
Future<String?> abrirScanner(BuildContext context, {String titulo = 'Escanear código'}) {
|
||||
if (!kIsWeb && (Platform.isLinux || Platform.isWindows)) {
|
||||
return _mostrarInputManual(context, titulo: titulo);
|
||||
}
|
||||
return Navigator.push<String>(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => ScannerScreen(titulo: titulo)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> _mostrarInputManual(BuildContext context, {required String titulo}) {
|
||||
final ctrl = TextEditingController();
|
||||
return showDialog<String>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: Row(
|
||||
children: [
|
||||
const Icon(Icons.qr_code, size: 22),
|
||||
const SizedBox(width: 8),
|
||||
Text(titulo, style: const TextStyle(fontSize: 16)),
|
||||
],
|
||||
),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text(
|
||||
'Escaneo de cámara no disponible en escritorio.\nIngresa el código manualmente:',
|
||||
style: TextStyle(fontSize: 13, color: Colors.black54),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
TextField(
|
||||
controller: ctrl,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Código / SKU',
|
||||
prefixIcon: Icon(Icons.qr_code),
|
||||
border: OutlineInputBorder(),
|
||||
),
|
||||
onSubmitted: (v) {
|
||||
if (v.trim().isNotEmpty) Navigator.pop(ctx, v.trim());
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx), child: const Text('Cancelar')),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
final v = ctrl.text.trim();
|
||||
if (v.isNotEmpty) Navigator.pop(ctx, v);
|
||||
},
|
||||
child: const Text('Buscar'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:mobile_scanner/mobile_scanner.dart';
|
||||
import '../../theme/app_theme.dart';
|
||||
|
||||
class ScannerScreen extends StatefulWidget {
|
||||
final String titulo;
|
||||
const ScannerScreen({Key? key, this.titulo = 'Escanear código'}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ScannerScreen> createState() => _ScannerScreenState();
|
||||
}
|
||||
|
||||
class _ScannerScreenState extends State<ScannerScreen> {
|
||||
final _controller = MobileScannerController();
|
||||
bool _scanned = false;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onDetect(Barcode barcode, MobileScannerArguments? args) {
|
||||
if (_scanned || barcode.rawValue == null || barcode.rawValue!.isEmpty) return;
|
||||
_scanned = true;
|
||||
Navigator.pop(context, barcode.rawValue);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.black,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
title: Text(widget.titulo),
|
||||
actions: [
|
||||
ValueListenableBuilder<TorchState>(
|
||||
valueListenable: _controller.torchState,
|
||||
builder: (_, state, __) => IconButton(
|
||||
tooltip: state == TorchState.on ? 'Apagar linterna' : 'Encender linterna',
|
||||
icon: Icon(
|
||||
state == TorchState.on ? Icons.flash_on : Icons.flash_off,
|
||||
color: state == TorchState.on ? Colors.yellow : Colors.white,
|
||||
),
|
||||
onPressed: _controller.toggleTorch,
|
||||
),
|
||||
),
|
||||
ValueListenableBuilder<CameraFacing>(
|
||||
valueListenable: _controller.cameraFacingState,
|
||||
builder: (_, facing, __) => IconButton(
|
||||
tooltip: 'Cambiar cámara',
|
||||
icon: const Icon(Icons.cameraswitch, color: Colors.white),
|
||||
onPressed: _controller.switchCamera,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Stack(
|
||||
children: [
|
||||
MobileScanner(
|
||||
controller: _controller,
|
||||
fit: BoxFit.cover,
|
||||
onDetect: _onDetect,
|
||||
),
|
||||
CustomPaint(
|
||||
painter: _ScanOverlayPainter(),
|
||||
child: const SizedBox.expand(),
|
||||
),
|
||||
Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 56,
|
||||
child: Column(
|
||||
children: const [
|
||||
Icon(Icons.qr_code_scanner, color: Colors.white38, size: 28),
|
||||
SizedBox(height: 10),
|
||||
Text(
|
||||
'Apunta al código QR o código de barras',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.white70, fontSize: 13),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _ScanOverlayPainter extends CustomPainter {
|
||||
@override
|
||||
void paint(Canvas canvas, Size size) {
|
||||
final frameSize = size.width * 0.72;
|
||||
final left = (size.width - frameSize) / 2;
|
||||
final top = (size.height - frameSize) / 2 - 40;
|
||||
final frameRect = Rect.fromLTWH(left, top, frameSize, frameSize);
|
||||
|
||||
// Semi-transparent overlay with hole
|
||||
final overlayPaint = Paint()..color = Colors.black.withOpacity(0.55);
|
||||
final outer = Path()..addRect(Rect.fromLTWH(0, 0, size.width, size.height));
|
||||
final inner = Path()..addRRect(RRect.fromRectAndRadius(frameRect, const Radius.circular(10)));
|
||||
canvas.drawPath(Path.combine(PathOperation.difference, outer, inner), overlayPaint);
|
||||
|
||||
// Corner brackets
|
||||
final bracketPaint = Paint()
|
||||
..color = AppTheme.primaryColor
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 3.5
|
||||
..strokeCap = StrokeCap.round;
|
||||
|
||||
const cl = 22.0; // corner length
|
||||
final l = frameRect.left;
|
||||
final t = frameRect.top;
|
||||
final r = frameRect.right;
|
||||
final b = frameRect.bottom;
|
||||
|
||||
// Top-left
|
||||
canvas.drawLine(Offset(l, t + cl), Offset(l, t), bracketPaint);
|
||||
canvas.drawLine(Offset(l, t), Offset(l + cl, t), bracketPaint);
|
||||
// Top-right
|
||||
canvas.drawLine(Offset(r - cl, t), Offset(r, t), bracketPaint);
|
||||
canvas.drawLine(Offset(r, t), Offset(r, t + cl), bracketPaint);
|
||||
// Bottom-left
|
||||
canvas.drawLine(Offset(l, b - cl), Offset(l, b), bracketPaint);
|
||||
canvas.drawLine(Offset(l, b), Offset(l + cl, b), bracketPaint);
|
||||
// Bottom-right
|
||||
canvas.drawLine(Offset(r - cl, b), Offset(r, b), bracketPaint);
|
||||
canvas.drawLine(Offset(r, b), Offset(r, b - cl), bracketPaint);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldRepaint(_) => false;
|
||||
}
|
||||
Reference in New Issue
Block a user