64 lines
1.5 KiB
Dart
64 lines
1.5 KiB
Dart
import '../../domain/models/task_item.dart';
|
|
|
|
class TaskItemModel {
|
|
const TaskItemModel({
|
|
required this.id,
|
|
required this.title,
|
|
required this.description,
|
|
required this.isCompleted,
|
|
required this.category,
|
|
required this.createdAt,
|
|
});
|
|
|
|
final String id;
|
|
final String title;
|
|
final String description;
|
|
final bool isCompleted;
|
|
final String category;
|
|
final String createdAt;
|
|
|
|
factory TaskItemModel.fromJson(Map<String, dynamic> json) {
|
|
return TaskItemModel(
|
|
id: json['id'] as String,
|
|
title: json['title'] as String,
|
|
description: json['description'] as String? ?? '',
|
|
isCompleted: json['isCompleted'] as bool? ?? false,
|
|
category: json['category'] as String? ?? 'General',
|
|
createdAt: json['createdAt'] as String,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'title': title,
|
|
'description': description,
|
|
'isCompleted': isCompleted,
|
|
'category': category,
|
|
'createdAt': createdAt,
|
|
};
|
|
}
|
|
|
|
TaskItem toDomain() {
|
|
return TaskItem(
|
|
id: id,
|
|
title: title,
|
|
description: description,
|
|
isCompleted: isCompleted,
|
|
category: category,
|
|
createdAt: DateTime.tryParse(createdAt) ?? DateTime.now(),
|
|
);
|
|
}
|
|
|
|
factory TaskItemModel.fromDomain(TaskItem item) {
|
|
return TaskItemModel(
|
|
id: item.id,
|
|
title: item.title,
|
|
description: item.description,
|
|
isCompleted: item.isCompleted,
|
|
category: item.category,
|
|
createdAt: item.createdAt.toIso8601String(),
|
|
);
|
|
}
|
|
}
|