2 Commits

Author SHA1 Message Date
marco 410a7eb843 made tasks dismissible 2026-06-19 00:35:20 +02:00
marco 20b017b066 added alarmkey and locationkey to allowlist 2026-06-19 00:21:34 +02:00
3 changed files with 68 additions and 17 deletions
+6 -1
View File
@@ -22,7 +22,12 @@ class LocalRepository
if (_prefs == null) {
await SharedPreferencesWithCache.create(
cacheOptions: const SharedPreferencesWithCacheOptions(
allowList: <String>{_tasksKey, _taskOrderKey},
allowList: <String>{
_tasksKey,
_taskOrderKey,
_alarmsKey,
_locationsKey,
},
),
).then((value) => _prefs = value);
}
+21 -16
View File
@@ -5,6 +5,7 @@ import '../model/extensions/controller_context.dart';
import '../model/task.dart';
import '../service/controllers/task_controller.dart';
import '../service/tools.dart';
import '../widgets/task_dismissible.dart';
import 'task_edit_page.dart';
class TaskOverviewPage extends StatefulWidget {
@@ -37,24 +38,28 @@ class _TaskOverviewPageState extends State<TaskOverviewPage> {
Widget itemBuilder(BuildContext context, int index) {
final task = tasks.elementAt(index);
return ListTile(
return TaskDismissible(
key: Key(task.id),
title: Text(task.title),
subtitle: task.description.isNotEmpty ? Text(task.description) : null,
trailing: Checkbox(
value: task.isCompleted,
onChanged: (isCompleted) => context
.controller<TaskController>()
.saveTask(task.copyWith(isCompleted: isCompleted)),
onDismissedRight: () =>
context.controller<TaskController>().deleteTask(task),
child: ListTile(
title: Text(task.title),
subtitle: task.description.isNotEmpty ? Text(task.description) : null,
trailing: Checkbox(
value: task.isCompleted,
onChanged: (isCompleted) => context
.controller<TaskController>()
.saveTask(task.copyWith(isCompleted: isCompleted)),
),
onTap: () async {
final result = await onTaskTapped(task);
if (result != null && context.mounted) {
context.controller<TaskController>().saveTask(
result.toTask(id: task.id),
);
}
},
),
onTap: () async {
final result = await onTaskTapped(task);
if (result != null && context.mounted) {
context.controller<TaskController>().saveTask(
result.toTask(id: task.id),
);
}
},
);
}
+41
View File
@@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
class TaskDismissible extends StatelessWidget {
const TaskDismissible({
required super.key,
this.onDismissedRight,
required this.child,
});
final VoidCallback? onDismissedRight;
final Widget child;
@override
Widget build(BuildContext context) {
return Dismissible(
key: key!,
direction: DismissDirection.startToEnd,
background: Container(
color: Theme.of(context).colorScheme.error,
child: Align(
alignment: AlignmentGeometry.centerLeft,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Icon(
Icons.delete,
color: Theme.of(context).colorScheme.onError,
),
),
),
),
onDismissed: onDismissed,
child: child,
);
}
void onDismissed(DismissDirection direction) {
if (direction == DismissDirection.startToEnd && onDismissedRight != null) {
onDismissedRight!();
}
}
}