From 02ab7f390db5154b3b70987be9a1d48862784120 Mon Sep 17 00:00:00 2001 From: kejaro Date: Sun, 27 Sep 2026 19:54:29 +0100 Subject: [PATCH] sdf --- mobile_app/lib/data/results.json | 11 ++- .../dashboard/views/match_results_view.dart | 79 ++++++++++++------- mobile_app/test/widget_test.dart | 25 +++++- 3 files changed, 84 insertions(+), 31 deletions(-) diff --git a/mobile_app/lib/data/results.json b/mobile_app/lib/data/results.json index cc72efe..fe9a726 100644 --- a/mobile_app/lib/data/results.json +++ b/mobile_app/lib/data/results.json @@ -25,13 +25,14 @@ { "datetime": "2023-10-01T12:15:00Z", "player": 32, - "score": 1, + "goal_type": 1, "elapsed": 88, "team": 1 }, { "datetime": "2023-10-01T12:30:00Z", "player": 2, + "goal_type": 0, "elapsed": 66, "team": 0 } @@ -62,18 +63,21 @@ { "datetime": "2023-10-01T12:15:00Z", "player": 32, + "goal_type": 1, "elapsed": 88, - "team": 1 + "team": 2 }, { "datetime": "2023-10-01T12:20:00Z", "player": 32, + "goal_type": 0, "elapsed": 32, "team": 1 }, { "datetime": "2023-10-01T12:30:00Z", "player": 2, + "goal_type": 2, "elapsed": 66, "team": 0 } @@ -97,18 +101,21 @@ "datetime": "2023-10-01T12:15:00Z", "player": 32, "elapsed": 88, + "goal_type": 2, "team": 1 }, { "datetime": "2023-10-01T12:20:00Z", "player": 32, "elapsed": 32, + "goal_type": 1, "team": 1 }, { "datetime": "2023-10-01T12:30:00Z", "player": 2, "elapsed": 66, + "goal_type": 0, "team": 0 } ] diff --git a/mobile_app/lib/ui/features/dashboard/views/match_results_view.dart b/mobile_app/lib/ui/features/dashboard/views/match_results_view.dart index ae84a7f..e3a3164 100644 --- a/mobile_app/lib/ui/features/dashboard/views/match_results_view.dart +++ b/mobile_app/lib/ui/features/dashboard/views/match_results_view.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; -import '../../../../domain/models/hockey_game.dart' show CardType, Match, Team; + +import '../../../../domain/models/hockey_game.dart' + show CardType, GoalType, Match, Team; import '../view_models/match_results_view_model.dart'; class MatchResultsView extends StatelessWidget { @@ -25,9 +27,8 @@ class MatchResultsView extends StatelessWidget { return ListView.builder( padding: const EdgeInsets.all(16), itemCount: viewModel.matches.length, - itemBuilder: (context, index) => _MatchCard( - match: viewModel.matches[index], - ), + itemBuilder: (context, index) => + _MatchCard(match: viewModel.matches[index]), ); }, ); @@ -46,17 +47,18 @@ class _MatchCard extends StatelessWidget { final date = DateTime.tryParse(match.datetime)?.toLocal(); final dateLabel = date == null ? match.datetime - : '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')}'; + : '${date.year}-${date.month.toString().padLeft(2, '0')}-${date.day.toString().padLeft(2, '0')} ${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}'; return Card( margin: const EdgeInsets.only(bottom: 12), - child: Padding( - padding: const EdgeInsets.all(16), - child: Column( + child: ExpansionTile( + shape: const Border(), + collapsedShape: const Border(), + title: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(dateLabel, style: textTheme.labelLarge), - const SizedBox(height: 12), + const SizedBox(height: 8), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ @@ -71,21 +73,35 @@ class _MatchCard extends StatelessWidget { const Text('Away'), ], ), - if (match.goals.isNotEmpty || match.cards.isNotEmpty) ...[ - const Divider(height: 24), - ...match.goals.map((goal) => _EventLine( - icon: Icons.sports_hockey, - label: 'Goal · ${_teamName(goal.team)} · #${goal.player}', - seconds: goal.seconds, - )), - ...match.cards.map((card) => _EventLine( - icon: Icons.style_outlined, - label: '${_cardName(card.cardType)} card · ${_teamName(card.team)} · #${card.player}', - seconds: card.seconds, - )), - ], ], ), + childrenPadding: const EdgeInsets.fromLTRB(16, 8, 16, 8), + children: [ + ...match.goals.map( + (goal) => _EventLine( + icon: Icons.sports_hockey, + label: + '${_goalTypeName(goal.goalType)} · ${_teamName(goal.team)} · #${goal.player}', + seconds: goal.seconds, + ), + ), + ...match.cards.map( + (card) => _EventLine( + icon: Icons.style_outlined, + label: + '${_cardName(card.cardType)} card · ${_teamName(card.team)} · #${card.player} · ${card.duration}s', + seconds: card.seconds, + ), + ), + if (match.goals.isEmpty && match.cards.isEmpty) + const Padding( + padding: EdgeInsets.only(bottom: 8), + child: Align( + alignment: Alignment.centerLeft, + child: Text('No recorded events'), + ), + ), + ], ), ); } @@ -113,7 +129,10 @@ class _EventLine extends StatelessWidget { Icon(icon, size: 18, color: Theme.of(context).colorScheme.secondary), const SizedBox(width: 8), Expanded(child: Text(label)), - Text('$minute:$second', style: Theme.of(context).textTheme.labelMedium), + Text( + '$minute:$second', + style: Theme.of(context).textTheme.labelMedium, + ), ], ), ); @@ -122,8 +141,14 @@ class _EventLine extends StatelessWidget { String _teamName(Team team) => team == Team.home ? 'Home' : 'Away'; +String _goalTypeName(GoalType type) => switch (type) { + GoalType.fieldGoal => 'Field goal', + GoalType.shortCorner => 'Short corner', + GoalType.penaltyStroke => 'Penalty stroke', +}; + String _cardName(CardType type) => switch (type) { - CardType.red => 'Red', - CardType.yellow => 'Yellow', - CardType.green => 'Green', - }; \ No newline at end of file + CardType.red => 'Red', + CardType.yellow => 'Yellow', + CardType.green => 'Green', +}; diff --git a/mobile_app/test/widget_test.dart b/mobile_app/test/widget_test.dart index f3baad2..a0b1233 100644 --- a/mobile_app/test/widget_test.dart +++ b/mobile_app/test/widget_test.dart @@ -1,15 +1,36 @@ +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mobile_app/app.dart'; void main() { - testWidgets('App smoke test - renders match results, navigates to settings', - (WidgetTester tester) async { + testWidgets('App smoke test - renders match results, navigates to settings', ( + WidgetTester tester, + ) async { await tester.pumpWidget(const MobileApp()); await tester.pumpAndSettle(); expect(find.text('Match Results'), findsOneWidget); expect(find.text('Home'), findsWidgets); expect(find.text('Away'), findsWidgets); + expect( + find.textContaining(RegExp(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}')), + findsWidgets, + ); + expect(find.text('Field goal · Away · #32'), findsNothing); + + await tester.tap( + find.textContaining(RegExp(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}')).first, + ); + await tester.pumpAndSettle(); + + expect(find.text('Field goal · Away · #32'), findsWidgets); + expect(find.textContaining('card · Away · #5 · 120s'), findsWidgets); + expect(find.byType(Divider), findsNothing); + final matchTile = tester.widget( + find.byType(ExpansionTile).first, + ); + expect(matchTile.shape, const Border()); + expect(matchTile.collapsedShape, const Border()); // Switch to Settings tab final settingsNav = find.text('Settings');