118 lines
2.4 KiB
Dart
118 lines
2.4 KiB
Dart
// task_adapter.dart
|
|
import 'package:hive/hive.dart';
|
|
|
|
part 'task_adapter.g.dart';
|
|
|
|
@HiveType(typeId: 0)
|
|
class Task extends HiveObject {
|
|
@HiveField(0)
|
|
final String id;
|
|
|
|
@HiveField(1)
|
|
final String title;
|
|
|
|
@HiveField(3)
|
|
String description;
|
|
|
|
@HiveField(4)
|
|
final String author;
|
|
|
|
@HiveField(5)
|
|
String executor;
|
|
|
|
@HiveField(6)
|
|
final DateTime startTime;
|
|
|
|
@HiveField(7)
|
|
DateTime? endTime;
|
|
|
|
@HiveField(8)
|
|
bool isCompleted;
|
|
|
|
@HiveField(9)
|
|
bool isSynced;
|
|
|
|
@HiveField(10) // Новое поле: список подзадач
|
|
final List<Subtask> items;
|
|
|
|
@HiveField(11)
|
|
bool isDeletedLocally;
|
|
|
|
@HiveField(12)
|
|
bool isNew;
|
|
|
|
Task({
|
|
required this.id,
|
|
required this.title,
|
|
required this.startTime,
|
|
required this.author,
|
|
required this.executor,
|
|
this.endTime,
|
|
this.isCompleted = false,
|
|
this.description = "",
|
|
this.isSynced = false,
|
|
this.isDeletedLocally = false,
|
|
this.items = const [],
|
|
this.isNew = true,
|
|
});
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {
|
|
'id': id,
|
|
'title': title,
|
|
'startTime': startTime.toIso8601String(),
|
|
'endTime': endTime?.toIso8601String() ?? '',
|
|
'author': author,
|
|
'executor': executor,
|
|
'isCompleted': isCompleted,
|
|
'description': description,
|
|
'items': items.map((item) => item.toMap()).toList(),
|
|
};
|
|
}
|
|
|
|
factory Task.fromMap(Map<String, dynamic> map) {
|
|
return Task(
|
|
id: map['_id'],
|
|
title: map['title'],
|
|
description: map['description'],
|
|
author: map['author'],
|
|
executor: map['executor'],
|
|
startTime: DateTime.parse(map['startTime']),
|
|
endTime: map['endTime'] != null ? DateTime.parse(map['endTime']) : null,
|
|
isCompleted: map['isCompleted'],
|
|
isSynced: true,
|
|
isDeletedLocally: false,
|
|
isNew: false,
|
|
items:
|
|
(map['items'] as List?)
|
|
?.map((item) => Subtask.fromMap(item))
|
|
.toList() ??
|
|
[],
|
|
);
|
|
}
|
|
|
|
get subtasks => items;
|
|
}
|
|
|
|
@HiveType(typeId: 1)
|
|
class Subtask extends HiveObject {
|
|
@HiveField(0)
|
|
final String id;
|
|
|
|
@HiveField(1)
|
|
String text;
|
|
|
|
@HiveField(2)
|
|
bool isDone;
|
|
|
|
Subtask({required this.id, required this.text, this.isDone = false});
|
|
|
|
Map<String, dynamic> toMap() {
|
|
return {'id': id, 'text': text, 'isDone': isDone};
|
|
}
|
|
|
|
factory Subtask.fromMap(Map<String, dynamic> map) {
|
|
return Subtask(id: map['id'], text: map['text'], isDone: map['isDone']);
|
|
}
|
|
}
|