feat: Rename encryptedName to name in Categories table and update related logic

This commit is contained in:
2026-05-22 09:27:20 +02:00
parent f595f33f4a
commit 27e1199178
4 changed files with 245 additions and 150 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ part 'app_database.g.dart';
@DataClassName('DbCategory') @DataClassName('DbCategory')
class Categories extends Table { class Categories extends Table {
TextColumn get id => text()(); TextColumn get id => text()();
TextColumn get encryptedName => text().named('encrypted_name')(); TextColumn get name => text().named('name')();
IntColumn get serverVersion => IntColumn get serverVersion =>
integer().named('server_version').withDefault(const Constant(0))(); integer().named('server_version').withDefault(const Constant(0))();
BoolColumn get isDeleted => BoolColumn get isDeleted =>
+148 -105
View File
@@ -629,12 +629,10 @@ class $CategoriesTable extends Categories
type: DriftSqlType.string, type: DriftSqlType.string,
requiredDuringInsert: true, requiredDuringInsert: true,
); );
static const VerificationMeta _encryptedNameMeta = const VerificationMeta( static const VerificationMeta _nameMeta = const VerificationMeta('name');
'encryptedName',
);
@override @override
late final GeneratedColumn<String> encryptedName = GeneratedColumn<String>( late final GeneratedColumn<String> name = GeneratedColumn<String>(
'encrypted_name', 'name',
aliasedName, aliasedName,
false, false,
type: DriftSqlType.string, type: DriftSqlType.string,
@@ -667,21 +665,6 @@ class $CategoriesTable extends Categories
), ),
defaultValue: const Constant(false), defaultValue: const Constant(false),
); );
static const VerificationMeta _isDirtyMeta = const VerificationMeta(
'isDirty',
);
@override
late final GeneratedColumn<bool> isDirty = GeneratedColumn<bool>(
'is_dirty',
aliasedName,
false,
type: DriftSqlType.bool,
requiredDuringInsert: false,
defaultConstraints: GeneratedColumn.constraintIsAlways(
'CHECK ("is_dirty" IN (0, 1))',
),
defaultValue: const Constant(true),
);
static const VerificationMeta _colorValueMeta = const VerificationMeta( static const VerificationMeta _colorValueMeta = const VerificationMeta(
'colorValue', 'colorValue',
); );
@@ -704,6 +687,21 @@ class $CategoriesTable extends Categories
type: DriftSqlType.int, type: DriftSqlType.int,
requiredDuringInsert: false, requiredDuringInsert: false,
); );
static const VerificationMeta _isDirtyMeta = const VerificationMeta(
'isDirty',
);
@override
late final GeneratedColumn<bool> isDirty = GeneratedColumn<bool>(
'is_dirty',
aliasedName,
false,
type: DriftSqlType.bool,
requiredDuringInsert: false,
defaultConstraints: GeneratedColumn.constraintIsAlways(
'CHECK ("is_dirty" IN (0, 1))',
),
defaultValue: const Constant(true),
);
static const VerificationMeta _updatedAtMeta = const VerificationMeta( static const VerificationMeta _updatedAtMeta = const VerificationMeta(
'updatedAt', 'updatedAt',
); );
@@ -718,12 +716,12 @@ class $CategoriesTable extends Categories
@override @override
List<GeneratedColumn> get $columns => [ List<GeneratedColumn> get $columns => [
id, id,
encryptedName, name,
serverVersion, serverVersion,
isDeleted, isDeleted,
isDirty,
colorValue, colorValue,
iconCodePoint, iconCodePoint,
isDirty,
updatedAt, updatedAt,
]; ];
@override @override
@@ -743,16 +741,13 @@ class $CategoriesTable extends Categories
} else if (isInserting) { } else if (isInserting) {
context.missing(_idMeta); context.missing(_idMeta);
} }
if (data.containsKey('encrypted_name')) { if (data.containsKey('name')) {
context.handle( context.handle(
_encryptedNameMeta, _nameMeta,
encryptedName.isAcceptableOrUnknown( name.isAcceptableOrUnknown(data['name']!, _nameMeta),
data['encrypted_name']!,
_encryptedNameMeta,
),
); );
} else if (isInserting) { } else if (isInserting) {
context.missing(_encryptedNameMeta); context.missing(_nameMeta);
} }
if (data.containsKey('server_version')) { if (data.containsKey('server_version')) {
context.handle( context.handle(
@@ -769,12 +764,6 @@ class $CategoriesTable extends Categories
isDeleted.isAcceptableOrUnknown(data['is_deleted']!, _isDeletedMeta), isDeleted.isAcceptableOrUnknown(data['is_deleted']!, _isDeletedMeta),
); );
} }
if (data.containsKey('is_dirty')) {
context.handle(
_isDirtyMeta,
isDirty.isAcceptableOrUnknown(data['is_dirty']!, _isDirtyMeta),
);
}
if (data.containsKey('color_value')) { if (data.containsKey('color_value')) {
context.handle( context.handle(
_colorValueMeta, _colorValueMeta,
@@ -790,6 +779,12 @@ class $CategoriesTable extends Categories
), ),
); );
} }
if (data.containsKey('is_dirty')) {
context.handle(
_isDirtyMeta,
isDirty.isAcceptableOrUnknown(data['is_dirty']!, _isDirtyMeta),
);
}
if (data.containsKey('updated_at')) { if (data.containsKey('updated_at')) {
context.handle( context.handle(
_updatedAtMeta, _updatedAtMeta,
@@ -811,9 +806,9 @@ class $CategoriesTable extends Categories
DriftSqlType.string, DriftSqlType.string,
data['${effectivePrefix}id'], data['${effectivePrefix}id'],
)!, )!,
encryptedName: attachedDatabase.typeMapping.read( name: attachedDatabase.typeMapping.read(
DriftSqlType.string, DriftSqlType.string,
data['${effectivePrefix}encrypted_name'], data['${effectivePrefix}name'],
)!, )!,
serverVersion: attachedDatabase.typeMapping.read( serverVersion: attachedDatabase.typeMapping.read(
DriftSqlType.int, DriftSqlType.int,
@@ -823,10 +818,6 @@ class $CategoriesTable extends Categories
DriftSqlType.bool, DriftSqlType.bool,
data['${effectivePrefix}is_deleted'], data['${effectivePrefix}is_deleted'],
)!, )!,
isDirty: attachedDatabase.typeMapping.read(
DriftSqlType.bool,
data['${effectivePrefix}is_dirty'],
)!,
colorValue: attachedDatabase.typeMapping.read( colorValue: attachedDatabase.typeMapping.read(
DriftSqlType.int, DriftSqlType.int,
data['${effectivePrefix}color_value'], data['${effectivePrefix}color_value'],
@@ -835,6 +826,10 @@ class $CategoriesTable extends Categories
DriftSqlType.int, DriftSqlType.int,
data['${effectivePrefix}icon_code_point'], data['${effectivePrefix}icon_code_point'],
), ),
isDirty: attachedDatabase.typeMapping.read(
DriftSqlType.bool,
data['${effectivePrefix}is_dirty'],
)!,
updatedAt: attachedDatabase.typeMapping.read( updatedAt: attachedDatabase.typeMapping.read(
DriftSqlType.dateTime, DriftSqlType.dateTime,
data['${effectivePrefix}updated_at'], data['${effectivePrefix}updated_at'],
@@ -850,37 +845,37 @@ class $CategoriesTable extends Categories
class DbCategory extends DataClass implements Insertable<DbCategory> { class DbCategory extends DataClass implements Insertable<DbCategory> {
final String id; final String id;
final String encryptedName; final String name;
final int serverVersion; final int serverVersion;
final bool isDeleted; final bool isDeleted;
final bool isDirty;
final int? colorValue; final int? colorValue;
final int? iconCodePoint; final int? iconCodePoint;
final bool isDirty;
final DateTime updatedAt; final DateTime updatedAt;
const DbCategory({ const DbCategory({
required this.id, required this.id,
required this.encryptedName, required this.name,
required this.serverVersion, required this.serverVersion,
required this.isDeleted, required this.isDeleted,
required this.isDirty,
this.colorValue, this.colorValue,
this.iconCodePoint, this.iconCodePoint,
required this.isDirty,
required this.updatedAt, required this.updatedAt,
}); });
@override @override
Map<String, Expression> toColumns(bool nullToAbsent) { Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{}; final map = <String, Expression>{};
map['id'] = Variable<String>(id); map['id'] = Variable<String>(id);
map['encrypted_name'] = Variable<String>(encryptedName); map['name'] = Variable<String>(name);
map['server_version'] = Variable<int>(serverVersion); map['server_version'] = Variable<int>(serverVersion);
map['is_deleted'] = Variable<bool>(isDeleted); map['is_deleted'] = Variable<bool>(isDeleted);
map['is_dirty'] = Variable<bool>(isDirty);
if (!nullToAbsent || colorValue != null) { if (!nullToAbsent || colorValue != null) {
map['color_value'] = Variable<int>(colorValue); map['color_value'] = Variable<int>(colorValue);
} }
if (!nullToAbsent || iconCodePoint != null) { if (!nullToAbsent || iconCodePoint != null) {
map['icon_code_point'] = Variable<int>(iconCodePoint); map['icon_code_point'] = Variable<int>(iconCodePoint);
} }
map['is_dirty'] = Variable<bool>(isDirty);
map['updated_at'] = Variable<DateTime>(updatedAt); map['updated_at'] = Variable<DateTime>(updatedAt);
return map; return map;
} }
@@ -888,16 +883,16 @@ class DbCategory extends DataClass implements Insertable<DbCategory> {
CategoriesCompanion toCompanion(bool nullToAbsent) { CategoriesCompanion toCompanion(bool nullToAbsent) {
return CategoriesCompanion( return CategoriesCompanion(
id: Value(id), id: Value(id),
encryptedName: Value(encryptedName), name: Value(name),
serverVersion: Value(serverVersion), serverVersion: Value(serverVersion),
isDeleted: Value(isDeleted), isDeleted: Value(isDeleted),
isDirty: Value(isDirty),
colorValue: colorValue == null && nullToAbsent colorValue: colorValue == null && nullToAbsent
? const Value.absent() ? const Value.absent()
: Value<int?>(colorValue), : Value(colorValue),
iconCodePoint: iconCodePoint == null && nullToAbsent iconCodePoint: iconCodePoint == null && nullToAbsent
? const Value.absent() ? const Value.absent()
: Value<int?>(iconCodePoint), : Value(iconCodePoint),
isDirty: Value(isDirty),
updatedAt: Value(updatedAt), updatedAt: Value(updatedAt),
); );
} }
@@ -909,12 +904,12 @@ class DbCategory extends DataClass implements Insertable<DbCategory> {
serializer ??= driftRuntimeOptions.defaultSerializer; serializer ??= driftRuntimeOptions.defaultSerializer;
return DbCategory( return DbCategory(
id: serializer.fromJson<String>(json['id']), id: serializer.fromJson<String>(json['id']),
encryptedName: serializer.fromJson<String>(json['encryptedName']), name: serializer.fromJson<String>(json['name']),
serverVersion: serializer.fromJson<int>(json['serverVersion']), serverVersion: serializer.fromJson<int>(json['serverVersion']),
isDeleted: serializer.fromJson<bool>(json['isDeleted']), isDeleted: serializer.fromJson<bool>(json['isDeleted']),
isDirty: serializer.fromJson<bool>(json['isDirty']),
colorValue: serializer.fromJson<int?>(json['colorValue']), colorValue: serializer.fromJson<int?>(json['colorValue']),
iconCodePoint: serializer.fromJson<int?>(json['iconCodePoint']), iconCodePoint: serializer.fromJson<int?>(json['iconCodePoint']),
isDirty: serializer.fromJson<bool>(json['isDirty']),
updatedAt: serializer.fromJson<DateTime>(json['updatedAt']), updatedAt: serializer.fromJson<DateTime>(json['updatedAt']),
); );
} }
@@ -923,52 +918,52 @@ class DbCategory extends DataClass implements Insertable<DbCategory> {
serializer ??= driftRuntimeOptions.defaultSerializer; serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{ return <String, dynamic>{
'id': serializer.toJson<String>(id), 'id': serializer.toJson<String>(id),
'encryptedName': serializer.toJson<String>(encryptedName), 'name': serializer.toJson<String>(name),
'serverVersion': serializer.toJson<int>(serverVersion), 'serverVersion': serializer.toJson<int>(serverVersion),
'isDeleted': serializer.toJson<bool>(isDeleted), 'isDeleted': serializer.toJson<bool>(isDeleted),
'isDirty': serializer.toJson<bool>(isDirty),
'colorValue': serializer.toJson<int?>(colorValue), 'colorValue': serializer.toJson<int?>(colorValue),
'iconCodePoint': serializer.toJson<int?>(iconCodePoint), 'iconCodePoint': serializer.toJson<int?>(iconCodePoint),
'isDirty': serializer.toJson<bool>(isDirty),
'updatedAt': serializer.toJson<DateTime>(updatedAt), 'updatedAt': serializer.toJson<DateTime>(updatedAt),
}; };
} }
DbCategory copyWith({ DbCategory copyWith({
String? id, String? id,
String? encryptedName, String? name,
int? serverVersion, int? serverVersion,
bool? isDeleted, bool? isDeleted,
Value<int?> colorValue = const Value.absent(),
Value<int?> iconCodePoint = const Value.absent(),
bool? isDirty, bool? isDirty,
int? colorValue,
int? iconCodePoint,
DateTime? updatedAt, DateTime? updatedAt,
}) => DbCategory( }) => DbCategory(
id: id ?? this.id, id: id ?? this.id,
encryptedName: encryptedName ?? this.encryptedName, name: name ?? this.name,
serverVersion: serverVersion ?? this.serverVersion, serverVersion: serverVersion ?? this.serverVersion,
isDeleted: isDeleted ?? this.isDeleted, isDeleted: isDeleted ?? this.isDeleted,
colorValue: colorValue.present ? colorValue.value : this.colorValue,
iconCodePoint: iconCodePoint.present
? iconCodePoint.value
: this.iconCodePoint,
isDirty: isDirty ?? this.isDirty, isDirty: isDirty ?? this.isDirty,
colorValue: colorValue ?? this.colorValue,
iconCodePoint: iconCodePoint ?? this.iconCodePoint,
updatedAt: updatedAt ?? this.updatedAt, updatedAt: updatedAt ?? this.updatedAt,
); );
DbCategory copyWithCompanion(CategoriesCompanion data) { DbCategory copyWithCompanion(CategoriesCompanion data) {
return DbCategory( return DbCategory(
id: data.id.present ? data.id.value : this.id, id: data.id.present ? data.id.value : this.id,
encryptedName: data.encryptedName.present name: data.name.present ? data.name.value : this.name,
? data.encryptedName.value
: this.encryptedName,
serverVersion: data.serverVersion.present serverVersion: data.serverVersion.present
? data.serverVersion.value ? data.serverVersion.value
: this.serverVersion, : this.serverVersion,
isDeleted: data.isDeleted.present ? data.isDeleted.value : this.isDeleted, isDeleted: data.isDeleted.present ? data.isDeleted.value : this.isDeleted,
isDirty: data.isDirty.present ? data.isDirty.value : this.isDirty,
colorValue: data.colorValue.present colorValue: data.colorValue.present
? data.colorValue.value ? data.colorValue.value
: this.colorValue, : this.colorValue,
iconCodePoint: data.iconCodePoint.present iconCodePoint: data.iconCodePoint.present
? data.iconCodePoint.value ? data.iconCodePoint.value
: this.iconCodePoint, : this.iconCodePoint,
isDirty: data.isDirty.present ? data.isDirty.value : this.isDirty,
updatedAt: data.updatedAt.present ? data.updatedAt.value : this.updatedAt, updatedAt: data.updatedAt.present ? data.updatedAt.value : this.updatedAt,
); );
} }
@@ -977,9 +972,11 @@ class DbCategory extends DataClass implements Insertable<DbCategory> {
String toString() { String toString() {
return (StringBuffer('DbCategory(') return (StringBuffer('DbCategory(')
..write('id: $id, ') ..write('id: $id, ')
..write('encryptedName: $encryptedName, ') ..write('name: $name, ')
..write('serverVersion: $serverVersion, ') ..write('serverVersion: $serverVersion, ')
..write('isDeleted: $isDeleted, ') ..write('isDeleted: $isDeleted, ')
..write('colorValue: $colorValue, ')
..write('iconCodePoint: $iconCodePoint, ')
..write('isDirty: $isDirty, ') ..write('isDirty: $isDirty, ')
..write('updatedAt: $updatedAt') ..write('updatedAt: $updatedAt')
..write(')')) ..write(')'))
@@ -989,9 +986,11 @@ class DbCategory extends DataClass implements Insertable<DbCategory> {
@override @override
int get hashCode => Object.hash( int get hashCode => Object.hash(
id, id,
encryptedName, name,
serverVersion, serverVersion,
isDeleted, isDeleted,
colorValue,
iconCodePoint,
isDirty, isDirty,
updatedAt, updatedAt,
); );
@@ -1000,66 +999,68 @@ class DbCategory extends DataClass implements Insertable<DbCategory> {
identical(this, other) || identical(this, other) ||
(other is DbCategory && (other is DbCategory &&
other.id == this.id && other.id == this.id &&
other.encryptedName == this.encryptedName && other.name == this.name &&
other.serverVersion == this.serverVersion && other.serverVersion == this.serverVersion &&
other.isDeleted == this.isDeleted && other.isDeleted == this.isDeleted &&
other.colorValue == this.colorValue &&
other.iconCodePoint == this.iconCodePoint &&
other.isDirty == this.isDirty && other.isDirty == this.isDirty &&
other.updatedAt == this.updatedAt); other.updatedAt == this.updatedAt);
} }
class CategoriesCompanion extends UpdateCompanion<DbCategory> { class CategoriesCompanion extends UpdateCompanion<DbCategory> {
final Value<String> id; final Value<String> id;
final Value<String> encryptedName; final Value<String> name;
final Value<int> serverVersion; final Value<int> serverVersion;
final Value<bool> isDeleted; final Value<bool> isDeleted;
final Value<int?> colorValue;
final Value<int?> iconCodePoint;
final Value<bool> isDirty; final Value<bool> isDirty;
final Value<DateTime> updatedAt; final Value<DateTime> updatedAt;
final Value<int> rowid; final Value<int> rowid;
final Value<int?> colorValue;
final Value<int?> iconCodePoint;
const CategoriesCompanion({ const CategoriesCompanion({
this.id = const Value.absent(), this.id = const Value.absent(),
this.encryptedName = const Value.absent(), this.name = const Value.absent(),
this.serverVersion = const Value.absent(), this.serverVersion = const Value.absent(),
this.isDeleted = const Value.absent(), this.isDeleted = const Value.absent(),
this.isDirty = const Value.absent(),
this.colorValue = const Value.absent(), this.colorValue = const Value.absent(),
this.iconCodePoint = const Value.absent(), this.iconCodePoint = const Value.absent(),
this.isDirty = const Value.absent(),
this.updatedAt = const Value.absent(), this.updatedAt = const Value.absent(),
this.rowid = const Value.absent(), this.rowid = const Value.absent(),
}); });
CategoriesCompanion.insert({ CategoriesCompanion.insert({
required String id, required String id,
required String encryptedName, required String name,
this.serverVersion = const Value.absent(), this.serverVersion = const Value.absent(),
this.isDeleted = const Value.absent(), this.isDeleted = const Value.absent(),
this.isDirty = const Value.absent(),
this.colorValue = const Value.absent(), this.colorValue = const Value.absent(),
this.iconCodePoint = const Value.absent(), this.iconCodePoint = const Value.absent(),
this.isDirty = const Value.absent(),
required DateTime updatedAt, required DateTime updatedAt,
this.rowid = const Value.absent(), this.rowid = const Value.absent(),
}) : id = Value(id), }) : id = Value(id),
encryptedName = Value(encryptedName), name = Value(name),
updatedAt = Value(updatedAt); updatedAt = Value(updatedAt);
static Insertable<DbCategory> custom({ static Insertable<DbCategory> custom({
Expression<String>? id, Expression<String>? id,
Expression<String>? encryptedName, Expression<String>? name,
Expression<int>? serverVersion, Expression<int>? serverVersion,
Expression<bool>? isDeleted, Expression<bool>? isDeleted,
Expression<bool>? isDirty,
Expression<int>? colorValue, Expression<int>? colorValue,
Expression<int>? iconCodePoint, Expression<int>? iconCodePoint,
Expression<bool>? isDirty,
Expression<DateTime>? updatedAt, Expression<DateTime>? updatedAt,
Expression<int>? rowid, Expression<int>? rowid,
}) { }) {
return RawValuesInsertable({ return RawValuesInsertable({
if (id != null) 'id': id, if (id != null) 'id': id,
if (encryptedName != null) 'encrypted_name': encryptedName, if (name != null) 'name': name,
if (serverVersion != null) 'server_version': serverVersion, if (serverVersion != null) 'server_version': serverVersion,
if (isDeleted != null) 'is_deleted': isDeleted, if (isDeleted != null) 'is_deleted': isDeleted,
if (isDirty != null) 'is_dirty': isDirty,
if (colorValue != null) 'color_value': colorValue, if (colorValue != null) 'color_value': colorValue,
if (iconCodePoint != null) 'icon_code_point': iconCodePoint, if (iconCodePoint != null) 'icon_code_point': iconCodePoint,
if (isDirty != null) 'is_dirty': isDirty,
if (updatedAt != null) 'updated_at': updatedAt, if (updatedAt != null) 'updated_at': updatedAt,
if (rowid != null) 'rowid': rowid, if (rowid != null) 'rowid': rowid,
}); });
@@ -1067,23 +1068,23 @@ class CategoriesCompanion extends UpdateCompanion<DbCategory> {
CategoriesCompanion copyWith({ CategoriesCompanion copyWith({
Value<String>? id, Value<String>? id,
Value<String>? encryptedName, Value<String>? name,
Value<int>? serverVersion, Value<int>? serverVersion,
Value<bool>? isDeleted, Value<bool>? isDeleted,
Value<int?>? colorValue,
Value<int?>? iconCodePoint,
Value<bool>? isDirty, Value<bool>? isDirty,
Value<int>? colorValue,
Value<int>? iconCodePoint,
Value<DateTime>? updatedAt, Value<DateTime>? updatedAt,
Value<int>? rowid, Value<int>? rowid,
}) { }) {
return CategoriesCompanion( return CategoriesCompanion(
id: id ?? this.id, id: id ?? this.id,
encryptedName: encryptedName ?? this.encryptedName, name: name ?? this.name,
serverVersion: serverVersion ?? this.serverVersion, serverVersion: serverVersion ?? this.serverVersion,
isDeleted: isDeleted ?? this.isDeleted, isDeleted: isDeleted ?? this.isDeleted,
isDirty: isDirty ?? this.isDirty,
colorValue: colorValue ?? this.colorValue, colorValue: colorValue ?? this.colorValue,
iconCodePoint: iconCodePoint ?? this.iconCodePoint, iconCodePoint: iconCodePoint ?? this.iconCodePoint,
isDirty: isDirty ?? this.isDirty,
updatedAt: updatedAt ?? this.updatedAt, updatedAt: updatedAt ?? this.updatedAt,
rowid: rowid ?? this.rowid, rowid: rowid ?? this.rowid,
); );
@@ -1095,8 +1096,8 @@ class CategoriesCompanion extends UpdateCompanion<DbCategory> {
if (id.present) { if (id.present) {
map['id'] = Variable<String>(id.value); map['id'] = Variable<String>(id.value);
} }
if (encryptedName.present) { if (name.present) {
map['encrypted_name'] = Variable<String>(encryptedName.value); map['name'] = Variable<String>(name.value);
} }
if (serverVersion.present) { if (serverVersion.present) {
map['server_version'] = Variable<int>(serverVersion.value); map['server_version'] = Variable<int>(serverVersion.value);
@@ -1104,15 +1105,15 @@ class CategoriesCompanion extends UpdateCompanion<DbCategory> {
if (isDeleted.present) { if (isDeleted.present) {
map['is_deleted'] = Variable<bool>(isDeleted.value); map['is_deleted'] = Variable<bool>(isDeleted.value);
} }
if (isDirty.present) {
map['is_dirty'] = Variable<bool>(isDirty.value);
}
if (colorValue.present) { if (colorValue.present) {
map['color_value'] = Variable<int>(colorValue.value); map['color_value'] = Variable<int>(colorValue.value);
} }
if (iconCodePoint.present) { if (iconCodePoint.present) {
map['icon_code_point'] = Variable<int>(iconCodePoint.value); map['icon_code_point'] = Variable<int>(iconCodePoint.value);
} }
if (isDirty.present) {
map['is_dirty'] = Variable<bool>(isDirty.value);
}
if (updatedAt.present) { if (updatedAt.present) {
map['updated_at'] = Variable<DateTime>(updatedAt.value); map['updated_at'] = Variable<DateTime>(updatedAt.value);
} }
@@ -1126,9 +1127,11 @@ class CategoriesCompanion extends UpdateCompanion<DbCategory> {
String toString() { String toString() {
return (StringBuffer('CategoriesCompanion(') return (StringBuffer('CategoriesCompanion(')
..write('id: $id, ') ..write('id: $id, ')
..write('encryptedName: $encryptedName, ') ..write('name: $name, ')
..write('serverVersion: $serverVersion, ') ..write('serverVersion: $serverVersion, ')
..write('isDeleted: $isDeleted, ') ..write('isDeleted: $isDeleted, ')
..write('colorValue: $colorValue, ')
..write('iconCodePoint: $iconCodePoint, ')
..write('isDirty: $isDirty, ') ..write('isDirty: $isDirty, ')
..write('updatedAt: $updatedAt, ') ..write('updatedAt: $updatedAt, ')
..write('rowid: $rowid') ..write('rowid: $rowid')
@@ -1444,9 +1447,11 @@ typedef $$NotesTableProcessedTableManager =
typedef $$CategoriesTableCreateCompanionBuilder = typedef $$CategoriesTableCreateCompanionBuilder =
CategoriesCompanion Function({ CategoriesCompanion Function({
required String id, required String id,
required String encryptedName, required String name,
Value<int> serverVersion, Value<int> serverVersion,
Value<bool> isDeleted, Value<bool> isDeleted,
Value<int?> colorValue,
Value<int?> iconCodePoint,
Value<bool> isDirty, Value<bool> isDirty,
required DateTime updatedAt, required DateTime updatedAt,
Value<int> rowid, Value<int> rowid,
@@ -1454,9 +1459,11 @@ typedef $$CategoriesTableCreateCompanionBuilder =
typedef $$CategoriesTableUpdateCompanionBuilder = typedef $$CategoriesTableUpdateCompanionBuilder =
CategoriesCompanion Function({ CategoriesCompanion Function({
Value<String> id, Value<String> id,
Value<String> encryptedName, Value<String> name,
Value<int> serverVersion, Value<int> serverVersion,
Value<bool> isDeleted, Value<bool> isDeleted,
Value<int?> colorValue,
Value<int?> iconCodePoint,
Value<bool> isDirty, Value<bool> isDirty,
Value<DateTime> updatedAt, Value<DateTime> updatedAt,
Value<int> rowid, Value<int> rowid,
@@ -1476,8 +1483,8 @@ class $$CategoriesTableFilterComposer
builder: (column) => ColumnFilters(column), builder: (column) => ColumnFilters(column),
); );
ColumnFilters<String> get encryptedName => $composableBuilder( ColumnFilters<String> get name => $composableBuilder(
column: $table.encryptedName, column: $table.name,
builder: (column) => ColumnFilters(column), builder: (column) => ColumnFilters(column),
); );
@@ -1491,6 +1498,16 @@ class $$CategoriesTableFilterComposer
builder: (column) => ColumnFilters(column), builder: (column) => ColumnFilters(column),
); );
ColumnFilters<int> get colorValue => $composableBuilder(
column: $table.colorValue,
builder: (column) => ColumnFilters(column),
);
ColumnFilters<int> get iconCodePoint => $composableBuilder(
column: $table.iconCodePoint,
builder: (column) => ColumnFilters(column),
);
ColumnFilters<bool> get isDirty => $composableBuilder( ColumnFilters<bool> get isDirty => $composableBuilder(
column: $table.isDirty, column: $table.isDirty,
builder: (column) => ColumnFilters(column), builder: (column) => ColumnFilters(column),
@@ -1516,8 +1533,8 @@ class $$CategoriesTableOrderingComposer
builder: (column) => ColumnOrderings(column), builder: (column) => ColumnOrderings(column),
); );
ColumnOrderings<String> get encryptedName => $composableBuilder( ColumnOrderings<String> get name => $composableBuilder(
column: $table.encryptedName, column: $table.name,
builder: (column) => ColumnOrderings(column), builder: (column) => ColumnOrderings(column),
); );
@@ -1531,6 +1548,16 @@ class $$CategoriesTableOrderingComposer
builder: (column) => ColumnOrderings(column), builder: (column) => ColumnOrderings(column),
); );
ColumnOrderings<int> get colorValue => $composableBuilder(
column: $table.colorValue,
builder: (column) => ColumnOrderings(column),
);
ColumnOrderings<int> get iconCodePoint => $composableBuilder(
column: $table.iconCodePoint,
builder: (column) => ColumnOrderings(column),
);
ColumnOrderings<bool> get isDirty => $composableBuilder( ColumnOrderings<bool> get isDirty => $composableBuilder(
column: $table.isDirty, column: $table.isDirty,
builder: (column) => ColumnOrderings(column), builder: (column) => ColumnOrderings(column),
@@ -1554,10 +1581,8 @@ class $$CategoriesTableAnnotationComposer
GeneratedColumn<String> get id => GeneratedColumn<String> get id =>
$composableBuilder(column: $table.id, builder: (column) => column); $composableBuilder(column: $table.id, builder: (column) => column);
GeneratedColumn<String> get encryptedName => $composableBuilder( GeneratedColumn<String> get name =>
column: $table.encryptedName, $composableBuilder(column: $table.name, builder: (column) => column);
builder: (column) => column,
);
GeneratedColumn<int> get serverVersion => $composableBuilder( GeneratedColumn<int> get serverVersion => $composableBuilder(
column: $table.serverVersion, column: $table.serverVersion,
@@ -1567,6 +1592,16 @@ class $$CategoriesTableAnnotationComposer
GeneratedColumn<bool> get isDeleted => GeneratedColumn<bool> get isDeleted =>
$composableBuilder(column: $table.isDeleted, builder: (column) => column); $composableBuilder(column: $table.isDeleted, builder: (column) => column);
GeneratedColumn<int> get colorValue => $composableBuilder(
column: $table.colorValue,
builder: (column) => column,
);
GeneratedColumn<int> get iconCodePoint => $composableBuilder(
column: $table.iconCodePoint,
builder: (column) => column,
);
GeneratedColumn<bool> get isDirty => GeneratedColumn<bool> get isDirty =>
$composableBuilder(column: $table.isDirty, builder: (column) => column); $composableBuilder(column: $table.isDirty, builder: (column) => column);
@@ -1606,17 +1641,21 @@ class $$CategoriesTableTableManager
updateCompanionCallback: updateCompanionCallback:
({ ({
Value<String> id = const Value.absent(), Value<String> id = const Value.absent(),
Value<String> encryptedName = const Value.absent(), Value<String> name = const Value.absent(),
Value<int> serverVersion = const Value.absent(), Value<int> serverVersion = const Value.absent(),
Value<bool> isDeleted = const Value.absent(), Value<bool> isDeleted = const Value.absent(),
Value<int?> colorValue = const Value.absent(),
Value<int?> iconCodePoint = const Value.absent(),
Value<bool> isDirty = const Value.absent(), Value<bool> isDirty = const Value.absent(),
Value<DateTime> updatedAt = const Value.absent(), Value<DateTime> updatedAt = const Value.absent(),
Value<int> rowid = const Value.absent(), Value<int> rowid = const Value.absent(),
}) => CategoriesCompanion( }) => CategoriesCompanion(
id: id, id: id,
encryptedName: encryptedName, name: name,
serverVersion: serverVersion, serverVersion: serverVersion,
isDeleted: isDeleted, isDeleted: isDeleted,
colorValue: colorValue,
iconCodePoint: iconCodePoint,
isDirty: isDirty, isDirty: isDirty,
updatedAt: updatedAt, updatedAt: updatedAt,
rowid: rowid, rowid: rowid,
@@ -1624,17 +1663,21 @@ class $$CategoriesTableTableManager
createCompanionCallback: createCompanionCallback:
({ ({
required String id, required String id,
required String encryptedName, required String name,
Value<int> serverVersion = const Value.absent(), Value<int> serverVersion = const Value.absent(),
Value<bool> isDeleted = const Value.absent(), Value<bool> isDeleted = const Value.absent(),
Value<int?> colorValue = const Value.absent(),
Value<int?> iconCodePoint = const Value.absent(),
Value<bool> isDirty = const Value.absent(), Value<bool> isDirty = const Value.absent(),
required DateTime updatedAt, required DateTime updatedAt,
Value<int> rowid = const Value.absent(), Value<int> rowid = const Value.absent(),
}) => CategoriesCompanion.insert( }) => CategoriesCompanion.insert(
id: id, id: id,
encryptedName: encryptedName, name: name,
serverVersion: serverVersion, serverVersion: serverVersion,
isDeleted: isDeleted, isDeleted: isDeleted,
colorValue: colorValue,
iconCodePoint: iconCodePoint,
isDirty: isDirty, isDirty: isDirty,
updatedAt: updatedAt, updatedAt: updatedAt,
rowid: rowid, rowid: rowid,
+20 -23
View File
@@ -39,15 +39,10 @@ class NoteRepository {
final List<DbCategory> dbCategories = await _database.getAllCategories(); final List<DbCategory> dbCategories = await _database.getAllCategories();
final List<Category> categories = []; final List<Category> categories = [];
for (final DbCategory row in dbCategories) { for (final DbCategory row in dbCategories) {
try {
final String decryptedName = await NoteEncryption.decryptNote(
row.encryptedName,
_masterKey,
);
categories.add( categories.add(
Category( Category(
id: row.id, id: row.id,
name: decryptedName, name: row.name,
serverVersion: row.serverVersion, serverVersion: row.serverVersion,
isDeleted: row.isDeleted, isDeleted: row.isDeleted,
updatedAt: row.updatedAt, updatedAt: row.updatedAt,
@@ -56,24 +51,17 @@ class NoteRepository {
iconCodePoint: row.iconCodePoint, iconCodePoint: row.iconCodePoint,
), ),
); );
} catch (e) {
debugPrint('Error al desencriptar categoría: $e');
}
} }
return categories; return categories;
} }
Future<void> createCategory(Category category) async { Future<void> createCategory(Category category) async {
debugPrint('createCategory called with: ${category.name}'); debugPrint('createCategory called with: ${category.name}');
final String encryptedName = await NoteEncryption.encryptNote(
category.name,
_masterKey,
);
debugPrint('Category name encrypted');
await _database.upsertCategory( await _database.upsertCategory(
CategoriesCompanion.insert( CategoriesCompanion.insert(
id: category.id, id: category.id,
encryptedName: encryptedName, name: category.name,
updatedAt: category.updatedAt, updatedAt: category.updatedAt,
serverVersion: const Value(0), serverVersion: const Value(0),
isDeleted: const Value(false), isDeleted: const Value(false),
@@ -317,14 +305,15 @@ class NoteRepository {
// Apply categories from server // Apply categories from server
for (final SyncCategoryResponse catResponse for (final SyncCategoryResponse catResponse
in response.changes.categories) { in response.changes.categories) {
// Store the encrypted blob received from the server directly in the DB. final String plainName = await _plainCategoryName(
// Decryption is only performed when loading categories for display. catResponse.encryptedName,
final String encryptedBlob = catResponse.encryptedName; _masterKey,
);
await _database.upsertCategory( await _database.upsertCategory(
CategoriesCompanion( CategoriesCompanion(
id: Value(catResponse.id), id: Value(catResponse.id),
encryptedName: Value(encryptedBlob), name: Value(plainName),
serverVersion: Value(catResponse.serverVersion), serverVersion: Value(catResponse.serverVersion),
isDeleted: Value(catResponse.isDeleted), isDeleted: Value(catResponse.isDeleted),
colorValue: Value<int?>(catResponse.colorValue), colorValue: Value<int?>(catResponse.colorValue),
@@ -490,16 +479,16 @@ Future<List<SyncCategoryPayload>> _encryptCategories(
final List<SyncCategoryPayload> payloads = []; final List<SyncCategoryPayload> payloads = [];
for (final DbCategory row in categories) { for (final DbCategory row in categories) {
// The DB already stores the encrypted name blob in `encryptedName`. // The DB stores the plain category name locally.
// Use it directly when building the sync payload and preserve // Use it directly when building the sync payload and preserve
// color/icon values from the DB row so they are sent to the server. // color/icon values from the DB row so they are sent to the server.
final String encryptedName = row.encryptedName; final String plainName = row.name;
payloads.add( payloads.add(
SyncCategoryPayload.fromCategory( SyncCategoryPayload.fromCategory(
Category( Category(
id: row.id, id: row.id,
name: row.encryptedName, name: plainName,
serverVersion: row.serverVersion, serverVersion: row.serverVersion,
isDeleted: row.isDeleted, isDeleted: row.isDeleted,
updatedAt: row.updatedAt, updatedAt: row.updatedAt,
@@ -507,7 +496,7 @@ Future<List<SyncCategoryPayload>> _encryptCategories(
colorValue: row.colorValue, colorValue: row.colorValue,
iconCodePoint: row.iconCodePoint, iconCodePoint: row.iconCodePoint,
), ),
encryptedName: encryptedName, encryptedName: await NoteEncryption.encryptNote(plainName, masterKey),
), ),
); );
} }
@@ -709,3 +698,11 @@ int _parallelWorkerCount(int itemCount) {
); );
return math.max(1, math.min(itemCount, cappedByCpu)); return math.max(1, math.min(itemCount, cappedByCpu));
} }
Future<String> _plainCategoryName(String storedName, String masterKey) async {
try {
return await NoteEncryption.decryptNote(storedName, masterKey);
} catch (_) {
return storedName;
}
}
+63 -8
View File
@@ -1,3 +1,4 @@
import 'dart:async';
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
@@ -832,13 +833,17 @@ class _CategoryDialogState extends State<_CategoryDialog> {
Color? _selectedColor; Color? _selectedColor;
IconData? _selectedIcon; IconData? _selectedIcon;
int _selectedSection = 0; int _selectedSection = 0;
bool _nameHasError = false;
bool _isSaving = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_controller = TextEditingController(text: widget.category?.name ?? ''); _controller = TextEditingController(text: widget.category?.name ?? '');
_selectedColor = _selectedColor =
widget.category != null && widget.category!.colorValue != null widget.category == null
? CategoryStyle.colors.first
: widget.category!.colorValue != null
? Color(widget.category!.colorValue!) ? Color(widget.category!.colorValue!)
: null; : null;
if (widget.category != null && widget.category!.iconCodePoint != null) { if (widget.category != null && widget.category!.iconCodePoint != null) {
@@ -846,6 +851,8 @@ class _CategoryDialogState extends State<_CategoryDialog> {
(IconData icon) => icon.codePoint == widget.category!.iconCodePoint, (IconData icon) => icon.codePoint == widget.category!.iconCodePoint,
orElse: () => CategoryStyle.icons.first, orElse: () => CategoryStyle.icons.first,
); );
} else if (widget.category == null) {
_selectedIcon = CategoryStyle.icons.first;
} }
} }
@@ -856,12 +863,24 @@ class _CategoryDialogState extends State<_CategoryDialog> {
} }
Future<void> _saveCategory() async { Future<void> _saveCategory() async {
if (_isSaving) {
return;
}
final String name = _controller.text.trim(); final String name = _controller.text.trim();
if (name.isEmpty) { if (name.isEmpty) {
setState(() {
_nameHasError = true;
});
return; return;
} }
try { try {
setState(() {
_nameHasError = false;
_isSaving = true;
});
final Category newCategory = Category( final Category newCategory = Category(
id: widget.category?.id, id: widget.category?.id,
name: name, name: name,
@@ -881,16 +900,19 @@ class _CategoryDialogState extends State<_CategoryDialog> {
await widget.repository.createCategory(newCategory); await widget.repository.createCategory(newCategory);
await widget.onCategoriesChanged(); await widget.onCategoriesChanged();
try {
await widget.onRequestSync();
} catch (_) {}
if (mounted) { if (mounted) {
await widget.onCategoryDeleted();
if (!mounted) return;
Navigator.pop(context); Navigator.pop(context);
} }
widget.onRequestSync().catchError((_) {});
} catch (e) { } catch (e) {
debugPrint('ERROR creating category: $e'); debugPrint('ERROR creating category: $e');
if (mounted) {
setState(() {
_isSaving = false;
});
}
if (mounted) { if (mounted) {
ScaffoldMessenger.of( ScaffoldMessenger.of(
context, context,
@@ -899,6 +921,24 @@ class _CategoryDialogState extends State<_CategoryDialog> {
} }
} }
Future<void> _runPostSaveCallbacks({
required Future<void> Function() onCategoriesChanged,
required Future<void> Function() onRequestSync,
required Future<void> Function() onCategoryDeleted,
}) async {
try {
await onCategoriesChanged();
} catch (_) {}
try {
await onCategoryDeleted();
} catch (_) {}
unawaited(
onRequestSync().catchError((_) {}),
);
}
Future<void> _deleteCategory() async { Future<void> _deleteCategory() async {
final bool? confirm = await showDialog<bool>( final bool? confirm = await showDialog<bool>(
context: context, context: context,
@@ -954,8 +994,17 @@ class _CategoryDialogState extends State<_CategoryDialog> {
children: [ children: [
TextField( TextField(
controller: _controller, controller: _controller,
onChanged: (_) {
if (_nameHasError) {
setState(() {
_nameHasError = false;
});
}
},
decoration: const InputDecoration( decoration: const InputDecoration(
hintText: 'Nombre de la categoría', hintText: 'Nombre de la categoría',
).copyWith(
errorText: _nameHasError ? 'El nombre es obligatorio' : null,
), ),
), ),
const SizedBox(height: 16), const SizedBox(height: 16),
@@ -1085,8 +1134,14 @@ class _CategoryDialogState extends State<_CategoryDialog> {
child: const Text('Cancelar'), child: const Text('Cancelar'),
), ),
TextButton( TextButton(
onPressed: _saveCategory, onPressed: _isSaving ? null : _saveCategory,
child: Text(widget.category == null ? 'Crear' : 'Guardar'), child: _isSaving
? const SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(strokeWidth: 2),
)
: Text(widget.category == null ? 'Crear' : 'Guardar'),
), ),
], ],
); );