mirror of
https://github.com/go-vikunja/app
synced 2024-06-02 18:49:47 +00:00
ee99869cf6
* Ran make format Signed-off-by: Timo Reichl <timo.reichl@mailbox.org> * Add VS Code launch config Signed-off-by: Timo Reichl <timo.reichl@mailbox.org> * pages/list/list.dart: Stop spinning wheel after adding a task Signed-off-by: Timo Reichl <timo.reichl@mailbox.org> * stores/list_store.dart: Fix updateTask() not being a future Signed-off-by: Timo Reichl <timo.reichl@mailbox.org> * Replace FlatButton with TextButton widgets Signed-off-by: Timo Reichl <timo.reichl@mailbox.org> * components/TaskTile.dart: Remove dead code Signed-off-by: Timo Reichl <timo.reichl@mailbox.org> * theme/theme.dart: Fix accentColor deprecation Signed-off-by: Timo Reichl <timo.reichl@mailbox.org> * pages/list/list_edit.dart: Fix SnackBar.hideCurrentSnackBar() deprecation Signed-off-by: Timo Reichl <timo.reichl@mailbox.org> * Remove unused folder lib/managers Signed-off-by: Timo Reichl <timo.reichl@mailbox.org>
92 lines
2.3 KiB
Dart
92 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:vikunja_app/models/task.dart';
|
|
import 'package:vikunja_app/global.dart';
|
|
|
|
class ListProvider with ChangeNotifier {
|
|
bool _isLoading = false;
|
|
int _maxPages = 0;
|
|
|
|
// TODO: Streams
|
|
List<Task> _tasks = [];
|
|
|
|
bool get isLoading => _isLoading;
|
|
|
|
int get maxPages => _maxPages;
|
|
|
|
set tasks(List<Task> tasks) {
|
|
_tasks = tasks;
|
|
notifyListeners();
|
|
}
|
|
|
|
List<Task> get tasks => _tasks;
|
|
|
|
void loadTasks({BuildContext context, int listId, int page = 1}) {
|
|
_tasks = [];
|
|
_isLoading = true;
|
|
notifyListeners();
|
|
|
|
VikunjaGlobal.of(context).taskService.getAll(listId, {
|
|
"sort_by": ["done", "id"],
|
|
"order_by": ["asc", "desc"],
|
|
"page": [page.toString()]
|
|
}).then((response) {
|
|
if (response.headers["x-pagination-total-pages"] != null) {
|
|
_maxPages = int.parse(response.headers["x-pagination-total-pages"]);
|
|
}
|
|
_tasks.addAll(response.body);
|
|
_isLoading = false;
|
|
notifyListeners();
|
|
});
|
|
}
|
|
|
|
Future<void> addTaskByTitle(
|
|
{BuildContext context, String title, int listId}) {
|
|
var globalState = VikunjaGlobal.of(context);
|
|
var newTask = Task(
|
|
id: null,
|
|
title: title,
|
|
createdBy: globalState.currentUser,
|
|
done: false,
|
|
);
|
|
_isLoading = true;
|
|
notifyListeners();
|
|
|
|
return globalState.taskService.add(listId, newTask).then((task) {
|
|
_tasks.insert(0, task);
|
|
_isLoading = false;
|
|
notifyListeners();
|
|
});
|
|
}
|
|
|
|
Future<void> addTask({BuildContext context, Task newTask, int listId}) {
|
|
var globalState = VikunjaGlobal.of(context);
|
|
_isLoading = true;
|
|
notifyListeners();
|
|
|
|
return globalState.taskService.add(listId, newTask).then((task) {
|
|
_tasks.insert(0, task);
|
|
_isLoading = false;
|
|
notifyListeners();
|
|
});
|
|
}
|
|
|
|
void updateTask({BuildContext context, int id, bool done}) {
|
|
var globalState = VikunjaGlobal.of(context);
|
|
globalState.taskService
|
|
.update(Task(
|
|
id: id,
|
|
done: done,
|
|
))
|
|
.then((task) {
|
|
// FIXME: This is ugly. We should use a redux to not have to do these kind of things.
|
|
// This is enough for now (it works™) but we should definitly fix it later.
|
|
_tasks.asMap().forEach((i, t) {
|
|
if (task.id == t.id) {
|
|
_tasks[i] = task;
|
|
}
|
|
});
|
|
notifyListeners();
|
|
});
|
|
}
|
|
}
|