Added label model

This commit is contained in:
konrad 2019-03-16 20:56:20 +01:00
parent 9606fe4ad6
commit fcfca5dfff
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
3 changed files with 47 additions and 4 deletions

37
lib/models/label.dart Normal file
View File

@ -0,0 +1,37 @@
import 'package:meta/meta.dart';
import 'package:vikunja_app/models/user.dart';
class Label {
final int id;
final String title, description, hexColor;
final DateTime created, updated;
final User createdBy;
Label(
{@required this.id,
this.title,
this.description,
this.hexColor,
this.created,
this.updated,
this.createdBy});
Label.fromJson(Map<String, dynamic> json)
: id = json['id'],
title = json['title'],
description = json['description'],
hexColor = json['hex_color'],
updated = DateTime.fromMillisecondsSinceEpoch(json['updated']),
created = DateTime.fromMillisecondsSinceEpoch(json['created']),
createdBy = User.fromJson(json['created_by']);
toJSON() => {
'id': id,
'title': title,
'description': description,
'hex_color': description,
'created_by': createdBy?.toJSON(),
'updated': updated?.millisecondsSinceEpoch,
'created': created?.millisecondsSinceEpoch,
};
}

View File

@ -1,6 +1,8 @@
import 'package:vikunja_app/models/user.dart';
import 'package:meta/meta.dart';
import 'package:vikunja_app/models/label.dart';
import 'package:vikunja_app/models/user.dart';
class Task {
final int id, parentTaskID, priority;
final DateTime created, updated, dueDate, startDate, endDate;
@ -10,8 +12,7 @@ class Task {
final User createdBy;
final Duration repeatAfter;
final List<Task> subtasks;
//labels
final List<Label> labels;
Task(
{@required this.id,
@ -26,6 +27,7 @@ class Task {
this.priority,
this.repeatAfter,
this.subtasks,
this.labels,
this.created,
this.updated,
this.createdBy});
@ -44,6 +46,9 @@ class Task {
parentTaskID = json['parentTaskID'],
priority = json['priority'],
repeatAfter = Duration(seconds: json['repeatAfter']),
labels = (json['labels'] as List<dynamic>)
?.map((label) => Label.fromJson(label))
?.toList(),
subtasks = (json['subtasks'] as List<dynamic>)
?.map((subtask) => Task.fromJson(subtask))
?.toList(),
@ -63,6 +68,7 @@ class Task {
'endDate': endDate?.millisecondsSinceEpoch,
'priority': priority,
'repeatAfter': repeatAfter.inSeconds,
'labels': labels?.map((label) => label.toJSON())?.toList(),
'subtasks': subtasks?.map((subtask) => subtask.toJSON())?.toList(),
'createdBy': createdBy?.toJSON(),
'updated': updated?.millisecondsSinceEpoch,

View File

@ -39,7 +39,7 @@ var _tasks = {
1: Task(
id: 1,
text: 'Task 1',
owner: _users[1],
createdBy: _users[1],
updated: DateTime.now(),
created: DateTime.now(),
description: 'A descriptive task',