fix operations e tasks
This commit is contained in:
@@ -124,6 +124,30 @@ class _TaskFormScreenState extends State<TaskFormScreen> {
|
||||
appBar: AppBar(
|
||||
title: Text(isEditing ? 'Modifica Task' : 'Nuovo Task'),
|
||||
actions: [
|
||||
// 🥷 1. BOTTONE COMPLETAMENTO RAPIDO (Solo se in edit e non già completato)
|
||||
if (isEditing && state.taskStatus != TaskStatus.completed)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8.0,
|
||||
vertical: 8.0,
|
||||
),
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
context.read<TaskFormCubit>().updateTaskStatus(
|
||||
TaskStatus.completed,
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.check_circle_outline),
|
||||
label: const Text('Completa'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.green.shade600,
|
||||
foregroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// 🥷 2. LOADER O BOTTONE SALVA
|
||||
if (state.status == TaskFormStatus.submitting)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(16.0),
|
||||
@@ -134,13 +158,18 @@ class _TaskFormScreenState extends State<TaskFormScreen> {
|
||||
),
|
||||
)
|
||||
else
|
||||
TextButton.icon(
|
||||
onPressed: state.isFormValid ? () => cubit.saveTask() : null,
|
||||
icon: const Icon(Icons.save),
|
||||
label: const Text('Salva'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: Colors.orange,
|
||||
disabledForegroundColor: Colors.grey,
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: TextButton.icon(
|
||||
onPressed: state.isFormValid
|
||||
? () => cubit.saveTask()
|
||||
: null,
|
||||
icon: const Icon(Icons.save),
|
||||
label: const Text('Salva'),
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: Colors.orange,
|
||||
disabledForegroundColor: Colors.grey,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -183,43 +212,6 @@ class _TaskFormScreenState extends State<TaskFormScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
if (state.id != null &&
|
||||
state.taskStatus != TaskStatus.completed)
|
||||
Container(
|
||||
margin: const EdgeInsets.only(bottom: 24.0),
|
||||
width: double.infinity,
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
// Chiama direttamente l'update immediato nel DB!
|
||||
context
|
||||
.read<TaskFormCubit>()
|
||||
.updateTaskStatus(TaskStatus.completed);
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.check_circle_outline,
|
||||
size: 28,
|
||||
),
|
||||
label: const Text(
|
||||
'Segna come Completato',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.green.shade600,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 16,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
elevation: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(height: 30),
|
||||
_buildFormFields(context, state, cubit),
|
||||
const SizedBox(height: 30),
|
||||
ElevatedButton.icon(
|
||||
@@ -302,6 +294,45 @@ class _TaskFormScreenState extends State<TaskFormScreen> {
|
||||
),
|
||||
onChanged: cubit.updateDescription,
|
||||
),
|
||||
if (state.id != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<TaskStatus>(
|
||||
// Leggiamo lo stato attuale dal Cubit (o usiamo un default per i nuovi task)
|
||||
initialValue: state.taskStatus,
|
||||
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Stato Attuale',
|
||||
prefixIcon: const Icon(Icons.flag_outlined),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
filled: true,
|
||||
fillColor: Theme.of(context).colorScheme.surface,
|
||||
),
|
||||
|
||||
// Mappiamo tutti i valori dell'enum in elementi della tendina
|
||||
items: TaskStatus.values.map((TaskStatus status) {
|
||||
return DropdownMenuItem<TaskStatus>(
|
||||
value: status,
|
||||
child: Text(
|
||||
status
|
||||
.displayName, // Usa la property displayName del tuo enum!
|
||||
style: TextStyle(
|
||||
fontWeight: status == state.taskStatus
|
||||
? FontWeight.bold
|
||||
: FontWeight.normal,
|
||||
),
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
|
||||
onChanged: (TaskStatus? newStatus) {
|
||||
if (newStatus != null && newStatus != state.taskStatus) {
|
||||
context.read<TaskFormCubit>().updateTaskStatus(newStatus);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// --- SCADENZA ---
|
||||
|
||||
Reference in New Issue
Block a user