This commit is contained in:
2026-05-14 12:07:05 +02:00
parent 3b3cfb5e43
commit 0f9616f19a
8 changed files with 410 additions and 100 deletions

View File

@@ -0,0 +1,132 @@
import 'package:flutter/material.dart';
import 'package:flux/features/tickets/models/ticket_model.dart';
Future<({TicketStatus status, String reason})?> showPauseTicketDialog(
BuildContext context,
) async {
return showDialog<({TicketStatus status, String reason})>(
context: context,
builder: (context) => const PauseTicketDialog(),
);
}
class PauseTicketDialog extends StatefulWidget {
const PauseTicketDialog({super.key});
@override
State<PauseTicketDialog> createState() => _PauseTicketDialogState();
}
class _PauseTicketDialogState extends State<PauseTicketDialog> {
final _reasonCtrl = TextEditingController();
// Partiamo con un default sensato
TicketStatus _selectedStatus = TicketStatus.waitingForParts;
@override
void dispose() {
_reasonCtrl.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Row(
children: [
Icon(Icons.pause_circle_outline, color: Colors.orange),
SizedBox(width: 8),
Text('Sospendi Lavorazione'),
],
),
content: SizedBox(
// Un po' di larghezza per i chips
width: double.maxFinite,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('Seleziona il motivo della sospensione:'),
const SizedBox(height: 16),
// --- SCELTA DELLO STATO (CHIPS) ---
Wrap(
spacing: 8.0,
runSpacing: 8.0,
children: [
ChoiceChip(
label: const Text('Attesa Ricambi'),
selected: _selectedStatus == TicketStatus.waitingForParts,
onSelected: (bool selected) {
if (selected) {
setState(
() => _selectedStatus = TicketStatus.waitingForParts,
);
}
},
),
ChoiceChip(
label: const Text('Attesa Preventivo'),
selected: _selectedStatus == TicketStatus.waitingForQuote,
onSelected: (bool selected) {
if (selected) {
setState(
() => _selectedStatus = TicketStatus.waitingForQuote,
);
}
},
),
ChoiceChip(
label: const Text('Attesa Cliente'),
selected: _selectedStatus == TicketStatus.waitingForCustomer,
onSelected: (bool selected) {
if (selected) {
setState(
() => _selectedStatus = TicketStatus.waitingForCustomer,
);
}
},
),
],
),
const SizedBox(height: 24),
const Text(
'Note aggiuntive (opzionali):',
style: TextStyle(fontSize: 12, color: Colors.grey),
),
const SizedBox(height: 8),
// --- NOTE AGGIUNTIVE ---
TextField(
controller: _reasonCtrl,
maxLines: 2,
decoration: const InputDecoration(
hintText: 'Es: Il fornitore consegna martedì...',
border: OutlineInputBorder(),
),
),
],
),
),
actions: [
TextButton(
onPressed: () =>
Navigator.of(context).pop(), // Ritorna null (Annulla)
child: const Text('Annulla'),
),
FilledButton(
style: FilledButton.styleFrom(
backgroundColor: Colors.orange.shade700,
),
onPressed: () {
// RITORNIAMO IL RECORD CON STATO E NOTE!
Navigator.of(
context,
).pop((status: _selectedStatus, reason: _reasonCtrl.text.trim()));
},
child: const Text('Conferma Pausa'),
),
],
);
}
}

View File

