2018-09-22 20:56:16 +00:00
|
|
|
import 'package:vikunja_app/models/user.dart';
|
2018-09-16 19:47:33 +00:00
|
|
|
import 'package:meta/meta.dart';
|
|
|
|
|
|
|
|
class Task {
|
|
|
|
final int id;
|
2018-12-03 21:26:00 +00:00
|
|
|
final DateTime created, updated, due;
|
|
|
|
final List<DateTime> reminders;
|
2020-06-15 21:42:12 +00:00
|
|
|
final String title, description;
|
2018-09-16 19:47:33 +00:00
|
|
|
final bool done;
|
|
|
|
final User owner;
|
|
|
|
|
|
|
|
Task(
|
|
|
|
{@required this.id,
|
|
|
|
this.created,
|
|
|
|
this.updated,
|
2018-12-03 21:26:00 +00:00
|
|
|
this.reminders,
|
2018-09-16 19:47:33 +00:00
|
|
|
this.due,
|
2020-06-15 21:42:12 +00:00
|
|
|
@required this.title,
|
2018-09-16 19:47:33 +00:00
|
|
|
this.description,
|
2018-09-17 16:16:50 +00:00
|
|
|
@required this.done,
|
2018-09-16 19:47:33 +00:00
|
|
|
@required this.owner});
|
|
|
|
|
|
|
|
Task.fromJson(Map<String, dynamic> json)
|
|
|
|
: id = json['id'],
|
2020-04-27 15:02:55 +00:00
|
|
|
updated = DateTime.parse(json['updated']),
|
|
|
|
created = DateTime.parse(json['created']),
|
2020-06-15 21:46:10 +00:00
|
|
|
reminders = (json['reminder_dates'] as List<dynamic>)
|
2020-04-27 15:02:55 +00:00
|
|
|
?.map((r) => DateTime.parse(r))
|
2018-12-03 21:26:00 +00:00
|
|
|
?.toList(),
|
2020-06-15 21:48:15 +00:00
|
|
|
due =
|
|
|
|
json['due_date'] != null ? DateTime.parse(json['due_date']) : null,
|
2018-09-16 19:47:33 +00:00
|
|
|
description = json['description'],
|
2020-06-15 21:42:12 +00:00
|
|
|
title = json['title'],
|
2018-09-16 19:47:33 +00:00
|
|
|
done = json['done'],
|
2020-06-15 21:46:10 +00:00
|
|
|
owner = User.fromJson(json['created_by']);
|
2018-09-17 16:16:50 +00:00
|
|
|
|
|
|
|
toJSON() => {
|
|
|
|
'id': id,
|
2020-04-27 15:02:55 +00:00
|
|
|
'updated': updated?.toIso8601String(),
|
|
|
|
'created': created?.toIso8601String(),
|
2020-06-15 21:46:10 +00:00
|
|
|
'reminder_dates':
|
2020-04-27 15:02:55 +00:00
|
|
|
reminders?.map((date) => date.toIso8601String())?.toList(),
|
2020-06-15 21:46:10 +00:00
|
|
|
'due_date': due?.toIso8601String(),
|
2018-09-17 16:16:50 +00:00
|
|
|
'description': description,
|
2020-06-15 21:42:12 +00:00
|
|
|
'title': title,
|
2018-09-17 16:16:50 +00:00
|
|
|
'done': done ?? false,
|
2020-06-15 21:46:10 +00:00
|
|
|
'created_by': owner?.toJSON()
|
2018-09-17 16:16:50 +00:00
|
|
|
};
|
2018-09-16 19:47:33 +00:00
|
|
|
}
|