| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227 |
- import 'package:flutter/material.dart';
- import 'package:go_router/go_router.dart';
- import 'package:ristoris/core/constants.dart';
- import 'package:ristoris/core/credit_score_color.dart';
- import 'package:ristoris/database/database.dart';
- 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(
- children: [
- Expanded(
- 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.surfaceContainerHighest,
- 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,
- ),
- ),
- ],
- ),
- const SizedBox(height: 4),
- 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,
- ),
- ),
- ],
- ),
- ],
- ),
- ),
- Divider(height: 1, color: cs.outlineVariant),
- const SizedBox(height: 16),
- 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: _buildOrdineButton(context),
- ),
- ],
- ),
- ],
- ),
- ),
- ),
- );
- }
- Widget _buildOrdineButton(BuildContext context) {
- final cs = Theme.of(context).colorScheme;
- final blocco = cliente.codBlocco;
- final isBloccato = blocco == '001';
- final hasWarning = blocco != null && blocco.isNotEmpty && blocco != '001';
- if (isBloccato) {
- return FilledButton.icon(
- onPressed: null,
- icon: const Icon(Icons.block, size: 18),
- label: const Text('Ordine'),
- style: FilledButton.styleFrom(
- backgroundColor: cs.surfaceContainerHighest,
- foregroundColor: cs.onSurfaceVariant,
- ),
- );
- }
- return FilledButton.icon(
- onPressed: () {
- if (hasWarning) {
- ScaffoldMessenger.of(context).showSnackBar(
- SnackBar(
- content: Text('Attenzione: cliente con blocco $blocco'),
- backgroundColor: Colors.amber.shade800,
- ),
- );
- }
- context.go('/dashboard/orders/new?cliente=${cliente.idCliente}');
- },
- icon: hasWarning ? const Icon(Icons.warning_amber_rounded, size: 18) : const Icon(Icons.add_shopping_cart_outlined, size: 18),
- label: const Text('Ordine'),
- style: getBloccoColors(blocco),
- );
- }
- ButtonStyle? getBloccoColors(String? codBlocco) {
- if (codBlocco == AppConstants.kBlocco) {
- return FilledButton.styleFrom(
- backgroundColor: Colors.deepOrange,
- foregroundColor: Colors.black87,
- );
- } else if (codBlocco != null && codBlocco.isNotEmpty) {
- return FilledButton.styleFrom(
- backgroundColor: Colors.amber,
- foregroundColor: Colors.black87,
- );
- }
- return null;
- }
- }
|