diff --git a/wrestling_scoreboard_client/lib/view/screens/display/common.dart b/wrestling_scoreboard_client/lib/view/screens/display/common.dart index b1aef296..7a68e563 100644 --- a/wrestling_scoreboard_client/lib/view/screens/display/common.dart +++ b/wrestling_scoreboard_client/lib/view/screens/display/common.dart @@ -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 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( + SingleProviderData(initialData: participationState, id: participationState.id!), + ).future); + })); + return ThemedContainer( + color: color, + child: Center( + child: LoadingBuilder>( + 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 getTeamHeader(Team home, Team guest, List 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, @@ -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, - ), - ), ), ), ], diff --git a/wrestling_scoreboard_client/lib/view/screens/display/match/match_display.dart b/wrestling_scoreboard_client/lib/view/screens/display/match/match_display.dart index 50a16664..280936bb 100644 --- a/wrestling_scoreboard_client/lib/view/screens/display/match/match_display.dart +++ b/wrestling_scoreboard_client/lib/view/screens/display/match/match_display.dart @@ -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( 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, ), ), - ), - ], - ), + ], + ); + }, ); } @@ -186,6 +194,7 @@ class BoutListItem extends StatelessWidget { initialData: bout, id: bout.id, builder: (context, bout) { + final winnerRole = bout.winnerRole; return Row( children: [ Row( @@ -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( - 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), ), ], ), diff --git a/wrestling_scoreboard_common/lib/src/data/team_match/team_match.dart b/wrestling_scoreboard_common/lib/src/data/team_match/team_match.dart index c02426e2..873e2d3a 100644 --- a/wrestling_scoreboard_common/lib/src/data/team_match/team_match.dart +++ b/wrestling_scoreboard_common/lib/src/data/team_match/team_match.dart @@ -88,17 +88,17 @@ class TeamMatch extends WrestlingEvent with _$TeamMatch { } static int getHomePoints(Iterable 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 bouts) { + return getClassificationPoints(bouts.map((bout) => bout.b)); + } + + static int getClassificationPoints(Iterable 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; }