task removeable, added header, more todos 🤷‍♀️ ..

This commit is contained in:
2023-01-10 02:01:05 +01:00
parent 33ff8b1f7d
commit 9f8e0c875c
15 changed files with 128 additions and 32 deletions

View File

@ -103,7 +103,7 @@ class _AddTaskWidgetState extends State<AddTaskWidget> with RestorationMixin {
children: [
Text("Begin: ", style: Theme.of(context).textTheme.labelLarge),
Expanded(
child: Text("${_beginDate.value.year}-${_beginDate.value.month.toString().padLeft(2,'0')}-${_beginDate.value.day.toString().padLeft(2,'0')}")
child: Text(Task.formatDate(_beginDate.value))
),
IconButton(
onPressed: () => _restorableDatePickerRouteFuture.present(),

View File

@ -1,6 +1,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_window_close/flutter_window_close.dart';
import 'package:nextcloud_reminder/addReminder.dart';
import 'package:nextcloud_reminder/parser/todotxt.dart';
import 'package:nextcloud_reminder/repeating_task.dart';
@ -28,7 +29,7 @@ class HomeWidget extends StatefulWidget {
class _HomeWidgetState extends State<HomeWidget> with WidgetsBindingObserver {
final ScrollTable _checkboxes = ScrollTable(title: "TODOs");
late final ScrollTable _checkboxes;
int _counter = 1;
late final Directory appDocDirectory;
late final File todotxt = File('${appDocDirectory.path}/todo.txt');
@ -45,7 +46,6 @@ class _HomeWidgetState extends State<HomeWidget> with WidgetsBindingObserver {
appDocDirectory = (await getApplicationDocumentsDirectory());
if (await todotxt.exists()) {
var data = await todotxt.readAsLines();
debugPrint(data.toString());
tasks.addAll(TodoParser.parse(data));
_loadTodos();
} else {
@ -57,7 +57,12 @@ class _HomeWidgetState extends State<HomeWidget> with WidgetsBindingObserver {
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
_checkboxes = ScrollTable(title: "TODOs", deleteCallback: _removeTask);
initLazy();
FlutterWindowClose.setWindowShouldCloseHandler(() async {
saveData();
return true;
});
}
@override
@ -81,16 +86,6 @@ class _HomeWidgetState extends State<HomeWidget> with WidgetsBindingObserver {
await todotxt.writeAsString(data);
}
void _addDummyTask() {
setState(() {
// This call to setState tells the Flutter framework that something has
// changed in this State, which causes it to rerun the build method below
// so that the display can reflect the updated values. If we changed
// stuff without calling setState(), then the build method would not be
// called again, and so nothing would appear to happen.
_checkboxes.addTask(RepeatingTask(task: Task(title: "Dummy Task #$_counter", begin: DateTime.now()), repeat: _counter++));
});
}
void _addTask(RepeatingTask? t) {
if (t != null) {
setState(() {
@ -99,6 +94,11 @@ class _HomeWidgetState extends State<HomeWidget> with WidgetsBindingObserver {
});
}
}
void _removeTask(RepeatingTask t) {
setState(() {
tasks.remove(t.task);
});
}
@override
Widget build(BuildContext context) {

View File

@ -23,9 +23,13 @@ class _RepeatingTaskState extends State<RepeatingTask> {
@override
Widget build(BuildContext context) {
return Row(
return Container(
decoration: const BoxDecoration(border: Border(bottom: BorderSide(),)),
margin: const EdgeInsets.all(0.0),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: _occurrences,
);
)
);
}
}

View File

@ -1,8 +1,9 @@
import 'package:flutter/material.dart';
import 'package:nextcloud_reminder/repeating_task.dart';
import 'package:nextcloud_reminder/types/tasks.dart';
class ScrollTable extends StatefulWidget {
ScrollTable({super.key, required this.title});
ScrollTable({super.key, required this.title, required this.deleteCallback});
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
@ -11,6 +12,7 @@ class ScrollTable extends StatefulWidget {
final String title;
final _ScrollTableState _internalState = _ScrollTableState();
final ValueChanged<RepeatingTask> deleteCallback;
@override
State<ScrollTable> createState() => _internalState;
@ -31,19 +33,64 @@ class _ScrollTableState extends State<ScrollTable> {
});
}
List<Widget> _buildTitles() {
removeTask(RepeatingTask task) {
setState(() {
_content.remove(task);
});
widget.deleteCallback(task);
}
Future<void> _showDetailsAndRemoveTask(BuildContext context, RepeatingTask t) {
return showDialog(context: context,
barrierDismissible: true,
builder: (BuildContext context)
{
return AlertDialog(
title: const Text("Task details"),
content: SingleChildScrollView(
child: ListBody(
children: [ Text(t.task.title),
Text("Projects: ${t.task.projects.isEmpty ? "none" : t.task.projects.join(", ")}"),
Text("Contexts: ${t.task.contexts.isEmpty ? "none" : t.task.contexts.join(", ")}"),
Padding(padding: EdgeInsets.only(top: 16),
child: Text(t.task.meta.isEmpty ? "" : "Meta:", style: Theme.of(context).textTheme.bodyLarge,)
),
] + List.of(t.task.meta.entries.map((e) => Text("${e.key}: ${e.value}"))),
),
),
actions: <Widget>[
TextButton(onPressed: () {
removeTask(t);
Navigator.of(context).pop();
},
style: TextButton.styleFrom(foregroundColor: Theme
.of(context)
.errorColor),
child: const Text("remove"),),
TextButton(onPressed: () => Navigator.of(context).pop(),
child: const Text("close")),
]
);
});
}
List<Widget> _buildTitles(BuildContext context) {
return List<Widget>.from(_content.map((RepeatingTask t) =>
Container(
alignment: Alignment.center,
width: 120.0,
alignment: Alignment.centerLeft,
width: 150.0,
height: 60.0,
color: Colors.white,
margin: const EdgeInsets.all(4.0),
child: Text(t.task.title, style: Theme
.of(context)
.textTheme
.labelMedium),
)));
margin: const EdgeInsets.only(left: 4, top: 1),
decoration: const BoxDecoration(color: Colors.white, border: Border(bottom: BorderSide(),)),
child: TextButton(
onPressed: () => _showDetailsAndRemoveTask(context,t),
child: Text(t.task.title,
style: Theme.of(context).textTheme.labelMedium),
)
)
)
);
}
@override
@ -54,14 +101,15 @@ class _ScrollTableState extends State<ScrollTable> {
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _buildTitles(),
//TODO: Text in container wie bei _buildTitles oben und width/height/margin/etc. festnageln.
children: List<Widget>.from([Text("Todo", style: Theme.of(context).dataTableTheme.headingTextStyle,)]) + _buildTitles(context),
),
Flexible(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: _content,
children: List<Widget>.from([Text("header ... date, date, date .. fancy turned 60 degrees", style: Theme.of(context).dataTableTheme.headingTextStyle)]) + List<Widget>.from(_content),
),
),
)

View File

@ -27,7 +27,7 @@ class _TaskItemState extends State<TaskItem>{
width: 60.0,
height: 60.0,
color: Colors.white,
margin: const EdgeInsets.all(4.0),
margin: const EdgeInsets.all(0.0),
child: _done == null ? null : Checkbox(value: _done, onChanged: (newState) => setState(() {
_done = newState!;
})),

View File

@ -19,12 +19,16 @@ class Task {
this.end,
});
static String formatDate(DateTime dt) {
return "${dt!.year}-${dt!.month.toString().padLeft(2,'0')}-${dt!.day.toString().padLeft(2,'0')}";
}
@override
String toString() {
return (done ? "x " : "")
+ (priority == null ? "" : "(${priority!}) ")
+ (begin == null ? "" : "${begin!.year}-${begin!.month}-${begin!.day} ")
+ (end == null ? "" : "${end!.year}-${end!.month}-${end!.day} ")
+ (begin == null ? "" : "${Task.formatDate(begin!)} ")
+ (end == null ? "" : "${Task.formatDate(end!)} ")
+ ("$title ")
+ meta.entries.map((entry) => "${entry.key}:${entry.value}").join(" ")
;