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

50 lines
1.4 KiB
Dart
Raw Normal View History

2018-09-22 20:56:16 +00:00
import 'package:vikunja_app/models/user.dart';
import 'package:meta/meta.dart';
class Task {
final int id;
final DateTime created, updated, due;
final List<DateTime> reminders;
final String title, description;
final bool done;
final User owner;
Task(
{@required this.id,
this.created,
this.updated,
this.reminders,
this.due,
@required this.title,
this.description,
@required this.done,
@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))
?.toList(),
2020-06-15 21:48:15 +00:00
due =
json['due_date'] != null ? DateTime.parse(json['due_date']) : null,
description = json['description'],
title = json['title'],
done = json['done'],
2020-06-15 21:46:10 +00:00
owner = User.fromJson(json['created_by']);
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(),
'description': description,
'title': title,
'done': done ?? false,
2020-06-15 21:46:10 +00:00
'created_by': owner?.toJSON()
};
}