This repository has been archived on 2022-04-20. You can view files and clone it, but cannot push or open issues or pull requests.
app/lib/models/task.dart
konrad 9606fe4ad6
Some checks failed
continuous-integration/drone/push Build is failing
Updated the model
2019-03-16 20:47:56 +01:00

72 lines
2.4 KiB
Dart

import 'package:vikunja_app/models/user.dart';
import 'package:meta/meta.dart';
class Task {
final int id, parentTaskID, priority;
final DateTime created, updated, dueDate, startDate, endDate;
final List<DateTime> reminderDates;
final String text, description;
final bool done;
final User createdBy;
final Duration repeatAfter;
final List<Task> subtasks;
//labels
Task(
{@required this.id,
this.text,
this.description,
this.done,
this.reminderDates,
this.dueDate,
this.startDate,
this.endDate,
this.parentTaskID,
this.priority,
this.repeatAfter,
this.subtasks,
this.created,
this.updated,
this.createdBy});
Task.fromJson(Map<String, dynamic> json)
: id = json['id'],
text = json['text'],
description = json['description'],
done = json['done'],
reminderDates = (json['reminderDates'] as List<dynamic>)
?.map((milli) => DateTime.fromMillisecondsSinceEpoch(milli))
?.toList(),
dueDate = DateTime.fromMillisecondsSinceEpoch(json['dueDate']),
startDate = DateTime.fromMillisecondsSinceEpoch(json['startDate']),
endDate = DateTime.fromMillisecondsSinceEpoch(json['endDate']),
parentTaskID = json['parentTaskID'],
priority = json['priority'],
repeatAfter = Duration(seconds: json['repeatAfter']),
subtasks = (json['subtasks'] as List<dynamic>)
?.map((subtask) => Task.fromJson(subtask))
?.toList(),
updated = DateTime.fromMillisecondsSinceEpoch(json['updated']),
created = DateTime.fromMillisecondsSinceEpoch(json['created']),
createdBy = User.fromJson(json['createdBy']);
toJSON() => {
'id': id,
'text': text,
'description': description,
'done': done ?? false,
'reminderDates':
reminderDates?.map((date) => date.millisecondsSinceEpoch)?.toList(),
'dueDate': dueDate?.millisecondsSinceEpoch,
'startDate': startDate?.millisecondsSinceEpoch,
'endDate': endDate?.millisecondsSinceEpoch,
'priority': priority,
'repeatAfter': repeatAfter.inSeconds,
'subtasks': subtasks?.map((subtask) => subtask.toJSON())?.toList(),
'createdBy': createdBy?.toJSON(),
'updated': updated?.millisecondsSinceEpoch,
'created': created?.millisecondsSinceEpoch,
};
}