76 lines
1.9 KiB
Dart
76 lines
1.9 KiB
Dart
import 'package:uuid/uuid.dart';
|
|
|
|
// Model: Note
|
|
// - Representa una nota guardada en la app.
|
|
// - `id` es el identificador local de SQLite (autoincrement).
|
|
// - `uuid` es el identificador global sincronizado con el servidor.
|
|
// - `index` representa el orden visual dentro de la lista.
|
|
// - `serverVersion` se usa para resolver conflictos en sync.
|
|
// - `isDeleted` marca eliminaciones blandas.
|
|
class Note {
|
|
Note({
|
|
this.id,
|
|
String? uuid,
|
|
required this.title,
|
|
required this.body,
|
|
required this.createdAt,
|
|
required this.updatedAt,
|
|
required this.index,
|
|
this.serverVersion = 0,
|
|
this.isDeleted = false,
|
|
this.isPermanentlyDeleted = false,
|
|
this.categoryId,
|
|
}) : uuid = uuid ?? Uuid().v4();
|
|
|
|
final int? id;
|
|
final String uuid;
|
|
final String title;
|
|
final String body;
|
|
final DateTime createdAt;
|
|
final DateTime updatedAt;
|
|
final int index;
|
|
final int serverVersion;
|
|
final bool isDeleted;
|
|
final bool isPermanentlyDeleted;
|
|
final String? categoryId;
|
|
|
|
Note copyWith({
|
|
int? id,
|
|
String? uuid,
|
|
String? title,
|
|
String? body,
|
|
DateTime? createdAt,
|
|
DateTime? updatedAt,
|
|
int? index,
|
|
int? serverVersion,
|
|
bool? isDeleted,
|
|
bool? isPermanentlyDeleted,
|
|
String? categoryId,
|
|
}) {
|
|
return Note(
|
|
id: id ?? this.id,
|
|
uuid: uuid ?? this.uuid,
|
|
title: title ?? this.title,
|
|
body: body ?? this.body,
|
|
createdAt: createdAt ?? this.createdAt,
|
|
updatedAt: updatedAt ?? this.updatedAt,
|
|
index: index ?? this.index,
|
|
serverVersion: serverVersion ?? this.serverVersion,
|
|
isDeleted: isDeleted ?? this.isDeleted,
|
|
isPermanentlyDeleted: isPermanentlyDeleted ?? this.isPermanentlyDeleted,
|
|
categoryId: categoryId ?? this.categoryId,
|
|
);
|
|
}
|
|
|
|
@override
|
|
bool operator ==(Object other) {
|
|
if (identical(this, other)) {
|
|
return true;
|
|
}
|
|
|
|
return other is Note && uuid == other.uuid;
|
|
}
|
|
|
|
@override
|
|
int get hashCode => uuid.hashCode;
|
|
} |