import 'location.dart'; class Task { final String id; final String title; final String description; final DateTime? start; final DateTime? due; final bool isCompleted; final String category; final List subtasks; final String url; Task({ required this.id, required this.title, this.description = '', this.start, this.due, this.isCompleted = false, this.category = '', this.subtasks = const [], this.url = '', }); Task copyWith({ String? id, String? title, String? description, DateTime? start, DateTime? due, bool? isCompleted, String? category, List? subtasks, List? alarms, Location? location, String? url, }) { return Task( id: id ?? this.id, title: title ?? this.title, description: description ?? this.description, start: start ?? this.start, due: due ?? this.due, isCompleted: isCompleted ?? this.isCompleted, category: category ?? this.category, subtasks: subtasks ?? this.subtasks, url: url ?? this.url, ); } factory Task.fromJson(Map 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?) ?.map((e) => Task.fromJson(e as Map)) .toList() ?? [], url: json['url'] as String? ?? '', ); } Map 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(), 'url': url, }; } @override bool operator ==(Object other) { if (other is! Task) return false; return hashCode == other.hashCode; } @override int get hashCode => id.hashCode; }