fix operations e tasks
This commit is contained in:
@@ -58,6 +58,7 @@ class TaskFormCubit extends Cubit<TaskFormState> {
|
||||
dueDate: task.dueDate,
|
||||
isGlobal: task.isGlobal, // Sfrutta il tuo getter storeId == null
|
||||
selectedStaffIds: task.assignedToIds,
|
||||
taskStatus: task.status,
|
||||
),
|
||||
);
|
||||
await _loadExistingTaskReminders(task.id!);
|
||||
@@ -272,6 +273,10 @@ class TaskFormCubit extends Cubit<TaskFormState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> updateTaskLocalStatus(TaskStatus newStatus) async {
|
||||
emit(state.copyWith(taskStatus: newStatus));
|
||||
}
|
||||
|
||||
Future<void> updateTaskStatus(TaskStatus newStatus) async {
|
||||
try {
|
||||
// Chiamiamo il repo passando il task aggiornato
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/core/utils/extensions.dart';
|
||||
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||
import 'package:flux/features/tasks/models/task_status.dart';
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
enum TaskStatus { open, inProgress, completed }
|
||||
|
||||
extension TaskStatusExtension on TaskStatus {
|
||||
String get name {
|
||||
String get displayName {
|
||||
switch (this) {
|
||||
case TaskStatus.open:
|
||||
return 'Da Iniziare';
|
||||
|
||||
@@ -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