sdf
This commit is contained in:
1 parent
4d377c1336
commit
02ab7f390d
3 files changed
+84
-31
No files matched your search
@@ -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',
|
||||
};
|
||||
CardType.red => 'Red',
|
||||
CardType.yellow => 'Yellow',
|
||||
CardType.green => 'Green',
|
||||
};
|
||||
Reference in new issue
Block a user