added toJson and fromJson functions
This commit is contained in:
@@ -4,4 +4,12 @@ class LatLng {
|
||||
|
||||
LatLng(this.lat, this.lng);
|
||||
LatLng.empty() : lat = 0, lng = 0;
|
||||
|
||||
factory LatLng.fromJson(Map<String, dynamic> json) {
|
||||
return LatLng(json['lat'] as double, json['lng'] as double);
|
||||
}
|
||||
|
||||
Map<String, double> toJson() {
|
||||
return {'lat': lat, 'lng': lng};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,4 +11,15 @@ class Location {
|
||||
|
||||
String get address => _address ?? '';
|
||||
LatLng get coordinates => _coordinates ?? LatLng.empty();
|
||||
|
||||
factory Location.fromJson(Map<String, dynamic> json) {
|
||||
return Location(
|
||||
address: json['address'] as String,
|
||||
coordinates: LatLng.fromJson(json['coordinates']),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {'address': address, 'coordinates': coordinates};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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