m3mo 864560ef2e Fix calendar navigation, task deletion, and language defaults
- Add date parameter support to DailyAgendaPage for calendar navigation
- Add popup menu to task tile with delete and reschedule options
- Set default locale to English when none is saved
- Update API base URL comment for desktop vs Android
2026-02-02 21:07:27 +01:00

179 lines
6.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:agenda_tasks/l10n/app_localizations.dart';
import '../../domain/entities/task_entity.dart';
import '../../domain/enums/priority.dart';
class TaskTile extends StatelessWidget {
final TaskEntity task;
final VoidCallback onToggle;
final VoidCallback onTap;
final VoidCallback onDelete;
final VoidCallback onReschedule;
const TaskTile({
super.key,
required this.task,
required this.onToggle,
required this.onTap,
required this.onDelete,
required this.onReschedule,
});
Color _getPriorityColor(Priority priority, BuildContext context) {
switch (priority) {
case Priority.high:
return Colors.red.shade700;
case Priority.medium:
return Colors.orange.shade700;
case Priority.low:
return Colors.green.shade700;
}
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!;
final priorityColor = _getPriorityColor(task.priority, context);
return Dismissible(
key: Key(task.id),
direction: DismissDirection.endToStart,
background: Container(
alignment: Alignment.centerRight,
padding: const EdgeInsets.only(right: 20),
color: Theme.of(context).colorScheme.error,
child: Icon(
Icons.delete,
color: Theme.of(context).colorScheme.onError,
),
),
confirmDismiss: (_) async {
return await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(l10n.deleteTask),
content: Text(l10n.deleteTaskConfirm),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: Text(l10n.cancel),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: Text(l10n.delete),
),
],
),
) ?? false;
},
onDismissed: (_) => onDelete(),
child: Card(
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Padding(
padding: const EdgeInsets.all(12),
child: Row(
children: [
Container(
width: 4,
height: 48,
decoration: BoxDecoration(
color: priorityColor,
borderRadius: BorderRadius.circular(2),
),
),
const SizedBox(width: 12),
Checkbox(
value: task.isDone,
onChanged: (_) => onToggle(),
),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
task.title,
style: Theme.of(context).textTheme.titleMedium?.copyWith(
decoration: task.isDone
? TextDecoration.lineThrough
: null,
color: task.isDone
? Theme.of(context).colorScheme.outline
: null,
),
),
if (task.description != null && task.description!.isNotEmpty)
Text(
task.description!,
style: Theme.of(context).textTheme.bodySmall?.copyWith(
color: Theme.of(context).colorScheme.outline,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
PopupMenuButton<String>(
onSelected: (value) async {
if (value == 'reschedule') {
onReschedule();
} else if (value == 'delete') {
final confirm = await showDialog<bool>(
context: context,
builder: (context) => AlertDialog(
title: Text(l10n.deleteTask),
content: Text(l10n.deleteTaskConfirm),
actions: [
TextButton(
onPressed: () => Navigator.pop(context, false),
child: Text(l10n.cancel),
),
TextButton(
onPressed: () => Navigator.pop(context, true),
child: Text(l10n.delete),
),
],
),
);
if (confirm == true) {
onDelete();
}
}
},
itemBuilder: (context) => [
PopupMenuItem(
value: 'reschedule',
child: Row(
children: [
const Icon(Icons.schedule),
const SizedBox(width: 8),
Text(l10n.rescheduleToTomorrow),
],
),
),
PopupMenuItem(
value: 'delete',
child: Row(
children: [
Icon(Icons.delete, color: Theme.of(context).colorScheme.error),
const SizedBox(width: 8),
Text(l10n.delete, style: TextStyle(color: Theme.of(context).colorScheme.error)),
],
),
),
],
),
],
),
),
),
),
);
}
}