further improved landing page. always sets due date. shows due date in list.

This commit is contained in:
benimautner 2022-04-15 23:48:23 +02:00
parent 644ebbd13f
commit 0277af9b6c
7 changed files with 80 additions and 24 deletions

View File

@ -1,24 +1,49 @@
import 'package:flutter/material.dart';
class AddDialog extends StatelessWidget {
final ValueChanged<String> onAdd;
final InputDecoration decoration;
import '../models/task.dart';
const AddDialog({Key key, this.onAdd, this.decoration}) : super(key: key);
enum NewTaskDue {day,week, month}
Map<NewTaskDue, Duration> newTaskDueToDuration = {
NewTaskDue.day: Duration(days: 1),
NewTaskDue.week: Duration(days: 7),
NewTaskDue.month: Duration(days: 30),
};
class AddDialog extends StatefulWidget {
final ValueChanged<String> onAdd;
final ValueChanged<Task> onAddTask;
final InputDecoration decoration;
const AddDialog({Key key, this.onAdd, this.decoration, this.onAddTask}) : super(key: key);
@override
State<StatefulWidget> createState() => AddDialogState();
}
class AddDialogState extends State<AddDialog> {
NewTaskDue newTaskDue = NewTaskDue.day;
@override
Widget build(BuildContext context) {
var textController = TextEditingController();
return new AlertDialog(
contentPadding: const EdgeInsets.all(16.0),
content: new Row(children: <Widget>[
Expanded(
child: new TextField(
autofocus: true,
decoration: this.decoration,
controller: textController,
content: new Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(children: <Widget>[
Expanded(
child: new TextField(
autofocus: true,
decoration: widget.decoration,
controller: textController,
),
),
)
]),
widget.onAddTask != null ? taskDueList("1 Day", NewTaskDue.day) : new Container(),
widget.onAddTask != null ? taskDueList("1 Week", NewTaskDue.week) : new Container(),
widget.onAddTask != null ? taskDueList("1 Month", NewTaskDue.month) : new Container(),
//],)
]),
actions: <Widget>[
new TextButton(
@ -28,12 +53,33 @@ class AddDialog extends StatelessWidget {
new TextButton(
child: const Text('ADD'),
onPressed: () {
if (this.onAdd != null && textController.text.isNotEmpty)
this.onAdd(textController.text);
if (widget.onAdd != null && textController.text.isNotEmpty)
widget.onAdd(textController.text);
if(widget.onAddTask != null && textController.text.isNotEmpty)
widget.onAddTask(Task(id: null, title: textController.text, done: false, owner: null, due: DateTime.now().add(newTaskDueToDuration[newTaskDue])));
Navigator.pop(context);
},
)
],
);
}
Widget taskDueList(String name, NewTaskDue thisNewTaskDue) {
// TODO: I know you can do better
return Row(children: [
Checkbox(value: newTaskDue == thisNewTaskDue, onChanged: (value) { setState(() => newTaskDue = value ? thisNewTaskDue: newTaskDue);}, shape: CircleBorder(),),
Text(name),
]);
/*Row(children: [
Checkbox(value: newTaskDue == NewTaskDue.week, onChanged: (value) { setState(() => newTaskDue = value ? NewTaskDue.week: newTaskDue);}, shape: CircleBorder(),),
Text("1 Week"),
]),
Row(children: [
Checkbox(value: newTaskDue == NewTaskDue.month, onChanged: (value) { setState(() => newTaskDue = value ? NewTaskDue.month: newTaskDue);}, shape: CircleBorder(),),
Text("1 Month"),
])
];
*/
}
}

View File

@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:vikunja_app/global.dart';
import 'package:vikunja_app/models/task.dart';
import 'package:vikunja_app/pages/task/edit_task.dart';
import 'package:vikunja_app/utils/misc.dart';
class TaskTile extends StatefulWidget {
final Task task;
@ -34,6 +35,7 @@ class TaskTileState extends State<TaskTile> {
@override
Widget build(BuildContext context) {
Duration durationUntilDue = _currentTask.due.difference(DateTime.now());
if (_currentTask.loading) {
return ListTile(
leading: Padding(
@ -69,7 +71,7 @@ class TaskTileState extends State<TaskTile> {
controlAffinity: ListTileControlAffinity.leading,
value: _currentTask.done ?? false,
subtitle: widget.showInfo && _currentTask.due.year > 2 ?
Text("Due in " + _currentTask.due.difference(DateTime.now()).inDays.toString() + " days.")
Text("Due in " + durationToHumanReadable(durationUntilDue),style: TextStyle(color: durationUntilDue.isNegative ? Colors.red : null),)
: _currentTask.description == null || _currentTask.description.isEmpty
? null
: Text(_currentTask.description),

View File

@ -47,7 +47,7 @@ class Task {
'created': created?.toIso8601String(),
'reminder_dates':
reminders?.map((date) => date.toIso8601String())?.toList(),
'due_date': due?.toIso8601String(),
'due_date': due.toUtc()?.toIso8601String(),
'description': description,
'title': title,
'done': done ?? false,

View File

@ -15,9 +15,9 @@ class User {
String avatarUrl(BuildContext context) {
return VikunjaGlobal.of(context).client.base +
"/" +
this.username +
"/avatar";
"/avatar/ " +
this.username+
"?size=50";
}
}

View File

@ -72,16 +72,14 @@ class LandingPageState extends State<LandingPage> {
showDialog(
context: context,
builder: (_) => AddDialog(
onAdd: (name) => _addItem(name, context),
onAddTask: (task) => _addTask(task, context),
decoration: new InputDecoration(
labelText: 'Task Name', hintText: 'eg. Milk')));
}
_addItem(String name, BuildContext context) {
_addTask(Task task, BuildContext context) {
var globalState = VikunjaGlobal.of(context);
var newTask = Task(
id: null, title: name, owner: globalState.currentUser, done: false, loading: true);
globalState.taskService.add(defaultList, newTask).then((_) {
globalState.taskService.add(defaultList, task).then((_) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text('The task was added successfully!'),
));

View File

@ -62,7 +62,6 @@ class TaskServiceOptions {
if(result.startsWith('&'))
result.substring(1);
log(result);
return result;
}
}

11
lib/utils/misc.dart Normal file
View File

@ -0,0 +1,11 @@
String durationToHumanReadable(Duration dur) {
if(dur.inDays.abs() > 1)
return dur.inDays.toString() + " days";
if(dur.inDays.abs() == 1)
return dur.inDays.toString() + " day";
if(dur.inHours.abs() > 1)
return dur.inHours.toString() + " hours";
if(dur.inHours.abs() == 1)
return dur.inHours.toString() + "1 hour";
return "under 1 hour";
}