4 Commits

Author SHA1 Message Date
marco 1ce55045a8 created minimal view to show tasks 2026-06-09 11:23:25 +02:00
marco a06870fbe5 added exampledata to test with 2026-06-09 11:23:08 +02:00
marco 38dc91fd5a added position field and copyWith constructor 2026-06-09 11:22:57 +02:00
marco 2d927b8aed created function to generate a unique id 2026-06-09 11:22:36 +02:00
5 changed files with 98 additions and 2 deletions
+9
View File
@@ -0,0 +1,9 @@
import 'model/task.dart';
import 'service/tools.dart' show generateId;
List<Task> tasks = [
Task(id: generateId(), title: 'Hund föhnen', position: 0),
Task(id: '${generateId()}1', title: 'Fuchs streicheln', position: 1),
Task(id: '${generateId()}2', title: 'Katze füttern', position: 2),
Task(id: '${generateId()}3', title: 'Bär kraulen', position: 3),
];
+5 -2
View File
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';
import 'model/pages/task_overview.dart';
void main() {
runApp(const MainApp());
}
@@ -9,8 +11,9 @@ class MainApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return const MaterialApp(
home: Scaffold(body: Center(child: Text('Hello World!'))),
return MaterialApp(
routes: {TaskOverview.routeName: (context) => TaskOverview()},
initialRoute: TaskOverview.routeName,
);
}
}
+51
View File
@@ -0,0 +1,51 @@
import 'package:flutter/material.dart';
import '../../example_data.dart';
import '../task.dart';
class TaskOverview extends StatefulWidget {
static const String routeName = '/';
const TaskOverview({super.key});
@override
State<TaskOverview> createState() => _TaskOverviewState();
}
class _TaskOverviewState extends State<TaskOverview> {
//TODO: Replace example data call
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: ReorderableListView.builder(
itemBuilder: itemBuilder,
itemCount: tasks.length,
onReorderItem: (oldIndex, newIndex) =>
reorderList(tasks, oldIndex, newIndex),
),
);
}
Widget itemBuilder(BuildContext context, int index) {
final task = tasks.elementAt(index);
return ListTile(
key: Key(task.id),
title: Text(task.title),
subtitle: Text(task.description),
);
}
List<Task> reorderList(List<Task> tasks, oldIndex, newIndex) {
final item = tasks.removeAt(oldIndex);
tasks.insert(newIndex, item);
final List<Task> reordered = [];
for (int i = 0; i < tasks.length; i++) {
reordered.add(tasks.elementAt(i).copyWith(position: i));
}
return reordered;
}
}
+32
View File
@@ -12,6 +12,7 @@ class Task {
final List<DateTime> alarms;
final Location? location;
final String url;
final int position;
Task({
required this.id,
@@ -25,5 +26,36 @@ class Task {
this.alarms = const [],
this.location,
this.url = '',
required this.position,
});
Task copyWith({
String? id,
String? title,
String? description,
DateTime? start,
DateTime? due,
bool? isCompleted,
String? category,
List<Task>? subtasks,
List<DateTime>? alarms,
Location? location,
String? url,
int? position,
}) {
return Task(
id: id ?? this.id,
title: title ?? this.title,
description: description ?? this.description,
start: start ?? this.start,
due: due ?? this.due,
isCompleted: isCompleted ?? this.isCompleted,
category: category ?? this.category,
subtasks: subtasks ?? this.subtasks,
alarms: alarms ?? this.alarms,
location: location ?? this.location,
url: url ?? this.url,
position: position ?? this.position,
);
}
}
+1
View File
@@ -0,0 +1 @@
String generateId() => DateTime.now().millisecondsSinceEpoch.toString();