created minimal view to show tasks
This commit is contained in:
+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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user