Make showUnit nullable

This commit is contained in:
Brandon Presley 2023-06-25 15:48:26 +12:00
parent 69f7e0c87b
commit 74b25e4e8f
2 changed files with 19 additions and 18 deletions

View File

@ -13,7 +13,7 @@ class Setting extends DataClass implements Insertable<Setting> {
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<Setting> {
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<Setting> {
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<Setting> {
}
map['notify'] = Variable<bool>(notify);
map['images'] = Variable<bool>(images);
map['show_unit'] = Variable<bool>(showUnit);
if (!nullToAbsent || showUnit != null) {
map['show_unit'] = Variable<bool?>(showUnit);
}
if (!nullToAbsent || lightColor != null) {
map['light_color'] = Variable<String?>(lightColor);
}
@ -110,7 +112,9 @@ class Setting extends DataClass implements Insertable<Setting> {
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<Setting> {
sound: serializer.fromJson<String?>(json['sound']),
notify: serializer.fromJson<bool>(json['notify']),
images: serializer.fromJson<bool>(json['images']),
showUnit: serializer.fromJson<bool>(json['showUnit']),
showUnit: serializer.fromJson<bool?>(json['showUnit']),
lightColor: serializer.fromJson<String?>(json['lightColor']),
darkColor: serializer.fromJson<String?>(json['darkColor']),
steps: serializer.fromJson<bool>(json['steps']),
@ -157,7 +161,7 @@ class Setting extends DataClass implements Insertable<Setting> {
'sound': serializer.toJson<String?>(sound),
'notify': serializer.toJson<bool>(notify),
'images': serializer.toJson<bool>(images),
'showUnit': serializer.toJson<bool>(showUnit),
'showUnit': serializer.toJson<bool?>(showUnit),
'lightColor': serializer.toJson<String?>(lightColor),
'darkColor': serializer.toJson<String?>(darkColor),
'steps': serializer.toJson<bool>(steps),
@ -269,7 +273,7 @@ class SettingsCompanion extends UpdateCompanion<Setting> {
final Value<String?> sound;
final Value<bool> notify;
final Value<bool> images;
final Value<bool> showUnit;
final Value<bool?> showUnit;
final Value<String?> lightColor;
final Value<String?> darkColor;
final Value<bool> steps;
@ -302,7 +306,7 @@ class SettingsCompanion extends UpdateCompanion<Setting> {
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<Setting> {
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<Setting> {
Expression<String?>? sound,
Expression<bool>? notify,
Expression<bool>? images,
Expression<bool>? showUnit,
Expression<bool?>? showUnit,
Expression<String?>? lightColor,
Expression<String?>? darkColor,
Expression<bool>? steps,
@ -366,7 +369,7 @@ class SettingsCompanion extends UpdateCompanion<Setting> {
Value<String?>? sound,
Value<bool>? notify,
Value<bool>? images,
Value<bool>? showUnit,
Value<bool?>? showUnit,
Value<String?>? lightColor,
Value<String?>? darkColor,
Value<bool>? steps,
@ -414,7 +417,7 @@ class SettingsCompanion extends UpdateCompanion<Setting> {
map['images'] = Variable<bool>(images.value);
}
if (showUnit.present) {
map['show_unit'] = Variable<bool>(showUnit.value);
map['show_unit'] = Variable<bool?>(showUnit.value);
}
if (lightColor.present) {
map['light_color'] = Variable<String?>(lightColor.value);
@ -510,9 +513,9 @@ class $SettingsTable extends Settings with TableInfo<$SettingsTable, Setting> {
final VerificationMeta _showUnitMeta = const VerificationMeta('showUnit');
@override
late final GeneratedColumn<bool?> showUnit = GeneratedColumn<bool?>(
'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(

View File

@ -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()();