- Flutter frontend with Provider state management - FastAPI backend with SQLAlchemy ORM - Internationalization support (EN/DE) - Clean Architecture folder structure - GoRouter for navigation - GetIt for dependency injection
134 lines
4.3 KiB
Dart
134 lines
4.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_gen/gen_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,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
IconButton(
|
|
icon: const Icon(Icons.schedule),
|
|
onPressed: onReschedule,
|
|
tooltip: l10n.rescheduleToTomorrow,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|