feat: handle delivery state transition and UI feedback in customer order form

This commit is contained in:
brontomark committed 2026-12-03 19:37:53 +01:00
1 parent 56f0d1ee53
commit a568486b4f
3 files changed
+488 -261

No files matched your search

@@ -298,6 +298,9 @@ class CustomerOrderFormCubit extends Cubit<CustomerOrderFormState> {
final transitionedToArrived =
saved.status == CustomerOrderStatus.arrived &&
previousStatus != CustomerOrderStatus.arrived;
final transitionedToDelivered =
saved.status == CustomerOrderStatus.delivered &&
previousStatus != CustomerOrderStatus.delivered;
emit(
state.copyWith(
@@ -306,6 +309,7 @@ class CustomerOrderFormCubit extends Cubit<CustomerOrderFormState> {
: CustomerOrderFormStatus.saved,
order: saved,
justMarkedArrived: transitionedToArrived,
justMarkedDelivered: transitionedToDelivered,
receiptNotificationResult: receiptNotificationResult,
errorMessage: null,
),
@@ -16,6 +16,7 @@ class CustomerOrderFormState extends Equatable {
final List<String> availableTags;
final String? errorMessage;
final bool justMarkedArrived;
final bool justMarkedDelivered;
final OrderNotificationResult? receiptNotificationResult;
const CustomerOrderFormState({
@@ -24,6 +25,7 @@ class CustomerOrderFormState extends Equatable {
this.availableTags = const [],
this.errorMessage,
this.justMarkedArrived = false,
this.justMarkedDelivered = false,
this.receiptNotificationResult,
});
@@ -33,6 +35,7 @@ class CustomerOrderFormState extends Equatable {
List<String>? availableTags,
String? errorMessage,
bool? justMarkedArrived,
bool? justMarkedDelivered,
OrderNotificationResult? receiptNotificationResult,
}) {
return CustomerOrderFormState(
@@ -41,6 +44,7 @@ class CustomerOrderFormState extends Equatable {
availableTags: availableTags ?? this.availableTags,
errorMessage: errorMessage,
justMarkedArrived: justMarkedArrived ?? false,
justMarkedDelivered: justMarkedDelivered ?? false,
receiptNotificationResult: receiptNotificationResult,
);
}
@@ -52,6 +56,7 @@ class CustomerOrderFormState extends Equatable {
availableTags,
errorMessage,
justMarkedArrived,
justMarkedDelivered,
receiptNotificationResult,
];
}
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flux/core/routes/routes.dart';
import 'package:flux/core/widgets/shared_forms/attachments_section.dart';
import 'package:flux/core/widgets/shared_forms/contact_preference_section.dart';
import 'package:flux/core/widgets/shared_forms/customer_section.dart';
@@ -10,6 +11,7 @@ import 'package:flux/features/customer_orders/models/customer_order_model.dart';
import 'package:flux/features/customer_orders/models/customer_order_status.dart';
import 'package:flux/features/customer_orders/utils/customer_order_label_pdf_service.dart';
import 'package:flux/features/master_data/store/bloc/store_cubit.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart';
import 'package:printing/printing.dart';
import 'package:url_launcher/url_launcher.dart';
@@ -202,6 +204,51 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
);
}
void _closeScreen() {
if (!mounted) return;
if (context.canPop()) {
context.pop();
} else {
context.goNamed(Routes.customerOrders);
}
}
Future<void> _showDeliveredSuccessDialog(CustomerOrderModel order) async {
final goToOrders = await showDialog<bool>(
context: context,
builder: (dialogCtx) {
return AlertDialog(
title: Row(
children: [
Icon(Icons.check_circle_rounded, color: Colors.green.shade600),
const SizedBox(width: 8),
const Expanded(child: Text('Consegna registrata!')),
],
),
content: Text(
'L\'ordine di ${order.customer?.name ?? 'Cliente'} (${order.productDescription}) è stato segnato come consegnato.',
),
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogCtx, false),
child: const Text('Rimani qui'),
),
FilledButton(
style: FilledButton.styleFrom(
backgroundColor: Colors.green.shade600,
),
onPressed: () => Navigator.pop(dialogCtx, true),
child: const Text('Vai agli Ordini'),
),
],
);
},
);
if (goToOrders == true && mounted) {
_closeScreen();
}
}
Future<void> _confirmDelete(BuildContext context) async {
final cubit = context.read<CustomerOrderFormCubit>();
final ok = await showDialog<bool>(
@@ -248,7 +295,7 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
}
if (state.status == CustomerOrderFormStatus.deleted) {
Navigator.of(context).pop();
_closeScreen();
return;
}
@@ -285,8 +332,29 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
if (state.justMarkedArrived) {
await _showArrivedLabelPrompt(state.order);
}
if (state.justMarkedDelivered && context.mounted) {
if (!context.canPop()) {
await _showDeliveredSuccessDialog(state.order);
return;
}
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(
'Ordine di ${state.order.customer?.name ?? 'Cliente'} segnato come consegnato!',
),
backgroundColor: Colors.green.shade700,
duration: const Duration(seconds: 3),
),
);
if (_closeAfterSave) {
_closeScreen();
}
return;
}
if (_closeAfterSave && context.mounted) {
Navigator.of(context).pop();
_closeScreen();
} else if (receiptResult == null && context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
@@ -340,9 +408,10 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
child: LayoutBuilder(
builder: (context, constraints) {
final isDesktop = constraints.maxWidth > 920;
final isMobile = constraints.maxWidth < 650;
return SingleChildScrollView(
padding: const EdgeInsets.all(16.0),
padding: EdgeInsets.all(isMobile ? 12.0 : 16.0),
child: Center(
child: ConstrainedBox(
constraints: BoxConstraints(
@@ -357,10 +426,10 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
padding: const EdgeInsets.only(
left: 4,
right: 4,
bottom: 12,
bottom: 10,
),
child: Wrap(
spacing: 20,
spacing: 16,
runSpacing: 4,
children: [
Text(
@@ -400,7 +469,12 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
(order.status == CustomerOrderStatus.arrived ||
order.status ==
CustomerOrderStatus.delivered))
_buildCassaCheckoutBanner(context, theme, order),
_buildCassaCheckoutBanner(
context,
theme,
order,
isMobile: isMobile,
),
if (isDesktop)
Row(
@@ -413,6 +487,7 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
context,
theme,
order,
isMobile: false,
),
_buildAttachmentsCard(context, order),
],
@@ -424,14 +499,26 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
context,
theme,
state,
isMobile: false,
),
),
],
)
else ...[
_buildOrderRequestCard(context, theme, order),
_buildManagementCard(context, theme, state),
_buildAttachmentsCard(context, order),
_buildOrderRequestCard(
context,
theme,
order,
isMobile: isMobile,
),
_buildManagementCard(
context,
theme,
state,
isMobile: isMobile,
),
if (!isMobile)
_buildAttachmentsCard(context, order),
],
],
),
@@ -443,7 +530,10 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
),
bottomNavigationBar: SafeArea(
child: Container(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.symmetric(
horizontal: 16.0,
vertical: 12.0,
),
decoration: BoxDecoration(
color: theme.scaffoldBackgroundColor,
boxShadow: [
@@ -473,8 +563,8 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
flex: 2,
child: FilledButton.icon(
style: FilledButton.styleFrom(
backgroundColor: order.status.color,
foregroundColor: Colors.white,
backgroundColor: theme.colorScheme.primary,
foregroundColor: theme.colorScheme.onPrimary,
padding: const EdgeInsets.symmetric(vertical: 14),
),
icon: state.status == CustomerOrderFormStatus.saving
@@ -510,8 +600,9 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
Widget _buildCassaCheckoutBanner(
BuildContext context,
ThemeData theme,
CustomerOrderModel order,
) {
CustomerOrderModel order, {
bool isMobile = false,
}) {
final currencyFmt = NumberFormat.currency(locale: 'it_IT', symbol: '€');
final livePrice = _parseAmount(_priceCtrl.text) > 0
? _parseAmount(_priceCtrl.text)
@@ -525,9 +616,105 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
: order.externalCode;
final isDelivered = order.status == CustomerOrderStatus.delivered;
final codeBox = Container(
width: isMobile ? double.infinity : null,
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: theme.dividerColor.withValues(alpha: 0.5),
),
),
child: Row(
mainAxisSize: isMobile ? MainAxisSize.max : MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: isMobile ? 1 : 0,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'CODICE DA BATTERE IN CASSA',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w800,
color: theme.colorScheme.onSurfaceVariant,
),
),
Text(
code.isNotEmpty ? code : 'Non inserito',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w900,
color: code.isNotEmpty
? theme.colorScheme.primary
: Colors.grey,
),
),
],
),
),
if (code.isNotEmpty) ...[
const SizedBox(width: 8),
IconButton(
tooltip: 'Copia codice cassa',
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.copy_rounded, size: 18),
onPressed: () {
Clipboard.setData(ClipboardData(text: code));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Codice "$code" copiato!'),
duration: const Duration(seconds: 2),
),
);
},
),
],
],
),
);
final priceBox = Container(
width: isMobile ? double.infinity : null,
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.teal.withValues(alpha: 0.4)),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
liveDeposit > 0
? 'DA INCASSARE (Prezzo ${currencyFmt.format(livePrice)} - Acconto ${currencyFmt.format(liveDeposit)})'
: 'PREZZO DA INCASSARE',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w800,
color: theme.colorScheme.onSurfaceVariant,
),
),
Text(
livePrice > 0
? currencyFmt.format(toPay)
: 'Prezzo non impostato',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w900,
color: Colors.teal.shade700,
),
),
],
),
);
return Container(
margin: const EdgeInsets.only(bottom: 20),
padding: const EdgeInsets.all(20),
margin: EdgeInsets.only(bottom: isMobile ? 14 : 20),
padding: EdgeInsets.all(isMobile ? 14 : 20),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: isDelivered
@@ -558,211 +745,198 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
? Icons.check_circle_rounded
: Icons.point_of_sale_rounded,
color: isDelivered ? Colors.green.shade700 : Colors.teal.shade700,
size: 26,
size: isMobile ? 22 : 26,
),
const SizedBox(width: 10),
Expanded(
child: Text(
isDelivered
? 'ORDINE GIÀ CONSEGNATO AL CLIENTE'
: 'RIEPILOGO CASSA & CONSEGNA AL CLIENTE',
: 'RIEPILOGO CASSA & CONSEGNA',
style: TextStyle(
fontWeight: FontWeight.w900,
fontSize: 14,
letterSpacing: 0.5,
fontSize: isMobile ? 13 : 14,
letterSpacing: 0.4,
color: isDelivered
? Colors.green.shade800
: Colors.teal.shade900,
),
),
),
OutlinedButton.icon(
icon: const Icon(Icons.qr_code_2_rounded, size: 18),
label: const Text('Etichetta QR'),
style: OutlinedButton.styleFrom(
visualDensity: VisualDensity.compact,
if (!isMobile)
OutlinedButton.icon(
icon: const Icon(Icons.qr_code_2_rounded, size: 18),
label: const Text('Etichetta QR'),
style: OutlinedButton.styleFrom(
visualDensity: VisualDensity.compact,
),
onPressed: () {
_flushControllersToCubit();
_printQrLabel(
context.read<CustomerOrderFormCubit>().state.order,
);
},
),
onPressed: () {
_flushControllersToCubit();
_printQrLabel(
context.read<CustomerOrderFormCubit>().state.order,
);
},
),
],
),
const Divider(height: 24),
Wrap(
spacing: 24,
runSpacing: 14,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
// Cliente
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'CLIENTE',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurfaceVariant,
),
),
Text(
order.customer?.name ?? 'Cliente sconosciuto',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w900,
),
),
],
Divider(height: isMobile ? 18 : 24),
if (isMobile) ...[
Text(
'CLIENTE',
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurfaceVariant,
),
// Codice Cassa copiabile
Container(
padding: const EdgeInsets.symmetric(
horizontal: 14,
vertical: 8,
),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: theme.dividerColor.withValues(alpha: 0.5),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'CODICE DA BATTERE IN CASSA',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w800,
color: theme.colorScheme.onSurfaceVariant,
),
),
Text(
code.isNotEmpty ? code : 'Non inserito',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w900,
color: code.isNotEmpty
? theme.colorScheme.primary
: Colors.grey,
),
),
],
),
if (code.isNotEmpty) ...[
const SizedBox(width: 8),
IconButton(
tooltip: 'Copia codice cassa',
visualDensity: VisualDensity.compact,
icon: const Icon(Icons.copy_rounded, size: 18),
onPressed: () {
Clipboard.setData(ClipboardData(text: code));
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Codice "$code" copiato!'),
duration: const Duration(seconds: 2),
),
);
},
),
],
],
),
Text(
order.customer?.name ?? 'Cliente sconosciuto',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w900,
),
),
if (order.productDescription.isNotEmpty) ...[
const SizedBox(height: 2),
Text(
order.quantity > 1
? '${order.productDescription} ×${order.quantity}'
: order.productDescription,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
fontWeight: FontWeight.w600,
),
),
// Prezzo & Da Saldare
Container(
padding: const EdgeInsets.symmetric(
horizontal: 14,
vertical: 8,
),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: Colors.teal.withValues(alpha: 0.4),
),
),
child: Column(
],
const SizedBox(height: 12),
codeBox,
const SizedBox(height: 10),
priceBox,
] else
Wrap(
spacing: 24,
runSpacing: 14,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
liveDeposit > 0
? 'DA INCASSARE (Prezzo ${currencyFmt.format(livePrice)} - Acconto ${currencyFmt.format(liveDeposit)})'
: 'PREZZO DA INCASSARE',
'CLIENTE',
style: TextStyle(
fontSize: 10,
fontWeight: FontWeight.w800,
fontSize: 11,
fontWeight: FontWeight.bold,
color: theme.colorScheme.onSurfaceVariant,
),
),
Text(
livePrice > 0
? currencyFmt.format(toPay)
: 'Prezzo non impostato',
style: TextStyle(
fontSize: 20,
order.customer?.name ?? 'Cliente sconosciuto',
style: theme.textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w900,
color: Colors.teal.shade700,
),
),
],
),
),
],
),
codeBox,
priceBox,
],
),
if (!isDelivered) ...[
const SizedBox(height: 16),
Wrap(
spacing: 10,
runSpacing: 10,
children: [
FilledButton.icon(
const SizedBox(height: 14),
if (isMobile) ...[
SizedBox(
width: double.infinity,
child: FilledButton.icon(
style: FilledButton.styleFrom(
backgroundColor: Colors.green.shade600,
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 14),
),
icon: const Icon(Icons.check_circle_outline_rounded),
label: const Text('Consegna al Cliente'),
label: const Text(
'Consegna al Cliente',
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
),
onPressed: () => _submitSave(
overrideStatus: CustomerOrderStatus.delivered,
closeAfter: true,
),
),
OutlinedButton.icon(
icon: order.contactPreference.buildIcon(size: 16),
label: Text(
order.customerNotified
? 'Ricontatta (${order.contactPreference.shortLabel})'
: 'Avvisa Cliente (${order.contactPreference.shortLabel})',
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: OutlinedButton.icon(
icon: order.contactPreference.buildIcon(size: 16),
label: Text(
order.customerNotified
? 'Ricontatta'
: 'Avvisa Cliente',
overflow: TextOverflow.ellipsis,
),
onPressed: () {
_flushControllersToCubit();
_launchCustomerContact(
context.read<CustomerOrderFormCubit>().state.order,
);
},
),
),
onPressed: () {
_flushControllersToCubit();
_launchCustomerContact(
context.read<CustomerOrderFormCubit>().state.order,
);
},
),
TextButton.icon(
style: TextButton.styleFrom(foregroundColor: Colors.red),
icon: const Icon(Icons.cancel_outlined, size: 18),
label: const Text('Annulla Ordine'),
onPressed: () => _submitSave(
overrideStatus: CustomerOrderStatus.cancelled,
closeAfter: true,
const SizedBox(width: 8),
TextButton.icon(
style: TextButton.styleFrom(foregroundColor: Colors.red),
icon: const Icon(Icons.cancel_outlined, size: 18),
label: const Text('Annulla'),
onPressed: () => _submitSave(
overrideStatus: CustomerOrderStatus.cancelled,
closeAfter: true,
),
),
),
],
),
],
),
] else
Wrap(
spacing: 10,
runSpacing: 10,
children: [
FilledButton.icon(
style: FilledButton.styleFrom(
backgroundColor: Colors.green.shade600,
foregroundColor: Colors.white,
),
icon: const Icon(Icons.check_circle_outline_rounded),
label: const Text('Consegna al Cliente'),
onPressed: () => _submitSave(
overrideStatus: CustomerOrderStatus.delivered,
closeAfter: true,
),
),
OutlinedButton.icon(
icon: order.contactPreference.buildIcon(size: 16),
label: Text(
order.customerNotified
? 'Ricontatta (${order.contactPreference.shortLabel})'
: 'Avvisa Cliente (${order.contactPreference.shortLabel})',
),
onPressed: () {
_flushControllersToCubit();
_launchCustomerContact(
context.read<CustomerOrderFormCubit>().state.order,
);
},
),
TextButton.icon(
style: TextButton.styleFrom(foregroundColor: Colors.red),
icon: const Icon(Icons.cancel_outlined, size: 18),
label: const Text('Annulla Ordine'),
onPressed: () => _submitSave(
overrideStatus: CustomerOrderStatus.cancelled,
closeAfter: true,
),
),
],
),
],
],
),
@@ -775,14 +949,65 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
Widget _buildOrderRequestCard(
BuildContext context,
ThemeData theme,
CustomerOrderModel order,
) {
CustomerOrderModel order, {
bool isMobile = false,
}) {
final dateFmt = DateFormat('dd/MM/yyyy');
final productField = TextFormField(
controller: _productCtrl,
decoration: const InputDecoration(
labelText: 'Prodotto richiesto *',
hintText: 'Es. Cover MagSafe iPhone 16 Pro Nera...',
prefixIcon: Icon(Icons.inventory_2_outlined),
),
validator: (val) => (val == null || val.trim().isEmpty)
? 'Inserisci cosa desidera ordinare il cliente'
: null,
);
final quantityStepper = Container(
decoration: BoxDecoration(
border: Border.all(
color: theme.dividerColor.withValues(alpha: 0.6),
),
borderRadius: BorderRadius.circular(10),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
tooltip: 'Riduci quantità',
icon: const Icon(Icons.remove, size: 18),
onPressed: order.quantity > 1
? () => context
.read<CustomerOrderFormCubit>()
.updateFields(quantity: order.quantity - 1)
: null,
),
Text(
'${order.quantity}',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
IconButton(
tooltip: 'Aumenta quantità',
icon: const Icon(Icons.add, size: 18),
onPressed: () => context
.read<CustomerOrderFormCubit>()
.updateFields(quantity: order.quantity + 1),
),
],
),
);
return _buildCard(
title: 'Richiesta Cliente',
icon: Icons.shopping_bag_outlined,
themeColor: Colors.indigo,
isMobile: isMobile,
headerTrailing: InkWell(
borderRadius: BorderRadius.circular(8),
onTap: () async {
@@ -881,61 +1106,30 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
const SizedBox(height: 18),
// Prodotto + Quantità
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: TextFormField(
controller: _productCtrl,
decoration: const InputDecoration(
labelText: 'Prodotto richiesto *',
hintText: 'Es. Cover MagSafe iPhone 16 Pro Nera...',
prefixIcon: Icon(Icons.inventory_2_outlined),
if (isMobile) ...[
productField,
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Quantità',
style: theme.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w600,
),
validator: (val) => (val == null || val.trim().isEmpty)
? 'Inserisci cosa desidera ordinare il cliente'
: null,
),
),
const SizedBox(width: 12),
Container(
decoration: BoxDecoration(
border: Border.all(
color: theme.dividerColor.withValues(alpha: 0.6),
),
borderRadius: BorderRadius.circular(10),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
tooltip: 'Riduci quantità',
icon: const Icon(Icons.remove, size: 18),
onPressed: order.quantity > 1
? () => context
.read<CustomerOrderFormCubit>()
.updateFields(quantity: order.quantity - 1)
: null,
),
Text(
'${order.quantity}',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
IconButton(
tooltip: 'Aumenta quantità',
icon: const Icon(Icons.add, size: 18),
onPressed: () => context
.read<CustomerOrderFormCubit>()
.updateFields(quantity: order.quantity + 1),
),
],
),
),
],
),
quantityStepper,
],
),
] else
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(child: productField),
const SizedBox(width: 12),
quantityStepper,
],
),
const SizedBox(height: 18),
// Modalità di Avviso Cliente
@@ -982,8 +1176,9 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
Widget _buildManagementCard(
BuildContext context,
ThemeData theme,
CustomerOrderFormState state,
) {
CustomerOrderFormState state, {
bool isMobile = false,
}) {
final order = state.order;
final dateTimeFmt = DateFormat('dd/MM/yyyy HH:mm');
@@ -991,6 +1186,7 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
title: 'Gestione Ordine, Etichette & Cassa',
icon: Icons.sell_outlined,
themeColor: Colors.teal,
isMobile: isMobile,
children: [
// Stato Ordine
Text(
@@ -1109,35 +1305,56 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
const SizedBox(height: 20),
// Codice Esterno (da battere in cassa) & Prezzo di vendita
Row(
children: [
Expanded(
child: TextFormField(
controller: _externalCodeCtrl,
decoration: const InputDecoration(
labelText: 'Codice Esterno (Cassa)',
hintText: 'Codice articolo...',
prefixIcon: Icon(Icons.qr_code_scanner_rounded),
),
onChanged: (_) => setState(() {}),
),
if (isMobile) ...[
TextFormField(
controller: _externalCodeCtrl,
decoration: const InputDecoration(
labelText: 'Codice Esterno (Cassa)',
hintText: 'Codice articolo...',
prefixIcon: Icon(Icons.qr_code_scanner_rounded),
),
const SizedBox(width: 12),
Expanded(
child: TextFormField(
controller: _priceCtrl,
keyboardType: const TextInputType.numberWithOptions(
decimal: true,
),
decoration: const InputDecoration(
labelText: 'Prezzo Vendita (€)',
prefixIcon: Icon(Icons.euro_rounded),
),
onChanged: (_) => setState(() {}),
),
onChanged: (_) => setState(() {}),
),
const SizedBox(height: 14),
TextFormField(
controller: _priceCtrl,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
decoration: const InputDecoration(
labelText: 'Prezzo Vendita (€)',
prefixIcon: Icon(Icons.euro_rounded),
),
],
),
onChanged: (_) => setState(() {}),
),
] else
Row(
children: [
Expanded(
child: TextFormField(
controller: _externalCodeCtrl,
decoration: const InputDecoration(
labelText: 'Codice Esterno (Cassa)',
hintText: 'Codice articolo...',
prefixIcon: Icon(Icons.qr_code_scanner_rounded),
),
onChanged: (_) => setState(() {}),
),
),
const SizedBox(width: 12),
Expanded(
child: TextFormField(
controller: _priceCtrl,
keyboardType: const TextInputType.numberWithOptions(
decimal: true,
),
decoration: const InputDecoration(
labelText: 'Prezzo Vendita (€)',
prefixIcon: Icon(Icons.euro_rounded),
),
onChanged: (_) => setState(() {}),
),
),
],
),
const SizedBox(height: 18),
// Sezione Avviso Cliente
@@ -1232,16 +1449,17 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
required Color themeColor,
required List<Widget> children,
Widget? headerTrailing,
bool isMobile = false,
}) {
return Card(
margin: const EdgeInsets.only(bottom: 20),
margin: EdgeInsets.only(bottom: isMobile ? 14 : 20),
elevation: 0,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: BorderSide(color: themeColor.withValues(alpha: 0.3), width: 1),
),
child: Padding(
padding: const EdgeInsets.all(20.0),
padding: EdgeInsets.all(isMobile ? 14.0 : 20.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@@ -1268,7 +1486,7 @@ class _CustomerOrderFormScreenState extends State<CustomerOrderFormScreen> {
?headerTrailing,
],
),
const Divider(height: 28),
Divider(height: isMobile ? 20 : 28),
...children,
],
),