Skip to content

Commit

Permalink
fix: Classification points and match display improvements (closes #49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustl22 committed Aug 22, 2024
1 parent 3516921 commit 061fdbb
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 75 deletions.
60 changes: 42 additions & 18 deletions wrestling_scoreboard_client/lib/view/screens/display/common.dart
Original file line number Diff line number Diff line change
@@ -1,13 +1,51 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:wrestling_scoreboard_client/provider/data_provider.dart';
import 'package:wrestling_scoreboard_client/view/widgets/loading_builder.dart';
import 'package:wrestling_scoreboard_client/view/widgets/scaled_text.dart';
import 'package:wrestling_scoreboard_client/view/widgets/themed.dart';
import 'package:wrestling_scoreboard_common/common.dart';

class ClassificationPointsDisplay extends ConsumerWidget {
final Iterable<ParticipantState?> participationStates;
final Color color;

const ClassificationPointsDisplay({required this.participationStates, required this.color, super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final participationStatesFuture = Future.wait(participationStates.map((participationState) async {
return participationState == null
? null
: ref.watch(singleDataStreamProvider<ParticipantState>(
SingleProviderData<ParticipantState>(initialData: participationState, id: participationState.id!),
).future);
}));
return ThemedContainer(
color: color,
child: Center(
child: LoadingBuilder<List<ParticipantState?>>(
future: participationStatesFuture,
initialData: null, // Handle initial data via the stream
builder: (context, participationStates) {
return ScaledText(
TeamMatch.getClassificationPoints(participationStates).toString(),
fontSize: 28,
minFontSize: 16,
softWrap: false,
);
}),
),
);
}
}

class CommonElements {
static List<Widget> getTeamHeader(Team home, Team guest, List<Bout> bouts, BuildContext context) {
final width = MediaQuery.of(context).size.width;
final padding = width / 100;
final edgeInsets = EdgeInsets.all(padding);

return [
ThemedContainer(
color: Colors.red.shade800,
Expand All @@ -22,29 +60,15 @@ class CommonElements {
Row(
children: [
Expanded(
child: ThemedContainer(
child: ClassificationPointsDisplay(
participationStates: bouts.map((bout) => bout.r),
color: Colors.red.shade900,
child: Center(
child: ScaledText(
TeamMatch.getHomePoints(bouts).toString(),
fontSize: 28,
minFontSize: 16,
softWrap: false,
),
),
),
),
Expanded(
child: ThemedContainer(
child: ClassificationPointsDisplay(
participationStates: bouts.map((bout) => bout.b),
color: Colors.blue.shade900,
child: Center(
child: ScaledText(
TeamMatch.getGuestPoints(bouts).toString(),
fontSize: 28,
minFontSize: 16,
softWrap: false,
),
),
),
),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,40 +140,48 @@ class BoutListItem extends StatelessWidget {
);
}

Widget displayParticipantState({ParticipantState? pState, required BoutRole role}) {
Widget displayParticipantState({ParticipantState? pState, required Bout bout, required BoutRole role}) {
final color = (role == bout.winnerRole) ? role.color().shade800 : null;
return NullableSingleConsumer<ParticipantState>(
id: pState?.id,
initialData: pState,
builder: (context, pState) => Column(
children: [
Expanded(
flex: 70,
builder: (context, pState) {
final technicalPoints = ParticipantState.getTechnicalPoints(actions, role);
return Column(
children: [
Expanded(
flex: 70,
child: ThemedContainer(
color: color,
child: Center(
child: bout.result != null
? ScaledText(
pState?.classificationPoints?.toString() ?? '0',
fontSize: 15,
)
: null,
),
)),
Expanded(
flex: 50,
child: ThemedContainer(
color: color,
child: Center(
child: ScaledText(
pState?.classificationPoints?.toString() ?? '-',
fontSize: 15,
),
child: bout.result != null ||
technicalPoints > 0 ||
bout.duration > Duration.zero ||
pState?.classificationPoints != null
? ScaledText(
technicalPoints.toString(),
fontSize: 8,
)
: null,
),
)),
Expanded(
flex: 50,
child: ThemedContainer(
color: color,
child: Center(
child: pState?.classificationPoints != null
? ScaledText(
ParticipantState.getTechnicalPoints(actions, role).toString(),
fontSize: 8,
)
: null,
),
),
),
],
),
],
);
},
);
}

Expand All @@ -186,6 +194,7 @@ class BoutListItem extends StatelessWidget {
initialData: bout,
id: bout.id,
builder: (context, bout) {
final winnerRole = bout.winnerRole;
return Row(
children: [
Row(
Expand Down Expand Up @@ -222,41 +231,34 @@ class BoutListItem extends StatelessWidget {
children: [
Expanded(
flex: 50,
child: displayParticipantState(pState: bout.r, role: BoutRole.red),
child: displayParticipantState(pState: bout.r, role: BoutRole.red, bout: bout),
),
Expanded(
flex: 100,
child: SingleConsumer<Bout>(
id: bout.id,
initialData: bout,
builder: (context, data) {
final winnerRole = data.winnerRole;
return Column(
children: [
Expanded(
flex: 70,
child: ThemedContainer(
color: winnerRole?.color().shade800,
child: Center(
child: ScaledText(data.result?.abbreviation(context) ?? '-', fontSize: 12),
),
)),
Expanded(
flex: 50,
child: Column(
children: [
Expanded(
flex: 70,
child: ThemedContainer(
color: winnerRole?.color().shade800,
child: Center(
child: winnerRole != null
? ScaledText(durationToString(data.duration), fontSize: 8)
: null,
child: ScaledText(bout.result?.abbreviation(context) ?? '', fontSize: 12),
),
),
],
);
},
)),
Expanded(
flex: 50,
child: Center(
child: bout.result != null || bout.duration > Duration.zero
? ScaledText(durationToString(bout.duration), fontSize: 8)
: null,
),
),
],
),
),
Expanded(
flex: 50,
child: displayParticipantState(pState: bout.b, role: BoutRole.blue),
child: displayParticipantState(pState: bout.b, role: BoutRole.blue, bout: bout),
),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ class TeamMatch extends WrestlingEvent with _$TeamMatch {
}

static int getHomePoints(Iterable<Bout> bouts) {
var res = 0;
for (final bout in bouts) {
res += bout.r?.classificationPoints ?? 0;
}
return res;
return getClassificationPoints(bouts.map((bout) => bout.r));
}

static int getGuestPoints(Iterable<Bout> bouts) {
return getClassificationPoints(bouts.map((bout) => bout.b));
}

static int getClassificationPoints(Iterable<ParticipantState?> participationStates) {
var res = 0;
for (final bout in bouts) {
res += bout.b?.classificationPoints ?? 0;
for (final state in participationStates) {
res += state?.classificationPoints ?? 0;
}
return res;
}
Expand Down

0 comments on commit 061fdbb

Please sign in to comment.