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, 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 // 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 deleteCallback; @override State createState() => _internalState; void addTask(RepeatingTask task) { _internalState.addTask(task); } } class _ScrollTableState extends State { final List _content = []; addTask(RepeatingTask task) { setState(() { _content.add(task); }); } removeTask(RepeatingTask task) { setState(() { _content.remove(task); }); widget.deleteCallback(task); } Future _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: [ 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 _buildTitles(BuildContext context) { return List.from(_content.map((RepeatingTask t) => Container( alignment: Alignment.centerLeft, width: 150.0, 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), ) ) ) ); } @override Widget build(BuildContext context) { return SingleChildScrollView( child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, //TODO: Text in container wie bei _buildTitles oben und width/height/margin/etc. festnageln. children: List.from([Text("Todo", style: Theme.of(context).dataTableTheme.headingTextStyle,)]) + _buildTitles(context), ), Flexible( child: SingleChildScrollView( scrollDirection: Axis.horizontal, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: List.from([Text("header ... date, date, date .. fancy turned 60 degrees", style: Theme.of(context).dataTableTheme.headingTextStyle)]) + List.from(_content), ), ), ) ], ) ); } }