Skip to content

Commit

Permalink
feat(server): Make WeightClass nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Jan 16, 2024
1 parent 320c34d commit c0f6952
Show file tree
Hide file tree
Showing 32 changed files with 430 additions and 414 deletions.
6 changes: 3 additions & 3 deletions wrestling_scoreboard_client/lib/data/bout_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ MaterialColor getColorFromBoutRole(BoutRole role) {
}

String getBoutTitle(BuildContext context, Bout bout) {
return '${bout.weightClass.name}, ${styleToAbbr(bout.weightClass.style, context)} | '
'${getParticipationStateName(context, bout.r)} vs. '
'${getParticipationStateName(context, bout.b)}';
final weightClass = bout.weightClass;
return '${weightClass == null ? '' : '${weightClass.name}, ${styleToAbbr(weightClass.style, context)} | '}'
'${getParticipationStateName(context, bout.r)} vs. ${getParticipationStateName(context, bout.b)}';
}

String getParticipationStateName(BuildContext context, ParticipantState? participantState) {
Expand Down
25 changes: 14 additions & 11 deletions wrestling_scoreboard_client/lib/ui/display/bout/bout_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class TeamMatchBoutDisplay extends StatelessWidget {
onPressBoutInfo: (BuildContext context) {
context.push('/${TeamMatchBoutOverview.route}/${teamMatchBout.id}');
},
navigateToBoutByIndex: (context, index) => navigateToTeamMatchBoutScreen(context, match, teamMatchBouts[index]),
navigateToBoutByIndex: (context, index) =>
navigateToTeamMatchBoutScreen(context, match, teamMatchBouts[index]),
home: match.home.team,
guest: match.guest.team,
);
Expand Down Expand Up @@ -451,16 +452,18 @@ class BoutState extends ConsumerState<BoutScreen> {
minFontSize: 10,
))),
]),
Center(
child: ScaledText(
'${styleToString(bout.weightClass.style, context)}',
minFontSize: 10,
)),
Center(
child: ScaledText(
bout.weightClass.name,
minFontSize: 10,
)),
if (bout.weightClass != null)
Center(
child: ScaledText(
'${styleToString(bout.weightClass!.style, context)}',
minFontSize: 10,
)),
if (bout.weightClass != null)
Center(
child: ScaledText(
bout.weightClass!.name,
minFontSize: 10,
)),
])),
Expanded(
flex: 50,
Expand Down
29 changes: 18 additions & 11 deletions wrestling_scoreboard_client/lib/ui/display/match/match_display.dart
Original file line number Diff line number Diff line change
Expand Up @@ -204,20 +204,27 @@ class BoutListItem extends StatelessWidget {
flex: 2,
child: Container(
padding: edgeInsets,
child: Center(
child: ScaledText(
'${bout.weightClass.weight} $weightUnit',
softWrap: false,
minFontSize: 10,
)),
child: bout.weightClass == null
? null
: Center(
child: ScaledText(
'${bout.weightClass!.weight} $weightUnit',
softWrap: false,
minFontSize: 10,
),
),
),
),
Expanded(
child: Center(
child: ScaledText(
styleToAbbr(bout.weightClass.style, context),
minFontSize: 12,
))),
child: Center(
child: bout.weightClass == null
? null
: ScaledText(
styleToAbbr(bout.weightClass!.style, context),
minFontSize: 12,
),
),
),
],
),
displayName(pStatus: bout.r, role: BoutRole.red, context: context),
Expand Down
4 changes: 2 additions & 2 deletions wrestling_scoreboard_client/lib/ui/edit/bout_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ abstract class BoutEdit extends StatefulWidget {
abstract class BoutEditState<T extends BoutEdit> extends State<T> implements AbstractEditState<Bout> {
final _formKey = GlobalKey<FormState>();

late WeightClass _weightClass;
WeightClass? _weightClass;
Participation? _redParticipation;
Participation? _blueParticipation;

@override
void initState() {
super.initState();
_weightClass = widget.bout!.weightClass;
_weightClass = widget.bout?.weightClass;
_redParticipation = widget.bout?.r?.participation;
_blueParticipation = widget.bout?.b?.participation;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract class BoutOverview extends StatelessWidget implements AbstractOverview<
icon: Icons.person,
),
ContentItem(
title: data.weightClass.name,
title: data.weightClass?.name ?? '-',
subtitle: localizations.weight,
icon: Icons.fitness_center,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class ScoreSheet {
]);
}

final isFreeStyle = bout.weightClass.style == WrestlingStyle.free;
final isFreeStyle = bout.weightClass?.style == WrestlingStyle.free;

final wrestlingEvent = event;
Person? matChairman;
Expand Down Expand Up @@ -190,8 +190,8 @@ class ScoreSheet {
color: PdfColors.grey300,
pencilColor: _pencilColor),
buildFormCell(
title: '${localizations.weightClass} (${bout.weightClass.unit.toAbbr()})',
content: bout.weightClass.weight.toString(),
title: '${localizations.weightClass} (${bout.weightClass?.unit.toAbbr()})',
content: bout.weightClass?.weight.toString(),
color: PdfColors.grey300,
pencilColor: _pencilColor),
buildFormCell(
Expand Down
8 changes: 4 additions & 4 deletions wrestling_scoreboard_common/lib/src/data/bout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Bout with _$Bout implements DataObject {
int? id,
ParticipantState? r, // red
ParticipantState? b, // blue
required WeightClass weightClass,
WeightClass? weightClass,
int? pool,
BoutRole? winnerRole,
BoutResult? result,
Expand All @@ -34,7 +34,7 @@ class Bout with _$Bout implements DataObject {
if (id != null) 'id': id,
'red_id': r?.id,
'blue_id': b?.id,
'weight_class_id': weightClass.id,
'weight_class_id': weightClass?.id,
'winner_role': winnerRole?.name,
'bout_result': result?.name,
'duration_millis': duration.inMilliseconds,
Expand All @@ -46,13 +46,13 @@ class Bout with _$Bout implements DataObject {
final blueId = e['blue_id'] as int?;
final winner = e['winner_role'] as String?;
final boutResult = e['bout_result'] as String?;
final weightClass = await getSingle<WeightClass>(e['weight_class_id'] as int);
final weightClassId = e['weight_class_id'] as int?;
final durationMillis = e['duration_millis'] as int?;
return Bout(
id: e['id'] as int?,
r: redId == null ? null : await getSingle<ParticipantState>(redId),
b: blueId == null ? null : await getSingle<ParticipantState>(blueId),
weightClass: weightClass!,
weightClass: weightClassId == null ? null : await getSingle<WeightClass>(weightClassId),
winnerRole: winner == null ? null : BoutRoleParser.valueOf(winner),
result: boutResult == null ? null : BoutResultParser.valueOf(boutResult),
duration: durationMillis == null ? Duration() : Duration(milliseconds: durationMillis),
Expand Down
43 changes: 23 additions & 20 deletions wrestling_scoreboard_common/lib/src/data/bout.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mixin _$Bout {
int? get id => throw _privateConstructorUsedError;
ParticipantState? get r => throw _privateConstructorUsedError; // red
ParticipantState? get b => throw _privateConstructorUsedError; // blue
WeightClass get weightClass => throw _privateConstructorUsedError;
WeightClass? get weightClass => throw _privateConstructorUsedError;
int? get pool => throw _privateConstructorUsedError;
BoutRole? get winnerRole => throw _privateConstructorUsedError;
BoutResult? get result => throw _privateConstructorUsedError;
Expand All @@ -43,15 +43,15 @@ abstract class $BoutCopyWith<$Res> {
{int? id,
ParticipantState? r,
ParticipantState? b,
WeightClass weightClass,
WeightClass? weightClass,
int? pool,
BoutRole? winnerRole,
BoutResult? result,
Duration duration});

$ParticipantStateCopyWith<$Res>? get r;
$ParticipantStateCopyWith<$Res>? get b;
$WeightClassCopyWith<$Res> get weightClass;
$WeightClassCopyWith<$Res>? get weightClass;
}

/// @nodoc
Expand All @@ -70,7 +70,7 @@ class _$BoutCopyWithImpl<$Res, $Val extends Bout>
Object? id = freezed,
Object? r = freezed,
Object? b = freezed,
Object? weightClass = null,
Object? weightClass = freezed,
Object? pool = freezed,
Object? winnerRole = freezed,
Object? result = freezed,
Expand All @@ -89,10 +89,10 @@ class _$BoutCopyWithImpl<$Res, $Val extends Bout>
? _value.b
: b // ignore: cast_nullable_to_non_nullable
as ParticipantState?,
weightClass: null == weightClass
weightClass: freezed == weightClass
? _value.weightClass
: weightClass // ignore: cast_nullable_to_non_nullable
as WeightClass,
as WeightClass?,
pool: freezed == pool
? _value.pool
: pool // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -138,8 +138,12 @@ class _$BoutCopyWithImpl<$Res, $Val extends Bout>

@override
@pragma('vm:prefer-inline')
$WeightClassCopyWith<$Res> get weightClass {
return $WeightClassCopyWith<$Res>(_value.weightClass, (value) {
$WeightClassCopyWith<$Res>? get weightClass {
if (_value.weightClass == null) {
return null;
}

return $WeightClassCopyWith<$Res>(_value.weightClass!, (value) {
return _then(_value.copyWith(weightClass: value) as $Val);
});
}
Expand All @@ -156,7 +160,7 @@ abstract class _$$BoutImplCopyWith<$Res> implements $BoutCopyWith<$Res> {
{int? id,
ParticipantState? r,
ParticipantState? b,
WeightClass weightClass,
WeightClass? weightClass,
int? pool,
BoutRole? winnerRole,
BoutResult? result,
Expand All @@ -167,15 +171,14 @@ abstract class _$$BoutImplCopyWith<$Res> implements $BoutCopyWith<$Res> {
@override
$ParticipantStateCopyWith<$Res>? get b;
@override
$WeightClassCopyWith<$Res> get weightClass;
$WeightClassCopyWith<$Res>? get weightClass;
}

/// @nodoc
class __$$BoutImplCopyWithImpl<$Res>
extends _$BoutCopyWithImpl<$Res, _$BoutImpl>
implements _$$BoutImplCopyWith<$Res> {
__$$BoutImplCopyWithImpl(
_$BoutImpl _value, $Res Function(_$BoutImpl) _then)
__$$BoutImplCopyWithImpl(_$BoutImpl _value, $Res Function(_$BoutImpl) _then)
: super(_value, _then);

@pragma('vm:prefer-inline')
Expand All @@ -184,7 +187,7 @@ class __$$BoutImplCopyWithImpl<$Res>
Object? id = freezed,
Object? r = freezed,
Object? b = freezed,
Object? weightClass = null,
Object? weightClass = freezed,
Object? pool = freezed,
Object? winnerRole = freezed,
Object? result = freezed,
Expand All @@ -203,10 +206,10 @@ class __$$BoutImplCopyWithImpl<$Res>
? _value.b
: b // ignore: cast_nullable_to_non_nullable
as ParticipantState?,
weightClass: null == weightClass
weightClass: freezed == weightClass
? _value.weightClass
: weightClass // ignore: cast_nullable_to_non_nullable
as WeightClass,
as WeightClass?,
pool: freezed == pool
? _value.pool
: pool // ignore: cast_nullable_to_non_nullable
Expand Down Expand Up @@ -234,7 +237,7 @@ class _$BoutImpl extends _Bout {
{this.id,
this.r,
this.b,
required this.weightClass,
this.weightClass,
this.pool,
this.winnerRole,
this.result,
Expand All @@ -253,7 +256,7 @@ class _$BoutImpl extends _Bout {
final ParticipantState? b;
// blue
@override
final WeightClass weightClass;
final WeightClass? weightClass;
@override
final int? pool;
@override
Expand All @@ -270,7 +273,7 @@ class _$BoutImpl extends _Bout {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$BoutImpl &&
Expand Down Expand Up @@ -311,7 +314,7 @@ abstract class _Bout extends Bout {
{final int? id,
final ParticipantState? r,
final ParticipantState? b,
required final WeightClass weightClass,
final WeightClass? weightClass,
final int? pool,
final BoutRole? winnerRole,
final BoutResult? result,
Expand All @@ -327,7 +330,7 @@ abstract class _Bout extends Bout {
@override // red
ParticipantState? get b;
@override // blue
WeightClass get weightClass;
WeightClass? get weightClass;
@override
int? get pool;
@override
Expand Down
7 changes: 4 additions & 3 deletions wrestling_scoreboard_common/lib/src/data/bout.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class _$BoutActionImpl extends _BoutAction {
final int? pointCount;

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$BoutActionImpl &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class _$BoutConfigImpl extends _BoutConfig {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$BoutConfigImpl &&
Expand Down
2 changes: 1 addition & 1 deletion wrestling_scoreboard_common/lib/src/data/club.freezed.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class _$ClubImpl extends _Club {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ClubImpl &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class _$CompetitionImpl extends _Competition {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CompetitionImpl &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class _$CompetitionBoutImpl extends _CompetitionBout {
}

@override
bool operator ==(dynamic other) {
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$CompetitionBoutImpl &&
Expand Down
Loading

0 comments on commit c0f6952

Please sign in to comment.