200 lines
6.6 KiB
Dart
200 lines
6.6 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
import '../buisness/ToDoItem.dart';
|
|
import '../buisness/ToDoProvider.dart';
|
|
import 'ToDoExpandableWidget.dart';
|
|
|
|
class ToDoListScreen extends StatelessWidget {
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.grey[900],
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.deepOrange[800],
|
|
title: const Text('To-Do List'),
|
|
titleSpacing: 150.0,
|
|
),
|
|
body: Consumer<ToDoProvider>(
|
|
builder: (context, toDoProvider, child) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: ListView(
|
|
children: toDoProvider.toDoList.map((todo) {
|
|
return ToDoExpandableWidget(
|
|
toDoItem: todo,
|
|
id: todo.id!,
|
|
);
|
|
},
|
|
).toList()
|
|
),
|
|
);
|
|
}
|
|
),
|
|
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
|
|
floatingActionButton: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
// Sortier-Button unten links
|
|
FloatingActionButton(
|
|
onPressed: () => _showSortOptions(context),
|
|
backgroundColor: Colors.orange,
|
|
heroTag: null,
|
|
child: const Icon(Icons.sort), // Damit beide Floating Buttons keine Konflikte haben
|
|
),
|
|
// Hinzufügen-Button unten rechts
|
|
FloatingActionButton(
|
|
onPressed: () => _showAddToDoDialog(context),
|
|
child: const Icon(Icons.add),
|
|
backgroundColor: Colors.orange,
|
|
heroTag: null, // Damit beide Floating Buttons keine Konflikte haben
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
// Sortier-Menü anzeigen
|
|
void _showSortOptions(BuildContext context) {
|
|
showModalBottomSheet(
|
|
backgroundColor: Colors.orange,
|
|
context: context,
|
|
builder: (context) {
|
|
return Wrap(
|
|
children: [
|
|
ListTile(
|
|
leading: const Icon(Icons.text_fields),
|
|
title: const Text('Sort by Name'),
|
|
onTap: () {
|
|
Provider.of<ToDoProvider>(context, listen: false).sortByName();
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.date_range),
|
|
title: const Text('Sort by Due Date'),
|
|
onTap: () {
|
|
Provider.of<ToDoProvider>(context, listen: false).sortByDueDate();
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
ListTile(
|
|
leading: const Icon(Icons.flag),
|
|
title: const Text('Sort by Status'),
|
|
onTap: () {
|
|
Provider.of<ToDoProvider>(context, listen: false).sortByStatus();
|
|
Navigator.pop(context);
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
// Hinzufügen eines neuen ToDos (Dialog)
|
|
void _showAddToDoDialog(BuildContext context) {
|
|
String name = '';
|
|
String description = '';
|
|
DateTime? dueDate;
|
|
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) {
|
|
return AlertDialog(
|
|
backgroundColor: Colors.grey[700],
|
|
insetPadding: EdgeInsets.zero,
|
|
title: const Text('Add To-Do'),
|
|
content: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.only(bottom: 8.0),
|
|
child: TextField(
|
|
decoration: const InputDecoration(labelText: 'Name', filled: true),
|
|
onChanged: (value) {
|
|
name = value;
|
|
},
|
|
),
|
|
),
|
|
TextField(
|
|
decoration: const InputDecoration(labelText: 'Description', filled: true),
|
|
onChanged: (value) {
|
|
description = value;
|
|
},
|
|
),
|
|
const SizedBox(height: 10),
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(top: 16.0),
|
|
child: ElevatedButton(
|
|
style: const ButtonStyle(
|
|
backgroundColor: WidgetStatePropertyAll<Color>(Colors.orange),
|
|
),
|
|
onPressed: () async {
|
|
DateTime? picked = await showDatePicker(
|
|
context: context,
|
|
initialDate: DateTime.now(),
|
|
firstDate: DateTime(2000),
|
|
lastDate: DateTime(2101),
|
|
);
|
|
if (picked != null) dueDate = picked;
|
|
},
|
|
child: const Text('Pick Due Date'),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
|
children: [
|
|
Expanded(
|
|
child: TextButton(
|
|
style: const ButtonStyle(
|
|
backgroundColor: WidgetStatePropertyAll<Color>(Colors.red),
|
|
),
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Cancel'),
|
|
),
|
|
),
|
|
const SizedBox(
|
|
width: 16,
|
|
),
|
|
Expanded(
|
|
child: ElevatedButton(
|
|
style: const ButtonStyle(
|
|
backgroundColor: WidgetStatePropertyAll<Color>(Colors.green),
|
|
),
|
|
onPressed: () {
|
|
if (name.isNotEmpty && description.isNotEmpty && dueDate != null) {
|
|
final newToDo = ToDoItem(
|
|
name: name,
|
|
description: description,
|
|
dueDate: dueDate!,
|
|
);
|
|
Provider.of<ToDoProvider>(context, listen: false).addToDo(newToDo);
|
|
Navigator.of(context).pop();
|
|
}
|
|
},
|
|
child: const Text('Add'),
|
|
),
|
|
),
|
|
],
|
|
)
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|