| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- import 'package:flutter/material.dart';
- import 'package:go_router/go_router.dart';
- import 'package:ristoris/database/database.dart';
- Color? _creditScoreBg(String? colorName) {
- switch (colorName?.toUpperCase()) {
- case 'VERDE':
- return const Color(0xFF008000);
- case 'VERDE CHIARO':
- return const Color(0xFF90EE90);
- case 'VERDE SCURO':
- return const Color(0xFF006400);
- case 'GIALLO':
- return const Color(0xFFFFA500);
- case 'GRIGIO':
- return const Color(0xFF808080);
- case 'ROSSO VIVO':
- return const Color(0xFFA80000);
- case 'ROSSO SCURO':
- return const Color(0xFF8B0000);
- case 'ROSSO':
- return const Color(0xFFFF0000);
- default:
- return null;
- }
- }
- class CustomerCard extends StatelessWidget {
- final Cliente cliente;
- const CustomerCard({super.key, required this.cliente});
- @override
- Widget build(BuildContext context) {
- final theme = Theme.of(context);
- final cs = theme.colorScheme;
- return Card(
- elevation: 0,
- color: Colors.white,
- clipBehavior: Clip.antiAlias,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(12),
- side: BorderSide(color: cs.outlineVariant),
- ),
- child: InkWell(
- onTap: () => context.push('/dashboard/customers/${cliente.idCliente}'),
- child: Padding(
- padding: const EdgeInsets.all(16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Row(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Expanded(
- child: Text(
- cliente.ragioneSociale ?? '',
- style: theme.textTheme.bodyMedium?.copyWith(
- color: cs.primary,
- ),
- maxLines: 2,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- if ((cliente.codCliente ?? '').isNotEmpty) ...[
- const SizedBox(width: 8),
- Container(
- padding: const EdgeInsets.symmetric(
- horizontal: 8,
- vertical: 4,
- ),
- decoration: BoxDecoration(
- color: _creditScoreBg(cliente.creditScoreColor) ??
- cs.surfaceVariant,
- borderRadius: BorderRadius.circular(4),
- ),
- child: Text(
- cliente.codCliente ?? '',
- style: TextStyle(
- fontSize: 12,
- height: 16 / 12,
- fontWeight: FontWeight.w500,
- color: _creditScoreBg(cliente.creditScoreColor) != null
- ? Colors.white
- : cs.onSurfaceVariant,
- ),
- ),
- ),
- ],
- ],
- ),
- const SizedBox(height: 4),
- Text(
- cliente.email ?? '',
- style: theme.textTheme.bodyMedium?.copyWith(
- color: cs.onSurfaceVariant,
- ),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- const SizedBox(height: 16),
- Row(
- children: [
- Icon(Icons.phone, size: 20, color: cs.onSurfaceVariant),
- const SizedBox(width: 8),
- Expanded(
- child: Text(
- cliente.telefono ?? '',
- style: theme.textTheme.bodyMedium?.copyWith(
- color: cs.onSurfaceVariant,
- ),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ],
- ),
- Row(
- children: [
- Icon(Icons.business, size: 20, color: cs.onSurfaceVariant),
- const SizedBox(width: 8),
- Expanded(
- child: Text(
- cliente.indirizzo ?? '',
- style: theme.textTheme.bodyMedium?.copyWith(
- color: cs.onSurfaceVariant,
- ),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ],
- ),
- const SizedBox(height: 8),
- Row(
- children: [
- Icon(Icons.location_on, size: 20, color: cs.onSurfaceVariant),
- const SizedBox(width: 8),
- Expanded(
- child: Text(
- [
- if ((cliente.citta ?? '').isNotEmpty) cliente.citta,
- if ((cliente.provincia ?? '').isNotEmpty)
- cliente.provincia,
- ].join(', '),
- style: theme.textTheme.bodyMedium?.copyWith(
- color: cs.onSurfaceVariant,
- ),
- maxLines: 1,
- overflow: TextOverflow.ellipsis,
- ),
- ),
- ],
- ),
- const SizedBox(height: 16),
- Divider(height: 1, color: cs.outlineVariant),
- const SizedBox(height: 12),
- Row(
- children: [
- Expanded(
- child: OutlinedButton.icon(
- onPressed: () {
- context.go('/dashboard/customers/${cliente.idCliente}');
- },
- icon: const Icon(Icons.info_outline, size: 18),
- label: const Text('Dettagli'),
- style: OutlinedButton.styleFrom(
- foregroundColor: cs.secondary,
- side: BorderSide(
- color: cs.secondary.withValues(alpha: 0.3),
- ),
- ),
- ),
- ),
- const SizedBox(width: 8),
- Expanded(
- child: FilledButton.icon(
- onPressed: () => context.go(
- '/dashboard/orders/new?cliente=${cliente.idCliente}',
- ),
- icon: const Icon(Icons.shopping_cart, size: 18),
- label: const Text('Nuovo ordine'),
- ),
- ),
- ],
- ),
- ],
- ),
- ),
- ),
- );
- }
- }
|