Files

78 lines
1.9 KiB
Dart

import 'package:uuid/uuid.dart';
const Object _unsetCategoryId = Object();
// Model: Note
// - Representa una nota guardada en la app.
class Note {
Note({
String? id,
required this.title,
required this.body,
required this.createdAt,
required this.updatedAt,
required this.position,
this.categoryId,
this.serverVersion = 0,
this.isDeleted = false,
this.isPermanentlyDeleted = false,
this.isDirty = true,
}) : id = id ?? Uuid().v4();
final String id;
final String title;
final String body;
final DateTime createdAt;
final DateTime updatedAt;
final double position;
final String? categoryId;
final int serverVersion;
final bool isDeleted;
final bool isPermanentlyDeleted;
final bool isDirty;
Note copyWith({
String? id,
String? title,
String? body,
DateTime? createdAt,
DateTime? updatedAt,
double? position,
Object? categoryId = _unsetCategoryId,
int? serverVersion,
bool? isDeleted,
bool? isPermanentlyDeleted,
bool? isDirty,
}) {
final String? resolvedCategoryId = identical(categoryId, _unsetCategoryId)
? this.categoryId
: categoryId as String?;
return Note(
id: id ?? this.id,
title: title ?? this.title,
body: body ?? this.body,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
position: position ?? this.position,
categoryId: resolvedCategoryId,
serverVersion: serverVersion ?? this.serverVersion,
isDeleted: isDeleted ?? this.isDeleted,
isPermanentlyDeleted: isPermanentlyDeleted ?? this.isPermanentlyDeleted,
isDirty: isDirty ?? this.isDirty,
);
}
@override
bool operator ==(Object other) {
if (identical(this, other)) {
return true;
}
return other is Note && id == other.id;
}
@override
int get hashCode => id.hashCode;
}