Expect exercises on plans to be non nullable

This commit is contained in:
Brandon Presley 2023-11-11 14:53:38 +13:00
parent ea745c1cec
commit 0eaac20e7e
3 changed files with 30 additions and 22 deletions

View File

@ -1248,8 +1248,8 @@ class $GymSetsTable extends GymSets with TableInfo<$GymSetsTable, GymSet> {
class Plan extends DataClass implements Insertable<Plan> { class Plan extends DataClass implements Insertable<Plan> {
final int id; final int id;
final String days; final String days;
final String? exercises; final String exercises;
Plan({required this.id, required this.days, this.exercises}); Plan({required this.id, required this.days, required this.exercises});
factory Plan.fromData(Map<String, dynamic> data, GeneratedDatabase db, factory Plan.fromData(Map<String, dynamic> data, GeneratedDatabase db,
{String? prefix}) { {String? prefix}) {
final effectivePrefix = prefix ?? ''; final effectivePrefix = prefix ?? '';
@ -1259,7 +1259,7 @@ class Plan extends DataClass implements Insertable<Plan> {
days: const StringType() days: const StringType()
.mapFromDatabaseResponse(data['${effectivePrefix}days'])!, .mapFromDatabaseResponse(data['${effectivePrefix}days'])!,
exercises: const StringType() exercises: const StringType()
.mapFromDatabaseResponse(data['${effectivePrefix}exercises']), .mapFromDatabaseResponse(data['${effectivePrefix}exercises'])!,
); );
} }
@override @override
@ -1267,9 +1267,7 @@ class Plan extends DataClass implements Insertable<Plan> {
final map = <String, Expression>{}; final map = <String, Expression>{};
map['id'] = Variable<int>(id); map['id'] = Variable<int>(id);
map['days'] = Variable<String>(days); map['days'] = Variable<String>(days);
if (!nullToAbsent || exercises != null) { map['exercises'] = Variable<String>(exercises);
map['exercises'] = Variable<String?>(exercises);
}
return map; return map;
} }
@ -1277,9 +1275,7 @@ class Plan extends DataClass implements Insertable<Plan> {
return PlansCompanion( return PlansCompanion(
id: Value(id), id: Value(id),
days: Value(days), days: Value(days),
exercises: exercises == null && nullToAbsent exercises: Value(exercises),
? const Value.absent()
: Value(exercises),
); );
} }
@ -1289,7 +1285,7 @@ class Plan extends DataClass implements Insertable<Plan> {
return Plan( return Plan(
id: serializer.fromJson<int>(json['id']), id: serializer.fromJson<int>(json['id']),
days: serializer.fromJson<String>(json['days']), days: serializer.fromJson<String>(json['days']),
exercises: serializer.fromJson<String?>(json['exercises']), exercises: serializer.fromJson<String>(json['exercises']),
); );
} }
@override @override
@ -1298,7 +1294,7 @@ class Plan extends DataClass implements Insertable<Plan> {
return <String, dynamic>{ return <String, dynamic>{
'id': serializer.toJson<int>(id), 'id': serializer.toJson<int>(id),
'days': serializer.toJson<String>(days), 'days': serializer.toJson<String>(days),
'exercises': serializer.toJson<String?>(exercises), 'exercises': serializer.toJson<String>(exercises),
}; };
} }
@ -1331,7 +1327,7 @@ class Plan extends DataClass implements Insertable<Plan> {
class PlansCompanion extends UpdateCompanion<Plan> { class PlansCompanion extends UpdateCompanion<Plan> {
final Value<int> id; final Value<int> id;
final Value<String> days; final Value<String> days;
final Value<String?> exercises; final Value<String> exercises;
const PlansCompanion({ const PlansCompanion({
this.id = const Value.absent(), this.id = const Value.absent(),
this.days = const Value.absent(), this.days = const Value.absent(),
@ -1340,12 +1336,13 @@ class PlansCompanion extends UpdateCompanion<Plan> {
PlansCompanion.insert({ PlansCompanion.insert({
this.id = const Value.absent(), this.id = const Value.absent(),
required String days, required String days,
this.exercises = const Value.absent(), required String exercises,
}) : days = Value(days); }) : days = Value(days),
exercises = Value(exercises);
static Insertable<Plan> custom({ static Insertable<Plan> custom({
Expression<int>? id, Expression<int>? id,
Expression<String>? days, Expression<String>? days,
Expression<String?>? exercises, Expression<String>? exercises,
}) { }) {
return RawValuesInsertable({ return RawValuesInsertable({
if (id != null) 'id': id, if (id != null) 'id': id,
@ -1355,7 +1352,7 @@ class PlansCompanion extends UpdateCompanion<Plan> {
} }
PlansCompanion copyWith( PlansCompanion copyWith(
{Value<int>? id, Value<String>? days, Value<String?>? exercises}) { {Value<int>? id, Value<String>? days, Value<String>? exercises}) {
return PlansCompanion( return PlansCompanion(
id: id ?? this.id, id: id ?? this.id,
days: days ?? this.days, days: days ?? this.days,
@ -1373,7 +1370,7 @@ class PlansCompanion extends UpdateCompanion<Plan> {
map['days'] = Variable<String>(days.value); map['days'] = Variable<String>(days.value);
} }
if (exercises.present) { if (exercises.present) {
map['exercises'] = Variable<String?>(exercises.value); map['exercises'] = Variable<String>(exercises.value);
} }
return map; return map;
} }
@ -1409,8 +1406,8 @@ class $PlansTable extends Plans with TableInfo<$PlansTable, Plan> {
final VerificationMeta _exercisesMeta = const VerificationMeta('exercises'); final VerificationMeta _exercisesMeta = const VerificationMeta('exercises');
@override @override
late final GeneratedColumn<String?> exercises = GeneratedColumn<String?>( late final GeneratedColumn<String?> exercises = GeneratedColumn<String?>(
'exercises', aliasedName, true, 'exercises', aliasedName, false,
type: const StringType(), requiredDuringInsert: false); type: const StringType(), requiredDuringInsert: true);
@override @override
List<GeneratedColumn> get $columns => [id, days, exercises]; List<GeneratedColumn> get $columns => [id, days, exercises];
@override @override
@ -1434,6 +1431,8 @@ class $PlansTable extends Plans with TableInfo<$PlansTable, Plan> {
if (data.containsKey('exercises')) { if (data.containsKey('exercises')) {
context.handle(_exercisesMeta, context.handle(_exercisesMeta,
exercises.isAcceptableOrUnknown(data['exercises']!, _exercisesMeta)); exercises.isAcceptableOrUnknown(data['exercises']!, _exercisesMeta));
} else if (isInserting) {
context.missing(_exercisesMeta);
} }
return context; return context;
} }

View File

@ -3,5 +3,5 @@ import 'package:moor/moor.dart';
class Plans extends Table { class Plans extends Table {
IntColumn get id => integer().autoIncrement()(); IntColumn get id => integer().autoIncrement()();
TextColumn get days => text()(); TextColumn get days => text()();
TextColumn get exercises => text().nullable()(); TextColumn get exercises => text()();
} }

View File

@ -65,6 +65,16 @@ class _PlansPageState extends State<_PlansPage> {
builder: (context, snapshot) { builder: (context, snapshot) {
final plans = snapshot.data; final plans = snapshot.data;
if (snapshot.hasError)
return Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
'Error: ${snapshot.error}',
style: Theme.of(context).textTheme.headlineSmall,
)),
);
if (plans == null) if (plans == null)
return const Center(child: CircularProgressIndicator()); return const Center(child: CircularProgressIndicator());
@ -73,8 +83,7 @@ class _PlansPageState extends State<_PlansPage> {
itemBuilder: (context, index) { itemBuilder: (context, index) {
return ListTile( return ListTile(
title: Text(plans[index].days.replaceAll(',', ', ')), title: Text(plans[index].days.replaceAll(',', ', ')),
subtitle: Text( subtitle: Text(plans[index].exercises),
plans[index].exercises?.replaceAll(',', ', ') ?? ''),
onTap: () async { onTap: () async {
await Navigator.push( await Navigator.push(
context, context,