Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ce55045a8 | |||
| a06870fbe5 | |||
| 38dc91fd5a | |||
| 2d927b8aed |
@@ -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
@@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'model/pages/task_overview.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(const MainApp());
|
runApp(const MainApp());
|
||||||
}
|
}
|
||||||
@@ -9,8 +11,9 @@ class MainApp extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const MaterialApp(
|
return MaterialApp(
|
||||||
home: Scaffold(body: Center(child: Text('Hello World!'))),
|
routes: {TaskOverview.routeName: (context) => TaskOverview()},
|
||||||
|
initialRoute: TaskOverview.routeName,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@ class Task {
|
|||||||
final List<DateTime> alarms;
|
final List<DateTime> alarms;
|
||||||
final Location? location;
|
final Location? location;
|
||||||
final String url;
|
final String url;
|
||||||
|
final int position;
|
||||||
|
|
||||||
Task({
|
Task({
|
||||||
required this.id,
|
required this.id,
|
||||||
@@ -25,5 +26,36 @@ class Task {
|
|||||||
this.alarms = const [],
|
this.alarms = const [],
|
||||||
this.location,
|
this.location,
|
||||||
this.url = '',
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
String generateId() => DateTime.now().millisecondsSinceEpoch.toString();
|
||||||
Reference in New Issue
Block a user