todotxt_reminder/lib/table.dart

121 lines
4.1 KiB
Dart
Raw Normal View History

2023-01-07 21:23:59 +00:00
import 'package:flutter/material.dart';
import 'package:nextcloud_reminder/repeating_task.dart';
import 'package:nextcloud_reminder/types/tasks.dart';
2023-01-07 21:23:59 +00:00
class ScrollTable extends StatefulWidget {
ScrollTable({super.key, required this.title, required this.deleteCallback});
2023-01-07 21:23:59 +00:00
// 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
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
final _ScrollTableState _internalState = _ScrollTableState();
final ValueChanged<RepeatingTask> deleteCallback;
2023-01-07 21:23:59 +00:00
@override
State<ScrollTable> createState() => _internalState;
void addTask(RepeatingTask task) {
_internalState.addTask(task);
}
}
class _ScrollTableState extends State<ScrollTable> {
final List<RepeatingTask> _content = [];
addTask(RepeatingTask task) {
setState(() {
_content.add(task);
});
}
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) {
2023-01-07 21:23:59 +00:00
return List<Widget>.from(_content.map((RepeatingTask t) =>
Container(
alignment: Alignment.centerLeft,
width: 150.0,
2023-01-07 21:23:59 +00:00
height: 60.0,
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),
)
)
)
);
2023-01-07 21:23:59 +00:00
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
//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),
2023-01-07 21:23:59 +00:00
),
Flexible(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: List<Widget>.from([Text("header ... date, date, date .. fancy turned 60 degrees", style: Theme.of(context).dataTableTheme.headingTextStyle)]) + List<Widget>.from(_content),
2023-01-07 21:23:59 +00:00
),
),
)
],
)
);
}
}