From 11eff63314ca1341cade202fa7764a9df6627ccb Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Fri, 10 Nov 2023 16:16:12 +1300 Subject: [PATCH] Update gym_set schema --- lib/database.g.dart | 957 +++++++++++++++++++++-------------------- lib/edit_set.dart | 4 +- lib/gym_set.dart | 7 +- lib/settings_page.dart | 8 +- 4 files changed, 493 insertions(+), 483 deletions(-) diff --git a/lib/database.g.dart b/lib/database.g.dart index 00be3da..2670b88 100644 --- a/lib/database.g.dart +++ b/lib/database.g.dart @@ -9,125 +9,154 @@ part of 'database.dart'; // ignore_for_file: type=lint class Setting extends DataClass implements Insertable { final bool alarm; - final bool vibrate; - final String? sound; - final bool notify; - final bool images; - final bool? showUnit; - final String? lightColor; + final bool? backup; final String? darkColor; - final bool steps; - final String date; - final bool showDate; - final String theme; - final bool showSets; - final bool noSound; - final bool backup; + final String? date; + final bool? images; + final String? lightColor; + final bool? noSound; + final bool? notify; + final bool? showDate; + final bool? showSets; + final bool? showUnit; + final String? sound; + final bool? steps; + final String? theme; + final bool vibrate; Setting( {required this.alarm, - required this.vibrate, - this.sound, - required this.notify, - required this.images, - this.showUnit, - this.lightColor, + this.backup, this.darkColor, - required this.steps, - required this.date, - required this.showDate, - required this.theme, - required this.showSets, - required this.noSound, - required this.backup}); + this.date, + this.images, + this.lightColor, + this.noSound, + this.notify, + this.showDate, + this.showSets, + this.showUnit, + this.sound, + this.steps, + this.theme, + required this.vibrate}); factory Setting.fromData(Map data, GeneratedDatabase db, {String? prefix}) { final effectivePrefix = prefix ?? ''; return Setting( alarm: const BoolType() .mapFromDatabaseResponse(data['${effectivePrefix}alarm'])!, - vibrate: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}vibrate'])!, - sound: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}sound']), - notify: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}notify'])!, - images: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}images'])!, - showUnit: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}show_unit']), - lightColor: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}light_color']), + backup: const BoolType() + .mapFromDatabaseResponse(data['${effectivePrefix}backup']), darkColor: const StringType() .mapFromDatabaseResponse(data['${effectivePrefix}dark_color']), - steps: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}steps'])!, date: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}date'])!, - showDate: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}show_date'])!, - theme: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}theme'])!, - showSets: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}show_sets'])!, + .mapFromDatabaseResponse(data['${effectivePrefix}date']), + images: const BoolType() + .mapFromDatabaseResponse(data['${effectivePrefix}images']), + lightColor: const StringType() + .mapFromDatabaseResponse(data['${effectivePrefix}light_color']), noSound: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}no_sound'])!, - backup: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}backup'])!, + .mapFromDatabaseResponse(data['${effectivePrefix}no_sound']), + notify: const BoolType() + .mapFromDatabaseResponse(data['${effectivePrefix}notify']), + showDate: const BoolType() + .mapFromDatabaseResponse(data['${effectivePrefix}show_date']), + showSets: const BoolType() + .mapFromDatabaseResponse(data['${effectivePrefix}show_sets']), + showUnit: const BoolType() + .mapFromDatabaseResponse(data['${effectivePrefix}show_unit']), + sound: const StringType() + .mapFromDatabaseResponse(data['${effectivePrefix}sound']), + steps: const BoolType() + .mapFromDatabaseResponse(data['${effectivePrefix}steps']), + theme: const StringType() + .mapFromDatabaseResponse(data['${effectivePrefix}theme']), + vibrate: const BoolType() + .mapFromDatabaseResponse(data['${effectivePrefix}vibrate'])!, ); } @override Map toColumns(bool nullToAbsent) { final map = {}; map['alarm'] = Variable(alarm); - map['vibrate'] = Variable(vibrate); - if (!nullToAbsent || sound != null) { - map['sound'] = Variable(sound); - } - map['notify'] = Variable(notify); - map['images'] = Variable(images); - if (!nullToAbsent || showUnit != null) { - map['show_unit'] = Variable(showUnit); - } - if (!nullToAbsent || lightColor != null) { - map['light_color'] = Variable(lightColor); + if (!nullToAbsent || backup != null) { + map['backup'] = Variable(backup); } if (!nullToAbsent || darkColor != null) { map['dark_color'] = Variable(darkColor); } - map['steps'] = Variable(steps); - map['date'] = Variable(date); - map['show_date'] = Variable(showDate); - map['theme'] = Variable(theme); - map['show_sets'] = Variable(showSets); - map['no_sound'] = Variable(noSound); - map['backup'] = Variable(backup); + if (!nullToAbsent || date != null) { + map['date'] = Variable(date); + } + if (!nullToAbsent || images != null) { + map['images'] = Variable(images); + } + if (!nullToAbsent || lightColor != null) { + map['light_color'] = Variable(lightColor); + } + if (!nullToAbsent || noSound != null) { + map['no_sound'] = Variable(noSound); + } + if (!nullToAbsent || notify != null) { + map['notify'] = Variable(notify); + } + if (!nullToAbsent || showDate != null) { + map['show_date'] = Variable(showDate); + } + if (!nullToAbsent || showSets != null) { + map['show_sets'] = Variable(showSets); + } + if (!nullToAbsent || showUnit != null) { + map['show_unit'] = Variable(showUnit); + } + if (!nullToAbsent || sound != null) { + map['sound'] = Variable(sound); + } + if (!nullToAbsent || steps != null) { + map['steps'] = Variable(steps); + } + if (!nullToAbsent || theme != null) { + map['theme'] = Variable(theme); + } + map['vibrate'] = Variable(vibrate); return map; } SettingsCompanion toCompanion(bool nullToAbsent) { return SettingsCompanion( alarm: Value(alarm), - vibrate: Value(vibrate), - sound: - sound == null && nullToAbsent ? const Value.absent() : Value(sound), - notify: Value(notify), - images: Value(images), - showUnit: showUnit == null && nullToAbsent - ? const Value.absent() - : Value(showUnit), - lightColor: lightColor == null && nullToAbsent - ? const Value.absent() - : Value(lightColor), + backup: + backup == null && nullToAbsent ? const Value.absent() : Value(backup), darkColor: darkColor == null && nullToAbsent ? const Value.absent() : Value(darkColor), - steps: Value(steps), - date: Value(date), - showDate: Value(showDate), - theme: Value(theme), - showSets: Value(showSets), - noSound: Value(noSound), - backup: Value(backup), + date: date == null && nullToAbsent ? const Value.absent() : Value(date), + images: + images == null && nullToAbsent ? const Value.absent() : Value(images), + lightColor: lightColor == null && nullToAbsent + ? const Value.absent() + : Value(lightColor), + noSound: noSound == null && nullToAbsent + ? const Value.absent() + : Value(noSound), + notify: + notify == null && nullToAbsent ? const Value.absent() : Value(notify), + showDate: showDate == null && nullToAbsent + ? const Value.absent() + : Value(showDate), + showSets: showSets == null && nullToAbsent + ? const Value.absent() + : Value(showSets), + showUnit: showUnit == null && nullToAbsent + ? const Value.absent() + : Value(showUnit), + sound: + sound == null && nullToAbsent ? const Value.absent() : Value(sound), + steps: + steps == null && nullToAbsent ? const Value.absent() : Value(steps), + theme: + theme == null && nullToAbsent ? const Value.absent() : Value(theme), + vibrate: Value(vibrate), ); } @@ -136,20 +165,20 @@ class Setting extends DataClass implements Insertable { serializer ??= moorRuntimeOptions.defaultSerializer; return Setting( alarm: serializer.fromJson(json['alarm']), - vibrate: serializer.fromJson(json['vibrate']), - sound: serializer.fromJson(json['sound']), - notify: serializer.fromJson(json['notify']), - images: serializer.fromJson(json['images']), - showUnit: serializer.fromJson(json['showUnit']), - lightColor: serializer.fromJson(json['lightColor']), + backup: serializer.fromJson(json['backup']), darkColor: serializer.fromJson(json['darkColor']), - steps: serializer.fromJson(json['steps']), - date: serializer.fromJson(json['date']), - showDate: serializer.fromJson(json['showDate']), - theme: serializer.fromJson(json['theme']), - showSets: serializer.fromJson(json['showSets']), - noSound: serializer.fromJson(json['noSound']), - backup: serializer.fromJson(json['backup']), + date: serializer.fromJson(json['date']), + images: serializer.fromJson(json['images']), + lightColor: serializer.fromJson(json['lightColor']), + noSound: serializer.fromJson(json['noSound']), + notify: serializer.fromJson(json['notify']), + showDate: serializer.fromJson(json['showDate']), + showSets: serializer.fromJson(json['showSets']), + showUnit: serializer.fromJson(json['showUnit']), + sound: serializer.fromJson(json['sound']), + steps: serializer.fromJson(json['steps']), + theme: serializer.fromJson(json['theme']), + vibrate: serializer.fromJson(json['vibrate']), ); } @override @@ -157,74 +186,74 @@ class Setting extends DataClass implements Insertable { serializer ??= moorRuntimeOptions.defaultSerializer; return { 'alarm': serializer.toJson(alarm), - 'vibrate': serializer.toJson(vibrate), - 'sound': serializer.toJson(sound), - 'notify': serializer.toJson(notify), - 'images': serializer.toJson(images), - 'showUnit': serializer.toJson(showUnit), - 'lightColor': serializer.toJson(lightColor), + 'backup': serializer.toJson(backup), 'darkColor': serializer.toJson(darkColor), - 'steps': serializer.toJson(steps), - 'date': serializer.toJson(date), - 'showDate': serializer.toJson(showDate), - 'theme': serializer.toJson(theme), - 'showSets': serializer.toJson(showSets), - 'noSound': serializer.toJson(noSound), - 'backup': serializer.toJson(backup), + 'date': serializer.toJson(date), + 'images': serializer.toJson(images), + 'lightColor': serializer.toJson(lightColor), + 'noSound': serializer.toJson(noSound), + 'notify': serializer.toJson(notify), + 'showDate': serializer.toJson(showDate), + 'showSets': serializer.toJson(showSets), + 'showUnit': serializer.toJson(showUnit), + 'sound': serializer.toJson(sound), + 'steps': serializer.toJson(steps), + 'theme': serializer.toJson(theme), + 'vibrate': serializer.toJson(vibrate), }; } Setting copyWith( {bool? alarm, - bool? vibrate, - String? sound, - bool? notify, - bool? images, - bool? showUnit, - String? lightColor, + bool? backup, String? darkColor, - bool? steps, String? date, - bool? showDate, - String? theme, - bool? showSets, + bool? images, + String? lightColor, bool? noSound, - bool? backup}) => + bool? notify, + bool? showDate, + bool? showSets, + bool? showUnit, + String? sound, + bool? steps, + String? theme, + bool? vibrate}) => Setting( alarm: alarm ?? this.alarm, - vibrate: vibrate ?? this.vibrate, - sound: sound ?? this.sound, - notify: notify ?? this.notify, - images: images ?? this.images, - showUnit: showUnit ?? this.showUnit, - lightColor: lightColor ?? this.lightColor, - darkColor: darkColor ?? this.darkColor, - steps: steps ?? this.steps, - date: date ?? this.date, - showDate: showDate ?? this.showDate, - theme: theme ?? this.theme, - showSets: showSets ?? this.showSets, - noSound: noSound ?? this.noSound, backup: backup ?? this.backup, + darkColor: darkColor ?? this.darkColor, + date: date ?? this.date, + images: images ?? this.images, + lightColor: lightColor ?? this.lightColor, + noSound: noSound ?? this.noSound, + notify: notify ?? this.notify, + showDate: showDate ?? this.showDate, + showSets: showSets ?? this.showSets, + showUnit: showUnit ?? this.showUnit, + sound: sound ?? this.sound, + steps: steps ?? this.steps, + theme: theme ?? this.theme, + vibrate: vibrate ?? this.vibrate, ); @override String toString() { return (StringBuffer('Setting(') ..write('alarm: $alarm, ') - ..write('vibrate: $vibrate, ') - ..write('sound: $sound, ') - ..write('notify: $notify, ') - ..write('images: $images, ') - ..write('showUnit: $showUnit, ') - ..write('lightColor: $lightColor, ') + ..write('backup: $backup, ') ..write('darkColor: $darkColor, ') - ..write('steps: $steps, ') ..write('date: $date, ') - ..write('showDate: $showDate, ') - ..write('theme: $theme, ') - ..write('showSets: $showSets, ') + ..write('images: $images, ') + ..write('lightColor: $lightColor, ') ..write('noSound: $noSound, ') - ..write('backup: $backup') + ..write('notify: $notify, ') + ..write('showDate: $showDate, ') + ..write('showSets: $showSets, ') + ..write('showUnit: $showUnit, ') + ..write('sound: $sound, ') + ..write('steps: $steps, ') + ..write('theme: $theme, ') + ..write('vibrate: $vibrate') ..write(')')) .toString(); } @@ -232,169 +261,160 @@ class Setting extends DataClass implements Insertable { @override int get hashCode => Object.hash( alarm, - vibrate, - sound, - notify, - images, - showUnit, - lightColor, + backup, darkColor, - steps, date, - showDate, - theme, - showSets, + images, + lightColor, noSound, - backup); + notify, + showDate, + showSets, + showUnit, + sound, + steps, + theme, + vibrate); @override bool operator ==(Object other) => identical(this, other) || (other is Setting && other.alarm == this.alarm && - other.vibrate == this.vibrate && - other.sound == this.sound && - other.notify == this.notify && - other.images == this.images && - other.showUnit == this.showUnit && - other.lightColor == this.lightColor && + other.backup == this.backup && other.darkColor == this.darkColor && - other.steps == this.steps && other.date == this.date && - other.showDate == this.showDate && - other.theme == this.theme && - other.showSets == this.showSets && + other.images == this.images && + other.lightColor == this.lightColor && other.noSound == this.noSound && - other.backup == this.backup); + other.notify == this.notify && + other.showDate == this.showDate && + other.showSets == this.showSets && + other.showUnit == this.showUnit && + other.sound == this.sound && + other.steps == this.steps && + other.theme == this.theme && + other.vibrate == this.vibrate); } class SettingsCompanion extends UpdateCompanion { final Value alarm; - final Value vibrate; - final Value sound; - final Value notify; - final Value images; - final Value showUnit; - final Value lightColor; + final Value backup; final Value darkColor; - final Value steps; - final Value date; - final Value showDate; - final Value theme; - final Value showSets; - final Value noSound; - final Value backup; + final Value date; + final Value images; + final Value lightColor; + final Value noSound; + final Value notify; + final Value showDate; + final Value showSets; + final Value showUnit; + final Value sound; + final Value steps; + final Value theme; + final Value vibrate; const SettingsCompanion({ this.alarm = const Value.absent(), - this.vibrate = const Value.absent(), - this.sound = const Value.absent(), - this.notify = const Value.absent(), - this.images = const Value.absent(), - this.showUnit = const Value.absent(), - this.lightColor = const Value.absent(), - this.darkColor = const Value.absent(), - this.steps = const Value.absent(), - this.date = const Value.absent(), - this.showDate = const Value.absent(), - this.theme = const Value.absent(), - this.showSets = const Value.absent(), - this.noSound = const Value.absent(), this.backup = const Value.absent(), + this.darkColor = const Value.absent(), + this.date = const Value.absent(), + this.images = const Value.absent(), + this.lightColor = const Value.absent(), + this.noSound = const Value.absent(), + this.notify = const Value.absent(), + this.showDate = const Value.absent(), + this.showSets = const Value.absent(), + this.showUnit = const Value.absent(), + this.sound = const Value.absent(), + this.steps = const Value.absent(), + this.theme = const Value.absent(), + this.vibrate = const Value.absent(), }); SettingsCompanion.insert({ required bool alarm, - required bool vibrate, - this.sound = const Value.absent(), - required bool notify, - required bool images, - this.showUnit = const Value.absent(), - this.lightColor = const Value.absent(), + this.backup = const Value.absent(), this.darkColor = const Value.absent(), - required bool steps, - required String date, - required bool showDate, - required String theme, - required bool showSets, - required bool noSound, - required bool backup, + this.date = const Value.absent(), + this.images = const Value.absent(), + this.lightColor = const Value.absent(), + this.noSound = const Value.absent(), + this.notify = const Value.absent(), + this.showDate = const Value.absent(), + this.showSets = const Value.absent(), + this.showUnit = const Value.absent(), + this.sound = const Value.absent(), + this.steps = const Value.absent(), + this.theme = const Value.absent(), + required bool vibrate, }) : alarm = Value(alarm), - vibrate = Value(vibrate), - notify = Value(notify), - images = Value(images), - steps = Value(steps), - date = Value(date), - showDate = Value(showDate), - theme = Value(theme), - showSets = Value(showSets), - noSound = Value(noSound), - backup = Value(backup); + vibrate = Value(vibrate); static Insertable custom({ Expression? alarm, - Expression? vibrate, - Expression? sound, - Expression? notify, - Expression? images, - Expression? showUnit, - Expression? lightColor, + Expression? backup, Expression? darkColor, - Expression? steps, - Expression? date, - Expression? showDate, - Expression? theme, - Expression? showSets, - Expression? noSound, - Expression? backup, + Expression? date, + Expression? images, + Expression? lightColor, + Expression? noSound, + Expression? notify, + Expression? showDate, + Expression? showSets, + Expression? showUnit, + Expression? sound, + Expression? steps, + Expression? theme, + Expression? vibrate, }) { return RawValuesInsertable({ if (alarm != null) 'alarm': alarm, - if (vibrate != null) 'vibrate': vibrate, - if (sound != null) 'sound': sound, - if (notify != null) 'notify': notify, - if (images != null) 'images': images, - if (showUnit != null) 'show_unit': showUnit, - if (lightColor != null) 'light_color': lightColor, - if (darkColor != null) 'dark_color': darkColor, - if (steps != null) 'steps': steps, - if (date != null) 'date': date, - if (showDate != null) 'show_date': showDate, - if (theme != null) 'theme': theme, - if (showSets != null) 'show_sets': showSets, - if (noSound != null) 'no_sound': noSound, if (backup != null) 'backup': backup, + if (darkColor != null) 'dark_color': darkColor, + if (date != null) 'date': date, + if (images != null) 'images': images, + if (lightColor != null) 'light_color': lightColor, + if (noSound != null) 'no_sound': noSound, + if (notify != null) 'notify': notify, + if (showDate != null) 'show_date': showDate, + if (showSets != null) 'show_sets': showSets, + if (showUnit != null) 'show_unit': showUnit, + if (sound != null) 'sound': sound, + if (steps != null) 'steps': steps, + if (theme != null) 'theme': theme, + if (vibrate != null) 'vibrate': vibrate, }); } SettingsCompanion copyWith( {Value? alarm, - Value? vibrate, - Value? sound, - Value? notify, - Value? images, - Value? showUnit, - Value? lightColor, + Value? backup, Value? darkColor, - Value? steps, - Value? date, - Value? showDate, - Value? theme, - Value? showSets, - Value? noSound, - Value? backup}) { + Value? date, + Value? images, + Value? lightColor, + Value? noSound, + Value? notify, + Value? showDate, + Value? showSets, + Value? showUnit, + Value? sound, + Value? steps, + Value? theme, + Value? vibrate}) { return SettingsCompanion( alarm: alarm ?? this.alarm, - vibrate: vibrate ?? this.vibrate, - sound: sound ?? this.sound, - notify: notify ?? this.notify, - images: images ?? this.images, - showUnit: showUnit ?? this.showUnit, - lightColor: lightColor ?? this.lightColor, - darkColor: darkColor ?? this.darkColor, - steps: steps ?? this.steps, - date: date ?? this.date, - showDate: showDate ?? this.showDate, - theme: theme ?? this.theme, - showSets: showSets ?? this.showSets, - noSound: noSound ?? this.noSound, backup: backup ?? this.backup, + darkColor: darkColor ?? this.darkColor, + date: date ?? this.date, + images: images ?? this.images, + lightColor: lightColor ?? this.lightColor, + noSound: noSound ?? this.noSound, + notify: notify ?? this.notify, + showDate: showDate ?? this.showDate, + showSets: showSets ?? this.showSets, + showUnit: showUnit ?? this.showUnit, + sound: sound ?? this.sound, + steps: steps ?? this.steps, + theme: theme ?? this.theme, + vibrate: vibrate ?? this.vibrate, ); } @@ -404,47 +424,47 @@ class SettingsCompanion extends UpdateCompanion { if (alarm.present) { map['alarm'] = Variable(alarm.value); } - if (vibrate.present) { - map['vibrate'] = Variable(vibrate.value); - } - if (sound.present) { - map['sound'] = Variable(sound.value); - } - if (notify.present) { - map['notify'] = Variable(notify.value); - } - if (images.present) { - map['images'] = Variable(images.value); - } - if (showUnit.present) { - map['show_unit'] = Variable(showUnit.value); - } - if (lightColor.present) { - map['light_color'] = Variable(lightColor.value); + if (backup.present) { + map['backup'] = Variable(backup.value); } if (darkColor.present) { map['dark_color'] = Variable(darkColor.value); } - if (steps.present) { - map['steps'] = Variable(steps.value); - } if (date.present) { - map['date'] = Variable(date.value); + map['date'] = Variable(date.value); } - if (showDate.present) { - map['show_date'] = Variable(showDate.value); + if (images.present) { + map['images'] = Variable(images.value); } - if (theme.present) { - map['theme'] = Variable(theme.value); - } - if (showSets.present) { - map['show_sets'] = Variable(showSets.value); + if (lightColor.present) { + map['light_color'] = Variable(lightColor.value); } if (noSound.present) { - map['no_sound'] = Variable(noSound.value); + map['no_sound'] = Variable(noSound.value); } - if (backup.present) { - map['backup'] = Variable(backup.value); + if (notify.present) { + map['notify'] = Variable(notify.value); + } + if (showDate.present) { + map['show_date'] = Variable(showDate.value); + } + if (showSets.present) { + map['show_sets'] = Variable(showSets.value); + } + if (showUnit.present) { + map['show_unit'] = Variable(showUnit.value); + } + if (sound.present) { + map['sound'] = Variable(sound.value); + } + if (steps.present) { + map['steps'] = Variable(steps.value); + } + if (theme.present) { + map['theme'] = Variable(theme.value); + } + if (vibrate.present) { + map['vibrate'] = Variable(vibrate.value); } return map; } @@ -453,20 +473,20 @@ class SettingsCompanion extends UpdateCompanion { String toString() { return (StringBuffer('SettingsCompanion(') ..write('alarm: $alarm, ') - ..write('vibrate: $vibrate, ') - ..write('sound: $sound, ') - ..write('notify: $notify, ') - ..write('images: $images, ') - ..write('showUnit: $showUnit, ') - ..write('lightColor: $lightColor, ') + ..write('backup: $backup, ') ..write('darkColor: $darkColor, ') - ..write('steps: $steps, ') ..write('date: $date, ') - ..write('showDate: $showDate, ') - ..write('theme: $theme, ') - ..write('showSets: $showSets, ') + ..write('images: $images, ') + ..write('lightColor: $lightColor, ') ..write('noSound: $noSound, ') - ..write('backup: $backup') + ..write('notify: $notify, ') + ..write('showDate: $showDate, ') + ..write('showSets: $showSets, ') + ..write('showUnit: $showUnit, ') + ..write('sound: $sound, ') + ..write('steps: $steps, ') + ..write('theme: $theme, ') + ..write('vibrate: $vibrate') ..write(')')) .toString(); } @@ -484,32 +504,63 @@ class $SettingsTable extends Settings with TableInfo<$SettingsTable, Setting> { type: const BoolType(), requiredDuringInsert: true, defaultConstraints: 'CHECK (alarm IN (0, 1))'); - final VerificationMeta _vibrateMeta = const VerificationMeta('vibrate'); + final VerificationMeta _backupMeta = const VerificationMeta('backup'); @override - late final GeneratedColumn vibrate = GeneratedColumn( - 'vibrate', aliasedName, false, + late final GeneratedColumn backup = GeneratedColumn( + 'backup', aliasedName, true, type: const BoolType(), - requiredDuringInsert: true, - defaultConstraints: 'CHECK (vibrate IN (0, 1))'); - final VerificationMeta _soundMeta = const VerificationMeta('sound'); + requiredDuringInsert: false, + defaultConstraints: 'CHECK (backup IN (0, 1))'); + final VerificationMeta _darkColorMeta = const VerificationMeta('darkColor'); @override - late final GeneratedColumn sound = GeneratedColumn( - 'sound', aliasedName, true, + late final GeneratedColumn darkColor = GeneratedColumn( + 'dark_color', aliasedName, true, type: const StringType(), requiredDuringInsert: false); - final VerificationMeta _notifyMeta = const VerificationMeta('notify'); + final VerificationMeta _dateMeta = const VerificationMeta('date'); @override - late final GeneratedColumn notify = GeneratedColumn( - 'notify', aliasedName, false, - type: const BoolType(), - requiredDuringInsert: true, - defaultConstraints: 'CHECK (notify IN (0, 1))'); + late final GeneratedColumn date = GeneratedColumn( + 'date', aliasedName, true, + type: const StringType(), requiredDuringInsert: false); final VerificationMeta _imagesMeta = const VerificationMeta('images'); @override late final GeneratedColumn images = GeneratedColumn( - 'images', aliasedName, false, + 'images', aliasedName, true, type: const BoolType(), - requiredDuringInsert: true, + requiredDuringInsert: false, defaultConstraints: 'CHECK (images IN (0, 1))'); + final VerificationMeta _lightColorMeta = const VerificationMeta('lightColor'); + @override + late final GeneratedColumn lightColor = GeneratedColumn( + 'light_color', aliasedName, true, + type: const StringType(), requiredDuringInsert: false); + final VerificationMeta _noSoundMeta = const VerificationMeta('noSound'); + @override + late final GeneratedColumn noSound = GeneratedColumn( + 'no_sound', aliasedName, true, + type: const BoolType(), + requiredDuringInsert: false, + defaultConstraints: 'CHECK (no_sound IN (0, 1))'); + final VerificationMeta _notifyMeta = const VerificationMeta('notify'); + @override + late final GeneratedColumn notify = GeneratedColumn( + 'notify', aliasedName, true, + type: const BoolType(), + requiredDuringInsert: false, + defaultConstraints: 'CHECK (notify IN (0, 1))'); + final VerificationMeta _showDateMeta = const VerificationMeta('showDate'); + @override + late final GeneratedColumn showDate = GeneratedColumn( + 'show_date', aliasedName, true, + type: const BoolType(), + requiredDuringInsert: false, + defaultConstraints: 'CHECK (show_date IN (0, 1))'); + final VerificationMeta _showSetsMeta = const VerificationMeta('showSets'); + @override + late final GeneratedColumn showSets = GeneratedColumn( + 'show_sets', aliasedName, true, + type: const BoolType(), + requiredDuringInsert: false, + defaultConstraints: 'CHECK (show_sets IN (0, 1))'); final VerificationMeta _showUnitMeta = const VerificationMeta('showUnit'); @override late final GeneratedColumn showUnit = GeneratedColumn( @@ -517,78 +568,47 @@ class $SettingsTable extends Settings with TableInfo<$SettingsTable, Setting> { type: const BoolType(), requiredDuringInsert: false, defaultConstraints: 'CHECK (show_unit IN (0, 1))'); - final VerificationMeta _lightColorMeta = const VerificationMeta('lightColor'); + final VerificationMeta _soundMeta = const VerificationMeta('sound'); @override - late final GeneratedColumn lightColor = GeneratedColumn( - 'light_color', aliasedName, true, - type: const StringType(), requiredDuringInsert: false); - final VerificationMeta _darkColorMeta = const VerificationMeta('darkColor'); - @override - late final GeneratedColumn darkColor = GeneratedColumn( - 'dark_color', aliasedName, true, + late final GeneratedColumn sound = GeneratedColumn( + 'sound', aliasedName, true, type: const StringType(), requiredDuringInsert: false); final VerificationMeta _stepsMeta = const VerificationMeta('steps'); @override late final GeneratedColumn steps = GeneratedColumn( - 'steps', aliasedName, false, + 'steps', aliasedName, true, type: const BoolType(), - requiredDuringInsert: true, + requiredDuringInsert: false, defaultConstraints: 'CHECK (steps IN (0, 1))'); - final VerificationMeta _dateMeta = const VerificationMeta('date'); - @override - late final GeneratedColumn date = GeneratedColumn( - 'date', aliasedName, false, - type: const StringType(), requiredDuringInsert: true); - final VerificationMeta _showDateMeta = const VerificationMeta('showDate'); - @override - late final GeneratedColumn showDate = GeneratedColumn( - 'show_date', aliasedName, false, - type: const BoolType(), - requiredDuringInsert: true, - defaultConstraints: 'CHECK (show_date IN (0, 1))'); final VerificationMeta _themeMeta = const VerificationMeta('theme'); @override late final GeneratedColumn theme = GeneratedColumn( - 'theme', aliasedName, false, - type: const StringType(), requiredDuringInsert: true); - final VerificationMeta _showSetsMeta = const VerificationMeta('showSets'); + 'theme', aliasedName, true, + type: const StringType(), requiredDuringInsert: false); + final VerificationMeta _vibrateMeta = const VerificationMeta('vibrate'); @override - late final GeneratedColumn showSets = GeneratedColumn( - 'show_sets', aliasedName, false, + late final GeneratedColumn vibrate = GeneratedColumn( + 'vibrate', aliasedName, false, type: const BoolType(), requiredDuringInsert: true, - defaultConstraints: 'CHECK (show_sets IN (0, 1))'); - final VerificationMeta _noSoundMeta = const VerificationMeta('noSound'); - @override - late final GeneratedColumn noSound = GeneratedColumn( - 'no_sound', aliasedName, false, - type: const BoolType(), - requiredDuringInsert: true, - defaultConstraints: 'CHECK (no_sound IN (0, 1))'); - final VerificationMeta _backupMeta = const VerificationMeta('backup'); - @override - late final GeneratedColumn backup = GeneratedColumn( - 'backup', aliasedName, false, - type: const BoolType(), - requiredDuringInsert: true, - defaultConstraints: 'CHECK (backup IN (0, 1))'); + defaultConstraints: 'CHECK (vibrate IN (0, 1))'); @override List get $columns => [ alarm, - vibrate, - sound, - notify, - images, - showUnit, - lightColor, + backup, darkColor, - steps, date, - showDate, - theme, - showSets, + images, + lightColor, noSound, - backup + notify, + showDate, + showSets, + showUnit, + sound, + steps, + theme, + vibrate ]; @override String get aliasedName => _alias ?? 'settings'; @@ -605,31 +625,21 @@ class $SettingsTable extends Settings with TableInfo<$SettingsTable, Setting> { } else if (isInserting) { context.missing(_alarmMeta); } - if (data.containsKey('vibrate')) { - context.handle(_vibrateMeta, - vibrate.isAcceptableOrUnknown(data['vibrate']!, _vibrateMeta)); - } else if (isInserting) { - context.missing(_vibrateMeta); + if (data.containsKey('backup')) { + context.handle(_backupMeta, + backup.isAcceptableOrUnknown(data['backup']!, _backupMeta)); } - if (data.containsKey('sound')) { + if (data.containsKey('dark_color')) { + context.handle(_darkColorMeta, + darkColor.isAcceptableOrUnknown(data['dark_color']!, _darkColorMeta)); + } + if (data.containsKey('date')) { context.handle( - _soundMeta, sound.isAcceptableOrUnknown(data['sound']!, _soundMeta)); - } - if (data.containsKey('notify')) { - context.handle(_notifyMeta, - notify.isAcceptableOrUnknown(data['notify']!, _notifyMeta)); - } else if (isInserting) { - context.missing(_notifyMeta); + _dateMeta, date.isAcceptableOrUnknown(data['date']!, _dateMeta)); } if (data.containsKey('images')) { context.handle(_imagesMeta, images.isAcceptableOrUnknown(data['images']!, _imagesMeta)); - } else if (isInserting) { - context.missing(_imagesMeta); - } - if (data.containsKey('show_unit')) { - context.handle(_showUnitMeta, - showUnit.isAcceptableOrUnknown(data['show_unit']!, _showUnitMeta)); } if (data.containsKey('light_color')) { context.handle( @@ -637,51 +647,43 @@ class $SettingsTable extends Settings with TableInfo<$SettingsTable, Setting> { lightColor.isAcceptableOrUnknown( data['light_color']!, _lightColorMeta)); } - if (data.containsKey('dark_color')) { - context.handle(_darkColorMeta, - darkColor.isAcceptableOrUnknown(data['dark_color']!, _darkColorMeta)); + if (data.containsKey('no_sound')) { + context.handle(_noSoundMeta, + noSound.isAcceptableOrUnknown(data['no_sound']!, _noSoundMeta)); } - if (data.containsKey('steps')) { - context.handle( - _stepsMeta, steps.isAcceptableOrUnknown(data['steps']!, _stepsMeta)); - } else if (isInserting) { - context.missing(_stepsMeta); - } - if (data.containsKey('date')) { - context.handle( - _dateMeta, date.isAcceptableOrUnknown(data['date']!, _dateMeta)); - } else if (isInserting) { - context.missing(_dateMeta); + if (data.containsKey('notify')) { + context.handle(_notifyMeta, + notify.isAcceptableOrUnknown(data['notify']!, _notifyMeta)); } if (data.containsKey('show_date')) { context.handle(_showDateMeta, showDate.isAcceptableOrUnknown(data['show_date']!, _showDateMeta)); - } else if (isInserting) { - context.missing(_showDateMeta); - } - if (data.containsKey('theme')) { - context.handle( - _themeMeta, theme.isAcceptableOrUnknown(data['theme']!, _themeMeta)); - } else if (isInserting) { - context.missing(_themeMeta); } if (data.containsKey('show_sets')) { context.handle(_showSetsMeta, showSets.isAcceptableOrUnknown(data['show_sets']!, _showSetsMeta)); - } else if (isInserting) { - context.missing(_showSetsMeta); } - if (data.containsKey('no_sound')) { - context.handle(_noSoundMeta, - noSound.isAcceptableOrUnknown(data['no_sound']!, _noSoundMeta)); - } else if (isInserting) { - context.missing(_noSoundMeta); + if (data.containsKey('show_unit')) { + context.handle(_showUnitMeta, + showUnit.isAcceptableOrUnknown(data['show_unit']!, _showUnitMeta)); } - if (data.containsKey('backup')) { - context.handle(_backupMeta, - backup.isAcceptableOrUnknown(data['backup']!, _backupMeta)); + if (data.containsKey('sound')) { + context.handle( + _soundMeta, sound.isAcceptableOrUnknown(data['sound']!, _soundMeta)); + } + if (data.containsKey('steps')) { + context.handle( + _stepsMeta, steps.isAcceptableOrUnknown(data['steps']!, _stepsMeta)); + } + if (data.containsKey('theme')) { + context.handle( + _themeMeta, theme.isAcceptableOrUnknown(data['theme']!, _themeMeta)); + } + if (data.containsKey('vibrate')) { + context.handle(_vibrateMeta, + vibrate.isAcceptableOrUnknown(data['vibrate']!, _vibrateMeta)); } else if (isInserting) { - context.missing(_backupMeta); + context.missing(_vibrateMeta); } return context; } @@ -704,14 +706,14 @@ class GymSet extends DataClass implements Insertable { final int id; final String name; final int reps; - final int weight; + final double weight; final int sets; final int minutes; final int seconds; - final bool hidden; + final bool? hidden; final String created; final String unit; - final String image; + final String? image; final String? steps; GymSet( {required this.id, @@ -721,10 +723,10 @@ class GymSet extends DataClass implements Insertable { required this.sets, required this.minutes, required this.seconds, - required this.hidden, + this.hidden, required this.created, required this.unit, - required this.image, + this.image, this.steps}); factory GymSet.fromData(Map data, GeneratedDatabase db, {String? prefix}) { @@ -736,7 +738,7 @@ class GymSet extends DataClass implements Insertable { .mapFromDatabaseResponse(data['${effectivePrefix}name'])!, reps: const IntType() .mapFromDatabaseResponse(data['${effectivePrefix}reps'])!, - weight: const IntType() + weight: const RealType() .mapFromDatabaseResponse(data['${effectivePrefix}weight'])!, sets: const IntType() .mapFromDatabaseResponse(data['${effectivePrefix}sets'])!, @@ -745,13 +747,13 @@ class GymSet extends DataClass implements Insertable { seconds: const IntType() .mapFromDatabaseResponse(data['${effectivePrefix}seconds'])!, hidden: const BoolType() - .mapFromDatabaseResponse(data['${effectivePrefix}hidden'])!, + .mapFromDatabaseResponse(data['${effectivePrefix}hidden']), created: const StringType() .mapFromDatabaseResponse(data['${effectivePrefix}created'])!, unit: const StringType() .mapFromDatabaseResponse(data['${effectivePrefix}unit'])!, image: const StringType() - .mapFromDatabaseResponse(data['${effectivePrefix}image'])!, + .mapFromDatabaseResponse(data['${effectivePrefix}image']), steps: const StringType() .mapFromDatabaseResponse(data['${effectivePrefix}steps']), ); @@ -762,14 +764,18 @@ class GymSet extends DataClass implements Insertable { map['id'] = Variable(id); map['name'] = Variable(name); map['reps'] = Variable(reps); - map['weight'] = Variable(weight); + map['weight'] = Variable(weight); map['sets'] = Variable(sets); map['minutes'] = Variable(minutes); map['seconds'] = Variable(seconds); - map['hidden'] = Variable(hidden); + if (!nullToAbsent || hidden != null) { + map['hidden'] = Variable(hidden); + } map['created'] = Variable(created); map['unit'] = Variable(unit); - map['image'] = Variable(image); + if (!nullToAbsent || image != null) { + map['image'] = Variable(image); + } if (!nullToAbsent || steps != null) { map['steps'] = Variable(steps); } @@ -785,10 +791,12 @@ class GymSet extends DataClass implements Insertable { sets: Value(sets), minutes: Value(minutes), seconds: Value(seconds), - hidden: Value(hidden), + hidden: + hidden == null && nullToAbsent ? const Value.absent() : Value(hidden), created: Value(created), unit: Value(unit), - image: Value(image), + image: + image == null && nullToAbsent ? const Value.absent() : Value(image), steps: steps == null && nullToAbsent ? const Value.absent() : Value(steps), ); @@ -801,14 +809,14 @@ class GymSet extends DataClass implements Insertable { id: serializer.fromJson(json['id']), name: serializer.fromJson(json['name']), reps: serializer.fromJson(json['reps']), - weight: serializer.fromJson(json['weight']), + weight: serializer.fromJson(json['weight']), sets: serializer.fromJson(json['sets']), minutes: serializer.fromJson(json['minutes']), seconds: serializer.fromJson(json['seconds']), - hidden: serializer.fromJson(json['hidden']), + hidden: serializer.fromJson(json['hidden']), created: serializer.fromJson(json['created']), unit: serializer.fromJson(json['unit']), - image: serializer.fromJson(json['image']), + image: serializer.fromJson(json['image']), steps: serializer.fromJson(json['steps']), ); } @@ -819,14 +827,14 @@ class GymSet extends DataClass implements Insertable { 'id': serializer.toJson(id), 'name': serializer.toJson(name), 'reps': serializer.toJson(reps), - 'weight': serializer.toJson(weight), + 'weight': serializer.toJson(weight), 'sets': serializer.toJson(sets), 'minutes': serializer.toJson(minutes), 'seconds': serializer.toJson(seconds), - 'hidden': serializer.toJson(hidden), + 'hidden': serializer.toJson(hidden), 'created': serializer.toJson(created), 'unit': serializer.toJson(unit), - 'image': serializer.toJson(image), + 'image': serializer.toJson(image), 'steps': serializer.toJson(steps), }; } @@ -835,7 +843,7 @@ class GymSet extends DataClass implements Insertable { {int? id, String? name, int? reps, - int? weight, + double? weight, int? sets, int? minutes, int? seconds, @@ -902,14 +910,14 @@ class GymSetsCompanion extends UpdateCompanion { final Value id; final Value name; final Value reps; - final Value weight; + final Value weight; final Value sets; final Value minutes; final Value seconds; - final Value hidden; + final Value hidden; final Value created; final Value unit; - final Value image; + final Value image; final Value steps; const GymSetsCompanion({ this.id = const Value.absent(), @@ -929,32 +937,31 @@ class GymSetsCompanion extends UpdateCompanion { this.id = const Value.absent(), required String name, required int reps, - required int weight, + required double weight, this.sets = const Value.absent(), this.minutes = const Value.absent(), this.seconds = const Value.absent(), this.hidden = const Value.absent(), required String created, this.unit = const Value.absent(), - required String image, + this.image = const Value.absent(), this.steps = const Value.absent(), }) : name = Value(name), reps = Value(reps), weight = Value(weight), - created = Value(created), - image = Value(image); + created = Value(created); static Insertable custom({ Expression? id, Expression? name, Expression? reps, - Expression? weight, + Expression? weight, Expression? sets, Expression? minutes, Expression? seconds, - Expression? hidden, + Expression? hidden, Expression? created, Expression? unit, - Expression? image, + Expression? image, Expression? steps, }) { return RawValuesInsertable({ @@ -977,14 +984,14 @@ class GymSetsCompanion extends UpdateCompanion { {Value? id, Value? name, Value? reps, - Value? weight, + Value? weight, Value? sets, Value? minutes, Value? seconds, - Value? hidden, + Value? hidden, Value? created, Value? unit, - Value? image, + Value? image, Value? steps}) { return GymSetsCompanion( id: id ?? this.id, @@ -1015,7 +1022,7 @@ class GymSetsCompanion extends UpdateCompanion { map['reps'] = Variable(reps.value); } if (weight.present) { - map['weight'] = Variable(weight.value); + map['weight'] = Variable(weight.value); } if (sets.present) { map['sets'] = Variable(sets.value); @@ -1027,7 +1034,7 @@ class GymSetsCompanion extends UpdateCompanion { map['seconds'] = Variable(seconds.value); } if (hidden.present) { - map['hidden'] = Variable(hidden.value); + map['hidden'] = Variable(hidden.value); } if (created.present) { map['created'] = Variable(created.value); @@ -1036,7 +1043,7 @@ class GymSetsCompanion extends UpdateCompanion { map['unit'] = Variable(unit.value); } if (image.present) { - map['image'] = Variable(image.value); + map['image'] = Variable(image.value); } if (steps.present) { map['steps'] = Variable(steps.value); @@ -1088,9 +1095,9 @@ class $GymSetsTable extends GymSets with TableInfo<$GymSetsTable, GymSet> { type: const IntType(), requiredDuringInsert: true); final VerificationMeta _weightMeta = const VerificationMeta('weight'); @override - late final GeneratedColumn weight = GeneratedColumn( + late final GeneratedColumn weight = GeneratedColumn( 'weight', aliasedName, false, - type: const IntType(), requiredDuringInsert: true); + type: const RealType(), requiredDuringInsert: true); final VerificationMeta _setsMeta = const VerificationMeta('sets'); @override late final GeneratedColumn sets = GeneratedColumn( @@ -1115,7 +1122,7 @@ class $GymSetsTable extends GymSets with TableInfo<$GymSetsTable, GymSet> { final VerificationMeta _hiddenMeta = const VerificationMeta('hidden'); @override late final GeneratedColumn hidden = GeneratedColumn( - 'hidden', aliasedName, false, + 'hidden', aliasedName, true, type: const BoolType(), requiredDuringInsert: false, defaultConstraints: 'CHECK (hidden IN (0, 1))', @@ -1135,8 +1142,8 @@ class $GymSetsTable extends GymSets with TableInfo<$GymSetsTable, GymSet> { final VerificationMeta _imageMeta = const VerificationMeta('image'); @override late final GeneratedColumn image = GeneratedColumn( - 'image', aliasedName, false, - type: const StringType(), requiredDuringInsert: true); + 'image', aliasedName, true, + type: const StringType(), requiredDuringInsert: false); final VerificationMeta _stepsMeta = const VerificationMeta('steps'); @override late final GeneratedColumn steps = GeneratedColumn( @@ -1216,8 +1223,6 @@ class $GymSetsTable extends GymSets with TableInfo<$GymSetsTable, GymSet> { if (data.containsKey('image')) { context.handle( _imageMeta, image.isAcceptableOrUnknown(data['image']!, _imageMeta)); - } else if (isInserting) { - context.missing(_imageMeta); } if (data.containsKey('steps')) { context.handle( diff --git a/lib/edit_set.dart b/lib/edit_set.dart index 97a7c81..af46271 100644 --- a/lib/edit_set.dart +++ b/lib/edit_set.dart @@ -103,8 +103,8 @@ class _EditGymSetPageState extends State { }, onChanged: (value) { setState(() { - gymSet = - gymSet.copyWith(weight: Value(int.tryParse(value) ?? 0)); + gymSet = gymSet.copyWith( + weight: Value(double.tryParse(value) ?? 0)); }); }, ), diff --git a/lib/gym_set.dart b/lib/gym_set.dart index d77dadc..663b2a5 100644 --- a/lib/gym_set.dart +++ b/lib/gym_set.dart @@ -4,13 +4,14 @@ class GymSets extends Table { IntColumn get id => integer().autoIncrement()(); TextColumn get name => text()(); IntColumn get reps => integer()(); - IntColumn get weight => integer()(); + RealColumn get weight => real()(); IntColumn get sets => integer().withDefault(const Constant(3))(); IntColumn get minutes => integer().withDefault(const Constant(3))(); IntColumn get seconds => integer().withDefault(const Constant(30))(); - BoolColumn get hidden => boolean().withDefault(const Constant(false))(); + BoolColumn get hidden => + boolean().nullable().withDefault(const Constant(false))(); TextColumn get created => text()(); TextColumn get unit => text().withDefault(const Constant('kg'))(); - TextColumn get image => text()(); + TextColumn get image => text().nullable()(); TextColumn get steps => text().nullable()(); } diff --git a/lib/settings_page.dart b/lib/settings_page.dart index f3a6f98..8d5eabc 100644 --- a/lib/settings_page.dart +++ b/lib/settings_page.dart @@ -40,7 +40,7 @@ class _SettingsPageState extends State<_SettingsPage> { @override void initState() { super.initState(); - stream = db.select(db.settings).watchSingle(); + stream = (db.select(db.settings)..limit(1)).watchSingle(); } @override @@ -50,6 +50,7 @@ class _SettingsPageState extends State<_SettingsPage> { stream: stream, builder: (context, snapshot) { final settings = snapshot.data; + print('build: $settings'); if (settings == null) return const Center(child: CircularProgressIndicator()); @@ -96,6 +97,9 @@ class _SettingsPageState extends State<_SettingsPage> { db = MyDatabase(); final migrator = db.createMigrator(); await migrator.createAll(); + await db.customInsert(''' + INSERT INTO gym_sets(id, name, reps, weight, created, unit, hidden, image, sets, minutes, seconds, steps) + SELECT id, name, reps, weight, created, unit, hidden, image, sets, minutes, seconds, steps FROM sets'''); print('Migrated.'); }, child: const Text("Import"))); @@ -115,7 +119,7 @@ class _SettingsPageState extends State<_SettingsPage> { return SwitchListTile( title: Text(item['title'].toString()), - value: item['value'] as bool, + value: (item['value'] ?? false) as bool, onChanged: (value) { switch (item['title']) { case 'Alarm':