added toJson and fromJson functions
This commit is contained in:
@@ -54,4 +54,48 @@ class Task {
|
||||
url: url ?? this.url,
|
||||
);
|
||||
}
|
||||
|
||||
factory Task.fromJson(Map<String, dynamic> json) {
|
||||
return Task(
|
||||
id: json['id'] as String,
|
||||
title: json['title'] as String,
|
||||
description: json['description'] as String? ?? '',
|
||||
start: json['start'] != null
|
||||
? DateTime.parse(json['start'] as String)
|
||||
: null,
|
||||
due: json['due'] != null ? DateTime.parse(json['due'] as String) : null,
|
||||
isCompleted: json['isCompleted'] as bool? ?? false,
|
||||
category: json['category'] as String? ?? '',
|
||||
subtasks:
|
||||
(json['subtasks'] as List<dynamic>?)
|
||||
?.map((e) => Task.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
alarms:
|
||||
(json['alarms'] as List<dynamic>?)
|
||||
?.map((e) => DateTime.parse(e as String))
|
||||
.toList() ??
|
||||
[],
|
||||
location: json['location'] != null
|
||||
? Location.fromJson(json['location'] as Map<String, dynamic>)
|
||||
: null,
|
||||
url: json['url'] as String? ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'title': title,
|
||||
'description': description,
|
||||
'start': start?.toIso8601String(),
|
||||
'due': due?.toIso8601String(),
|
||||
'isCompleted': isCompleted,
|
||||
'category': category,
|
||||
'subtasks': subtasks.map((e) => e.toJson()).toList(),
|
||||
'alarms': alarms.map((e) => e.toIso8601String()).toList(),
|
||||
'location': location?.toJson(),
|
||||
'url': url,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user