Expect exercises on plans to be non nullable
This commit is contained in:
parent
ea745c1cec
commit
0eaac20e7e
|
@ -1248,8 +1248,8 @@ class $GymSetsTable extends GymSets with TableInfo<$GymSetsTable, GymSet> {
|
|||
class Plan extends DataClass implements Insertable<Plan> {
|
||||
final int id;
|
||||
final String days;
|
||||
final String? exercises;
|
||||
Plan({required this.id, required this.days, this.exercises});
|
||||
final String exercises;
|
||||
Plan({required this.id, required this.days, required this.exercises});
|
||||
factory Plan.fromData(Map<String, dynamic> data, GeneratedDatabase db,
|
||||
{String? prefix}) {
|
||||
final effectivePrefix = prefix ?? '';
|
||||
|
@ -1259,7 +1259,7 @@ class Plan extends DataClass implements Insertable<Plan> {
|
|||
days: const StringType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}days'])!,
|
||||
exercises: const StringType()
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}exercises']),
|
||||
.mapFromDatabaseResponse(data['${effectivePrefix}exercises'])!,
|
||||
);
|
||||
}
|
||||
@override
|
||||
|
@ -1267,9 +1267,7 @@ class Plan extends DataClass implements Insertable<Plan> {
|
|||
final map = <String, Expression>{};
|
||||
map['id'] = Variable<int>(id);
|
||||
map['days'] = Variable<String>(days);
|
||||
if (!nullToAbsent || exercises != null) {
|
||||
map['exercises'] = Variable<String?>(exercises);
|
||||
}
|
||||
map['exercises'] = Variable<String>(exercises);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -1277,9 +1275,7 @@ class Plan extends DataClass implements Insertable<Plan> {
|
|||
return PlansCompanion(
|
||||
id: Value(id),
|
||||
days: Value(days),
|
||||
exercises: exercises == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(exercises),
|
||||
exercises: Value(exercises),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -1289,7 +1285,7 @@ class Plan extends DataClass implements Insertable<Plan> {
|
|||
return Plan(
|
||||
id: serializer.fromJson<int>(json['id']),
|
||||
days: serializer.fromJson<String>(json['days']),
|
||||
exercises: serializer.fromJson<String?>(json['exercises']),
|
||||
exercises: serializer.fromJson<String>(json['exercises']),
|
||||
);
|
||||
}
|
||||
@override
|
||||
|
@ -1298,7 +1294,7 @@ class Plan extends DataClass implements Insertable<Plan> {
|
|||
return <String, dynamic>{
|
||||
'id': serializer.toJson<int>(id),
|
||||
'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> {
|
||||
final Value<int> id;
|
||||
final Value<String> days;
|
||||
final Value<String?> exercises;
|
||||
final Value<String> exercises;
|
||||
const PlansCompanion({
|
||||
this.id = const Value.absent(),
|
||||
this.days = const Value.absent(),
|
||||
|
@ -1340,12 +1336,13 @@ class PlansCompanion extends UpdateCompanion<Plan> {
|
|||
PlansCompanion.insert({
|
||||
this.id = const Value.absent(),
|
||||
required String days,
|
||||
this.exercises = const Value.absent(),
|
||||
}) : days = Value(days);
|
||||
required String exercises,
|
||||
}) : days = Value(days),
|
||||
exercises = Value(exercises);
|
||||
static Insertable<Plan> custom({
|
||||
Expression<int>? id,
|
||||
Expression<String>? days,
|
||||
Expression<String?>? exercises,
|
||||
Expression<String>? exercises,
|
||||
}) {
|
||||
return RawValuesInsertable({
|
||||
if (id != null) 'id': id,
|
||||
|
@ -1355,7 +1352,7 @@ class PlansCompanion extends UpdateCompanion<Plan> {
|
|||
}
|
||||
|
||||
PlansCompanion copyWith(
|
||||
{Value<int>? id, Value<String>? days, Value<String?>? exercises}) {
|
||||
{Value<int>? id, Value<String>? days, Value<String>? exercises}) {
|
||||
return PlansCompanion(
|
||||
id: id ?? this.id,
|
||||
days: days ?? this.days,
|
||||
|
@ -1373,7 +1370,7 @@ class PlansCompanion extends UpdateCompanion<Plan> {
|
|||
map['days'] = Variable<String>(days.value);
|
||||
}
|
||||
if (exercises.present) {
|
||||
map['exercises'] = Variable<String?>(exercises.value);
|
||||
map['exercises'] = Variable<String>(exercises.value);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
@ -1409,8 +1406,8 @@ class $PlansTable extends Plans with TableInfo<$PlansTable, Plan> {
|
|||
final VerificationMeta _exercisesMeta = const VerificationMeta('exercises');
|
||||
@override
|
||||
late final GeneratedColumn<String?> exercises = GeneratedColumn<String?>(
|
||||
'exercises', aliasedName, true,
|
||||
type: const StringType(), requiredDuringInsert: false);
|
||||
'exercises', aliasedName, false,
|
||||
type: const StringType(), requiredDuringInsert: true);
|
||||
@override
|
||||
List<GeneratedColumn> get $columns => [id, days, exercises];
|
||||
@override
|
||||
|
@ -1434,6 +1431,8 @@ class $PlansTable extends Plans with TableInfo<$PlansTable, Plan> {
|
|||
if (data.containsKey('exercises')) {
|
||||
context.handle(_exercisesMeta,
|
||||
exercises.isAcceptableOrUnknown(data['exercises']!, _exercisesMeta));
|
||||
} else if (isInserting) {
|
||||
context.missing(_exercisesMeta);
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
|
|
@ -3,5 +3,5 @@ import 'package:moor/moor.dart';
|
|||
class Plans extends Table {
|
||||
IntColumn get id => integer().autoIncrement()();
|
||||
TextColumn get days => text()();
|
||||
TextColumn get exercises => text().nullable()();
|
||||
TextColumn get exercises => text()();
|
||||
}
|
||||
|
|
|
@ -65,6 +65,16 @@ class _PlansPageState extends State<_PlansPage> {
|
|||
builder: (context, snapshot) {
|
||||
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)
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
|
||||
|
@ -73,8 +83,7 @@ class _PlansPageState extends State<_PlansPage> {
|
|||
itemBuilder: (context, index) {
|
||||
return ListTile(
|
||||
title: Text(plans[index].days.replaceAll(',', ', ')),
|
||||
subtitle: Text(
|
||||
plans[index].exercises?.replaceAll(',', ', ') ?? ''),
|
||||
subtitle: Text(plans[index].exercises),
|
||||
onTap: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
|
|
Loading…
Reference in New Issue
Block a user