refinements
This commit is contained in:
@@ -141,6 +141,55 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// Formatta in "GG/MM/AAAA HH:MM"
|
||||
String _formatDateTime(DateTime dt) {
|
||||
return "${dt.day.toString().padLeft(2, '0')}/${dt.month.toString().padLeft(2, '0')}/${dt.year} ${dt.hour.toString().padLeft(2, '0')}:${dt.minute.toString().padLeft(2, '0')}";
|
||||
}
|
||||
|
||||
// Lancia i popup di Data e poi di Ora
|
||||
Future<void> _selectDeliveryDate(
|
||||
BuildContext context,
|
||||
TicketModel ticket,
|
||||
) async {
|
||||
final initialDate = ticket.estimatedDeliveryAt ?? DateTime.now();
|
||||
|
||||
// 1. Chiediamo la Data
|
||||
final pickedDate = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: initialDate,
|
||||
firstDate: DateTime(
|
||||
2020,
|
||||
), // Oppure DateTime.now() se non vuoi date passate
|
||||
lastDate: DateTime(2100),
|
||||
);
|
||||
|
||||
if (pickedDate == null) return; // L'utente ha annullato
|
||||
|
||||
// 2. Chiediamo l'Ora
|
||||
if (!context.mounted) return;
|
||||
final pickedTime = await showTimePicker(
|
||||
context: context,
|
||||
initialTime: TimeOfDay.fromDateTime(initialDate),
|
||||
);
|
||||
|
||||
if (pickedTime == null) return; // L'utente ha annullato
|
||||
|
||||
// 3. Fondiamo Data e Ora in un unico DateTime
|
||||
final finalDateTime = DateTime(
|
||||
pickedDate.year,
|
||||
pickedDate.month,
|
||||
pickedDate.day,
|
||||
pickedTime.hour,
|
||||
pickedTime.minute,
|
||||
);
|
||||
|
||||
// 4. Aggiorniamo il Cubit
|
||||
if (!context.mounted) return;
|
||||
context.read<TicketFormCubit>().updateFields(
|
||||
estimatedDeliveryAt: finalDateTime,
|
||||
);
|
||||
}
|
||||
|
||||
Future<String?> _generateIdForQr() async {
|
||||
// 1. Validiamo i campi obbligatori (es. il cliente)
|
||||
if (!_formKey.currentState!.validate()) return null;
|
||||
@@ -817,6 +866,37 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
readOnly: true, // MAGIA: Impedisce l'apertura della tastiera
|
||||
// Creiamo un controller "al volo" solo per mostrargli la stringa
|
||||
controller: TextEditingController(
|
||||
text: ticket.estimatedDeliveryAt != null
|
||||
? _formatDateTime(ticket.estimatedDeliveryAt!)
|
||||
: '',
|
||||
),
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Riconsegna prevista (Data e Ora)',
|
||||
prefixIcon: const Icon(Icons.event_available),
|
||||
// Bottone con la X per rimuovere la data se il cliente ti dice "fai con calma"
|
||||
suffixIcon: ticket.estimatedDeliveryAt != null
|
||||
? IconButton(
|
||||
icon: const Icon(Icons.clear),
|
||||
onPressed: () {
|
||||
// NOTA: Dovrai assicurarti che il tuo Cubit gestisca il reset.
|
||||
// O passi un flag come clearEstimatedDelivery: true,
|
||||
// o gestisci il null se il tuo updateFields lo permette.
|
||||
context.read<TicketFormCubit>().updateFields(
|
||||
clearEstimatedDelivery:
|
||||
true, // Esempio di flag da aggiungere nel Cubit
|
||||
);
|
||||
},
|
||||
)
|
||||
: null,
|
||||
),
|
||||
// Quando tappi il campo di testo, partono i calendari
|
||||
onTap: () => _selectDeliveryDate(context, ticket),
|
||||
),
|
||||
if (ticket.ticketType == TicketType.repair) ...[
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<WarrantyType>(
|
||||
|
||||
Reference in New Issue
Block a user