@@ -0,0 +1,302 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flux/features/tickets/blocs/ticket_form_cubit.dart';
import 'package:flux/features/tickets/blocs/ticket_form_state.dart';
import 'package:flux/features/tickets/models/ticket_model.dart';
import 'package:flux/features/tickets/ui/ticket_workspace/pause_ticket_dialog.dart';
class TicketWorkspaceScreen extends StatelessWidget {
const TicketWorkspaceScreen({super.key});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Scaffold(
appBar: AppBar(
title: const Text('Banco di Lavoro'),
//backgroundColor: theme.colorScheme.inversePrimary,
centerTitle: true,
),
// SafeArea in basso per ospitare i bottoni fissi
bottomNavigationBar: SafeArea(child: _buildBottomActions(context)),
body: SingleChildScrollView(
padding: const EdgeInsets.all(24.0),
child: BlocBuilder<TicketFormCubit, TicketFormState>(
builder: (context, state) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildDeviceHeader(theme, state.ticket),
const SizedBox(height: 24),
_buildDefectRecap(theme, state.ticket),
const SizedBox(height: 32),
_buildOperationsSection(theme, state.ticket),
],
);
},
),
),
);
}
// --- 1. HEADER DISPOSITIVO E PASSWORD ---
Widget _buildDeviceHeader(ThemeData theme, TicketModel ticket) {
bool hasTargetPw =
((ticket.targetPassword != null && ticket.targetPassword!.isNotEmpty));
bool hasSourcePw =
((ticket.sourcePassword != null && ticket.sourcePassword!.isNotEmpty));
return Card(
elevation: 0,
color: theme.colorScheme.primaryContainer.withValues(alpha: 0.4),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: BorderSide(
color: theme.colorScheme.primary.withValues(alpha: 0.2),
),
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'DISPOSITIVO IN LAVORAZIONE',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: theme.colorScheme.primary,
letterSpacing: 1.2,
),
),
const SizedBox(height: 8),
Text(
ticket.targetModelName ??
'Modello Sconosciuto', // Es: "iPhone 13 Pro"
style: const TextStyle(
fontSize: 24,
fontWeight: FontWeight.w800,
),
),
],
),
),
if (hasSourcePw || hasTargetPw) ...[
Wrap(
spacing: 12,
runSpacing: 12,
children: [
if (hasTargetPw)
Container(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: theme.dividerColor),
),
child: Column(
children: [
const Text(
'PIN / SBLOCCO Target device',
style: TextStyle(fontSize: 10, color: Colors.grey),
),
const SizedBox(height: 4),
Text(
ticket.targetPassword ?? '',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
letterSpacing: 2,
),
),
],
),
),
if (hasSourcePw)
Container(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 12,
),
decoration: BoxDecoration(
color: theme.colorScheme.surface,
borderRadius: BorderRadius.circular(12),
border: Border.all(color: theme.dividerColor),
),
child: Column(
children: [
const Text(
'PIN / SBLOCCO Source device',
style: TextStyle(fontSize: 10, color: Colors.grey),
),
const SizedBox(height: 4),
Text(
ticket.sourcePassword ?? '',
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
letterSpacing: 2,
),
),
],
),
),
],
),
],
],
),
),
);
}
// --- 2. RECAP DIFETTO ---
Widget _buildDefectRecap(ThemeData theme, TicketModel ticket) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Row(
children: [
Icon(Icons.warning_amber_rounded, color: Colors.orange),
SizedBox(width: 8),
Text(
'Difetto Segnalato',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
],
),
const SizedBox(height: 12),
Container(
width: double.infinity,
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHighest.withValues(
alpha: 0.3,
),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: theme.dividerColor),
),
child: Text(
ticket.request,
style: const TextStyle(fontSize: 16, height: 1.5),
),
),
],
);
}
// --- 3. SEZIONE COSTI E RICAMBI (Mockup) ---
Widget _buildOperationsSection(ThemeData theme, TicketModel ticket) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text(
'Ricambi e Manodopera',
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
),
TextButton.icon(
onPressed: () {
// TODO: Apri modal per aggiungere una riga di costo
},
icon: const Icon(Icons.add),
label: const Text('Aggiungi Voce'),
),
],
),
const SizedBox(height: 12),
// Qui ci andrà un ListView.builder collegato alla tabella dei costi/operazioni
Container(
padding: const EdgeInsets.all(32),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: theme.dividerColor,
style: BorderStyle.solid,
),
),
child: const Center(
child: Text(
'Nessun ricambio o costo inserito.\nClicca su "Aggiungi Voce" per iniziare.',
textAlign: TextAlign.center,
style: TextStyle(color: Colors.grey),
),
),
),
],
);
}
// --- 4. BOTTONI AZIONE FINALI (In basso) ---
Widget _buildBottomActions(BuildContext context) {
return Container(
padding: const EdgeInsets.all(16.0),
decoration: BoxDecoration(
color: Theme.of(context).scaffoldBackgroundColor,
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.05),
blurRadius: 10,
offset: const Offset(0, -5),
),
],
),
child: Row(
children: [
// Bottone Pausa
Expanded(
flex: 1,
child: OutlinedButton.icon(
// ... stile del bottone ...
onPressed: () async {
// 1. Apriamo la modale e riceviamo il RECORD
final result = await showPauseTicketDialog(context);
// 2. Se l'utente ha confermato...
if (result != null && context.mounted) {
// 3. Lanciamo l'azione passando lo stato esatto e le note
await context.read<TicketFormCubit>().pauseTicket(
newStatus: result.status,
notes: result.reason,
);
// 4. Riportiamo l'utente alla dashboard
if (context.mounted) Navigator.of(context).pop();
}
},
icon: const Icon(Icons.pause),
label: const Text('Metti in Pausa'),
),
),
// Bottone Completa
Expanded(
flex: 2,
child: FilledButton.icon(
style: FilledButton.styleFrom(
padding: const EdgeInsets.symmetric(vertical: 16),
backgroundColor: Colors.green.shade600,
),
onPressed: () {
// TODO: Logica Completa Riparazione
},
icon: const Icon(Icons.check_circle_outline),
label: const Text(
'COMPLETA RIPARAZIONE',
style: TextStyle(fontWeight: FontWeight.bold, letterSpacing: 1),
),
),
),
],
),
);
}
}