Updates
This commit is contained in:
1 parent
02ab7f390d
commit
97c10c8d12
7 files changed
+559
-16
No files matched your search
@@ -1,4 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
|
||||
import '../../../../domain/models/hockey_game.dart'
|
||||
show CardType, GoalType, Match, Team;
|
||||
@@ -35,13 +37,21 @@ class MatchResultsView extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _MatchCard extends StatelessWidget {
|
||||
class _MatchCard extends StatefulWidget {
|
||||
const _MatchCard({required this.match});
|
||||
|
||||
final Match match;
|
||||
|
||||
@override
|
||||
State<_MatchCard> createState() => _MatchCardState();
|
||||
}
|
||||
|
||||
class _MatchCardState extends State<_MatchCard> {
|
||||
bool _isExpanded = false;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final match = widget.match;
|
||||
final colors = Theme.of(context).colorScheme;
|
||||
final textTheme = Theme.of(context).textTheme;
|
||||
final date = DateTime.tryParse(match.datetime)?.toLocal();
|
||||
@@ -54,6 +64,16 @@ class _MatchCard extends StatelessWidget {
|
||||
child: ExpansionTile(
|
||||
shape: const Border(),
|
||||
collapsedShape: const Border(),
|
||||
onExpansionChanged: (expanded) => setState(() => _isExpanded = expanded),
|
||||
trailing: _isExpanded
|
||||
? IconButton(
|
||||
tooltip: 'Share match',
|
||||
icon: const Icon(Icons.share_outlined),
|
||||
onPressed: () => SharePlus.instance.share(
|
||||
ShareParams(text: _matchShareText(match)),
|
||||
),
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
title: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -79,17 +99,23 @@ class _MatchCard extends StatelessWidget {
|
||||
children: [
|
||||
...match.goals.map(
|
||||
(goal) => _EventLine(
|
||||
icon: Icons.sports_hockey,
|
||||
label:
|
||||
'${_goalTypeName(goal.goalType)} · ${_teamName(goal.team)} · #${goal.player}',
|
||||
leading: Icon(
|
||||
Icons.sports_hockey,
|
||||
size: 18,
|
||||
color: Theme.of(context).colorScheme.secondary,
|
||||
),
|
||||
team: _teamName(goal.team),
|
||||
playerNumber: goal.player,
|
||||
eventType: _goalTypeName(goal.goalType),
|
||||
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',
|
||||
leading: _CardMarker(cardType: card.cardType),
|
||||
team: _teamName(card.team),
|
||||
playerNumber: card.player,
|
||||
eventType: '${_cardName(card.cardType)} card · ${_cardDurationLabel(card.duration)}',
|
||||
seconds: card.seconds,
|
||||
),
|
||||
),
|
||||
@@ -109,26 +135,75 @@ class _MatchCard extends StatelessWidget {
|
||||
|
||||
class _EventLine extends StatelessWidget {
|
||||
const _EventLine({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.leading,
|
||||
required this.team,
|
||||
required this.playerNumber,
|
||||
required this.eventType,
|
||||
required this.seconds,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final Widget leading;
|
||||
final String team;
|
||||
final int playerNumber;
|
||||
final String eventType;
|
||||
final int seconds;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final minute = seconds ~/ 60;
|
||||
final second = (seconds % 60).toString().padLeft(2, '0');
|
||||
final playerLabel = '#${playerNumber.toString().padLeft(2, '0')}';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.only(bottom: 4),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: 18, color: Theme.of(context).colorScheme.secondary),
|
||||
SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: Center(child: leading),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: Text(label)),
|
||||
SizedBox(
|
||||
width: 40,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(team),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 12,
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: const Text('·', textAlign: TextAlign.center),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 42,
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(playerLabel),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 12,
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: const Text('·', textAlign: TextAlign.center),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
eventType,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Text(
|
||||
'$minute:$second',
|
||||
style: Theme.of(context).textTheme.labelMedium,
|
||||
@@ -139,8 +214,69 @@ class _EventLine extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _CardMarker extends StatelessWidget {
|
||||
const _CardMarker({required this.cardType});
|
||||
|
||||
final CardType cardType;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final svgPath = switch (cardType) {
|
||||
CardType.green => 'lib/data/icons/green-card.svg',
|
||||
CardType.yellow => 'lib/data/icons/yellow-card.svg',
|
||||
CardType.red => 'lib/data/icons/red-card.svg',
|
||||
};
|
||||
|
||||
return SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: SvgPicture.asset(
|
||||
svgPath,
|
||||
width: 18,
|
||||
height: 18,
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
String _teamName(Team team) => team == Team.home ? 'Home' : 'Away';
|
||||
|
||||
String _matchShareText(Match match) {
|
||||
final buffer = StringBuffer()
|
||||
..writeln('Match result')
|
||||
..writeln(match.datetime)
|
||||
..writeln('Home ${match.homeScore} - ${match.awayScore} Away');
|
||||
|
||||
if (match.goals.isNotEmpty) {
|
||||
buffer.writeln();
|
||||
buffer.writeln('Goals:');
|
||||
for (final goal in match.goals) {
|
||||
buffer.writeln(
|
||||
'- ${_teamName(goal.team)} · #${goal.player.toString().padLeft(2, '0')} · ${_goalTypeName(goal.goalType)} · ${_formatTime(goal.seconds)}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (match.cards.isNotEmpty) {
|
||||
buffer.writeln();
|
||||
buffer.writeln('Cards:');
|
||||
for (final card in match.cards) {
|
||||
buffer.writeln(
|
||||
'- ${_teamName(card.team)} · #${card.player.toString().padLeft(2, '0')} · ${_cardName(card.cardType)} card · ${_cardDurationLabel(card.duration)} · ${_formatTime(card.seconds)}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
String _formatTime(int seconds) {
|
||||
final minute = seconds ~/ 60;
|
||||
final second = (seconds % 60).toString().padLeft(2, '0');
|
||||
return '$minute:$second';
|
||||
}
|
||||
|
||||
String _goalTypeName(GoalType type) => switch (type) {
|
||||
GoalType.fieldGoal => 'Field goal',
|
||||
GoalType.shortCorner => 'Short corner',
|
||||
@@ -152,3 +288,9 @@ String _cardName(CardType type) => switch (type) {
|
||||
CardType.yellow => 'Yellow',
|
||||
CardType.green => 'Green',
|
||||
};
|
||||
|
||||
String _cardDurationLabel(int durationSeconds) {
|
||||
final minutes = durationSeconds ~/ 60;
|
||||
final seconds = (durationSeconds % 60).toString().padLeft(2, '0');
|
||||
return '$minutes:$seconds';
|
||||
}
|
||||
Reference in new issue
Block a user