Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 410a7eb843 | |||
| 20b017b066 |
@@ -22,7 +22,12 @@ class LocalRepository
|
|||||||
if (_prefs == null) {
|
if (_prefs == null) {
|
||||||
await SharedPreferencesWithCache.create(
|
await SharedPreferencesWithCache.create(
|
||||||
cacheOptions: const SharedPreferencesWithCacheOptions(
|
cacheOptions: const SharedPreferencesWithCacheOptions(
|
||||||
allowList: <String>{_tasksKey, _taskOrderKey},
|
allowList: <String>{
|
||||||
|
_tasksKey,
|
||||||
|
_taskOrderKey,
|
||||||
|
_alarmsKey,
|
||||||
|
_locationsKey,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
).then((value) => _prefs = value);
|
).then((value) => _prefs = value);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import '../model/extensions/controller_context.dart';
|
|||||||
import '../model/task.dart';
|
import '../model/task.dart';
|
||||||
import '../service/controllers/task_controller.dart';
|
import '../service/controllers/task_controller.dart';
|
||||||
import '../service/tools.dart';
|
import '../service/tools.dart';
|
||||||
|
import '../widgets/task_dismissible.dart';
|
||||||
import 'task_edit_page.dart';
|
import 'task_edit_page.dart';
|
||||||
|
|
||||||
class TaskOverviewPage extends StatefulWidget {
|
class TaskOverviewPage extends StatefulWidget {
|
||||||
@@ -37,24 +38,28 @@ class _TaskOverviewPageState extends State<TaskOverviewPage> {
|
|||||||
Widget itemBuilder(BuildContext context, int index) {
|
Widget itemBuilder(BuildContext context, int index) {
|
||||||
final task = tasks.elementAt(index);
|
final task = tasks.elementAt(index);
|
||||||
|
|
||||||
return ListTile(
|
return TaskDismissible(
|
||||||
key: Key(task.id),
|
key: Key(task.id),
|
||||||
title: Text(task.title),
|
onDismissedRight: () =>
|
||||||
subtitle: task.description.isNotEmpty ? Text(task.description) : null,
|
context.controller<TaskController>().deleteTask(task),
|
||||||
trailing: Checkbox(
|
child: ListTile(
|
||||||
value: task.isCompleted,
|
title: Text(task.title),
|
||||||
onChanged: (isCompleted) => context
|
subtitle: task.description.isNotEmpty ? Text(task.description) : null,
|
||||||
.controller<TaskController>()
|
trailing: Checkbox(
|
||||||
.saveTask(task.copyWith(isCompleted: isCompleted)),
|
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),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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!();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user