111 lines
3.3 KiB
Dart
111 lines
3.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../model/callback_models/create_task_request.dart';
|
|
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 'locations_overview_page.dart';
|
|
import 'task_edit_page.dart';
|
|
|
|
class TaskOverviewPage extends StatefulWidget {
|
|
static const String routeName = '/';
|
|
const TaskOverviewPage({super.key});
|
|
|
|
@override
|
|
State<TaskOverviewPage> createState() => _TaskOverviewPageState();
|
|
}
|
|
|
|
class _TaskOverviewPageState extends State<TaskOverviewPage> {
|
|
List<Task> get tasks => context.controller<TaskController>().orderedTasks;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Text('Hallo Yannick'),
|
|
actions: [
|
|
PopupMenuButton(
|
|
itemBuilder: (_) => [
|
|
PopupMenuItem(
|
|
onTap: onLocationsButtonTapped,
|
|
child: Text('Locations'),
|
|
),
|
|
],
|
|
icon: Icon(Icons.more_vert),
|
|
),
|
|
],
|
|
),
|
|
body: Padding(
|
|
padding: EdgeInsetsGeometry.symmetric(
|
|
horizontal: MediaQuery.of(context).size.width * 0.05,
|
|
),
|
|
child: ReorderableListView.builder(
|
|
itemBuilder: itemBuilder,
|
|
itemCount: tasks.length,
|
|
onReorderItem: context.controller<TaskController>().reorderTask,
|
|
),
|
|
),
|
|
floatingActionButton: FloatingActionButton(
|
|
onPressed: onCreateTaskTapped,
|
|
child: Icon(Icons.add),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget itemBuilder(BuildContext context, int index) {
|
|
final task = tasks.elementAt(index);
|
|
|
|
return Padding(
|
|
key: Key(task.id),
|
|
padding: const EdgeInsets.only(bottom: 12),
|
|
child: TaskDismissible(
|
|
key: Key(task.id),
|
|
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),
|
|
);
|
|
}
|
|
},
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<CreateTaskRequest?> onTaskTapped(Task task) async {
|
|
final result = await Navigator.of(
|
|
context,
|
|
).pushNamed(TaskEditPage.routeName, arguments: task);
|
|
return result as CreateTaskRequest?;
|
|
}
|
|
|
|
void onCreateTaskTapped() async {
|
|
final result =
|
|
await Navigator.of(context).pushNamed(TaskEditPage.routeName)
|
|
as CreateTaskRequest?;
|
|
|
|
if (result != null && mounted) {
|
|
context.controller<TaskController>().saveTask(
|
|
result.toTask(id: generateId()),
|
|
);
|
|
}
|
|
}
|
|
|
|
void onLocationsButtonTapped() =>
|
|
Navigator.of(context).pushNamed(LocationsOverviewPage.routeName);
|
|
}
|