From 74b25e4e8f8d187e5a12e025e9c9f49b21a82c6d Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Sun, 25 Jun 2023 15:48:26 +1200 Subject: [PATCH] Make showUnit nullable --- lib/database.g.dart | 35 ++++++++++++++++++----------------- lib/settings.dart | 2 +- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/database.g.dart b/lib/database.g.dart index da3949c..00be3da 100644 --- a/lib/database.g.dart +++ b/lib/database.g.dart @@ -13,7 +13,7 @@ class Setting extends DataClass implements Insertable { final String? sound; final bool notify; final bool images; - final bool showUnit; + final bool? showUnit; final String? lightColor; final String? darkColor; final bool steps; @@ -29,7 +29,7 @@ class Setting extends DataClass implements Insertable { this.sound, required this.notify, required this.images, - required this.showUnit, + this.showUnit, this.lightColor, this.darkColor, required this.steps, @@ -54,7 +54,7 @@ class Setting extends DataClass implements Insertable { images: const BoolType() .mapFromDatabaseResponse(data['${effectivePrefix}images'])!, showUnit: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}show_unit'])!, + .mapFromDatabaseResponse(data['${effectivePrefix}show_unit']), lightColor: const StringType() .mapFromDatabaseResponse(data['${effectivePrefix}light_color']), darkColor: const StringType() @@ -85,7 +85,9 @@ class Setting extends DataClass implements Insertable { } map['notify'] = Variable(notify); map['images'] = Variable(images); - map['show_unit'] = Variable(showUnit); + if (!nullToAbsent || showUnit != null) { + map['show_unit'] = Variable(showUnit); + } if (!nullToAbsent || lightColor != null) { map['light_color'] = Variable(lightColor); } @@ -110,7 +112,9 @@ class Setting extends DataClass implements Insertable { sound == null && nullToAbsent ? const Value.absent() : Value(sound), notify: Value(notify), images: Value(images), - showUnit: Value(showUnit), + showUnit: showUnit == null && nullToAbsent + ? const Value.absent() + : Value(showUnit), lightColor: lightColor == null && nullToAbsent ? const Value.absent() : Value(lightColor), @@ -136,7 +140,7 @@ class Setting extends DataClass implements Insertable { sound: serializer.fromJson(json['sound']), notify: serializer.fromJson(json['notify']), images: serializer.fromJson(json['images']), - showUnit: serializer.fromJson(json['showUnit']), + showUnit: serializer.fromJson(json['showUnit']), lightColor: serializer.fromJson(json['lightColor']), darkColor: serializer.fromJson(json['darkColor']), steps: serializer.fromJson(json['steps']), @@ -157,7 +161,7 @@ class Setting extends DataClass implements Insertable { 'sound': serializer.toJson(sound), 'notify': serializer.toJson(notify), 'images': serializer.toJson(images), - 'showUnit': serializer.toJson(showUnit), + 'showUnit': serializer.toJson(showUnit), 'lightColor': serializer.toJson(lightColor), 'darkColor': serializer.toJson(darkColor), 'steps': serializer.toJson(steps), @@ -269,7 +273,7 @@ class SettingsCompanion extends UpdateCompanion { final Value sound; final Value notify; final Value images; - final Value showUnit; + final Value showUnit; final Value lightColor; final Value darkColor; final Value steps; @@ -302,7 +306,7 @@ class SettingsCompanion extends UpdateCompanion { this.sound = const Value.absent(), required bool notify, required bool images, - required bool showUnit, + this.showUnit = const Value.absent(), this.lightColor = const Value.absent(), this.darkColor = const Value.absent(), required bool steps, @@ -316,7 +320,6 @@ class SettingsCompanion extends UpdateCompanion { vibrate = Value(vibrate), notify = Value(notify), images = Value(images), - showUnit = Value(showUnit), steps = Value(steps), date = Value(date), showDate = Value(showDate), @@ -330,7 +333,7 @@ class SettingsCompanion extends UpdateCompanion { Expression? sound, Expression? notify, Expression? images, - Expression? showUnit, + Expression? showUnit, Expression? lightColor, Expression? darkColor, Expression? steps, @@ -366,7 +369,7 @@ class SettingsCompanion extends UpdateCompanion { Value? sound, Value? notify, Value? images, - Value? showUnit, + Value? showUnit, Value? lightColor, Value? darkColor, Value? steps, @@ -414,7 +417,7 @@ class SettingsCompanion extends UpdateCompanion { map['images'] = Variable(images.value); } if (showUnit.present) { - map['show_unit'] = Variable(showUnit.value); + map['show_unit'] = Variable(showUnit.value); } if (lightColor.present) { map['light_color'] = Variable(lightColor.value); @@ -510,9 +513,9 @@ class $SettingsTable extends Settings with TableInfo<$SettingsTable, Setting> { final VerificationMeta _showUnitMeta = const VerificationMeta('showUnit'); @override late final GeneratedColumn showUnit = GeneratedColumn( - 'show_unit', aliasedName, false, + 'show_unit', aliasedName, true, type: const BoolType(), - requiredDuringInsert: true, + requiredDuringInsert: false, defaultConstraints: 'CHECK (show_unit IN (0, 1))'); final VerificationMeta _lightColorMeta = const VerificationMeta('lightColor'); @override @@ -627,8 +630,6 @@ class $SettingsTable extends Settings with TableInfo<$SettingsTable, Setting> { if (data.containsKey('show_unit')) { context.handle(_showUnitMeta, showUnit.isAcceptableOrUnknown(data['show_unit']!, _showUnitMeta)); - } else if (isInserting) { - context.missing(_showUnitMeta); } if (data.containsKey('light_color')) { context.handle( diff --git a/lib/settings.dart b/lib/settings.dart index c528810..23fef36 100644 --- a/lib/settings.dart +++ b/lib/settings.dart @@ -25,7 +25,7 @@ class Settings extends Table { TextColumn get sound => text().nullable()(); BoolColumn get notify => boolean()(); BoolColumn get images => boolean()(); - BoolColumn get showUnit => boolean()(); + BoolColumn get showUnit => boolean().nullable()(); TextColumn get lightColor => text().nullable()(); TextColumn get darkColor => text().nullable()(); BoolColumn get steps => boolean()();