Initial commit: Flutter app + PHP/MySQL backend on Hostinger

Replaces Firebase with a self-hosted PHP/MySQL API served from
winded.prymsolutions.com. Includes full backend (schema, auth, events,
teams, brackets, suggestions, stats, media, file upload) and updated
Flutter repositories and domain models.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-14 20:13:57 -07:00
commit b239ae3e5f
208 changed files with 19187 additions and 0 deletions
@@ -0,0 +1,349 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../application/stats_notifier.dart';
import 'widgets/leaderboard_tile.dart';
import 'widgets/stat_bar_chart.dart';
import 'widgets/stats_filter_bar.dart';
/// Stats hub: standings + player leaderboards. Driven by [DefaultTabController]
/// so the [StatsFilterBar] in the AppBar bottom slot stays in sync with the
/// [TabBarView] below.
class StatsScreen extends ConsumerWidget {
const StatsScreen({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(
title: const Text('Stats'),
bottom: const StatsFilterBar(),
),
body: const TabBarView(
children: [
_StandingsTab(),
_ScorersTab(),
_AssistsTab(),
],
),
),
);
}
}
// ---------------------------------------------------------------------------
// Standings
// ---------------------------------------------------------------------------
class _StandingsTab extends ConsumerWidget {
const _StandingsTab();
@override
Widget build(BuildContext context, WidgetRef ref) {
final standingsAsync = ref.watch(teamStandingsProvider);
return standingsAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (err, _) => _ErrorState(
message: err.toString(),
onRetry: () => ref.invalidate(teamStandingsProvider),
),
data: (teams) {
if (teams.isEmpty) {
return const _EmptyState(
icon: Icons.emoji_events_outlined,
title: 'No standings yet',
body: 'League standings will appear once teams have played games.',
);
}
return ListView(
padding: const EdgeInsets.symmetric(vertical: 12),
children: [
const _SectionHeader(label: 'League standings'),
const _StandingsHeaderRow(),
for (var i = 0; i < teams.length; i++)
LeaderboardTile.team(
rank: i + 1,
team: teams[i],
navContext: context,
),
const SizedBox(height: 24),
const _SectionHeader(label: 'Wins by team'),
StatBarChart(
valueLabel: 'Wins',
data: [
for (final t in teams)
StatBarDatum(label: t.name, value: t.wins),
],
),
const SizedBox(height: 24),
],
);
},
);
}
}
class _StandingsHeaderRow extends StatelessWidget {
const _StandingsHeaderRow();
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final style = theme.textTheme.labelSmall?.copyWith(
color: scheme.onSurfaceVariant,
fontWeight: FontWeight.w700,
letterSpacing: 0.6,
);
return Padding(
padding: const EdgeInsets.fromLTRB(24, 4, 24, 8),
child: Row(
children: [
SizedBox(width: 34, child: Text('#', style: style)),
const SizedBox(width: 12),
Expanded(child: Text('TEAM', style: style)),
const SizedBox(width: 12),
SizedBox(width: 70, child: Text('W · D · L', style: style)),
SizedBox(
width: 48,
child: Text(
'PTS',
style: style,
textAlign: TextAlign.right,
),
),
],
),
);
}
}
// ---------------------------------------------------------------------------
// Player leaderboards
// ---------------------------------------------------------------------------
class _ScorersTab extends ConsumerWidget {
const _ScorersTab();
@override
Widget build(BuildContext context, WidgetRef ref) {
final scorersAsync = ref.watch(topScorersProvider);
return scorersAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (err, _) => _ErrorState(
message: err.toString(),
onRetry: () => ref.invalidate(topScorersProvider),
),
data: (entries) => _PlayerLeaderboardView(
entries: entries,
statSelector: (p) => p.player.goalsScored,
statLabel: 'goals',
chartLabel: 'Goals',
headerTitle: 'Top scorers',
chartTitle: 'Top 6 scorers',
emptyTitle: 'No goals yet',
emptyBody: 'Player goal tallies will appear here once games are logged.',
),
);
}
}
class _AssistsTab extends ConsumerWidget {
const _AssistsTab();
@override
Widget build(BuildContext context, WidgetRef ref) {
final assistsAsync = ref.watch(topAssistersProvider);
return assistsAsync.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (err, _) => _ErrorState(
message: err.toString(),
onRetry: () => ref.invalidate(topAssistersProvider),
),
data: (entries) => _PlayerLeaderboardView(
entries: entries,
statSelector: (p) => p.player.assists,
statLabel: 'assists',
chartLabel: 'Assists',
headerTitle: 'Top assists',
chartTitle: 'Top 6 assist leaders',
emptyTitle: 'No assists yet',
emptyBody:
'Player assist tallies will appear here once games are logged.',
),
);
}
}
/// Shared layout for the two player-stat tabs: chart on top, ranked list below.
class _PlayerLeaderboardView extends StatelessWidget {
const _PlayerLeaderboardView({
required this.entries,
required this.statSelector,
required this.statLabel,
required this.chartLabel,
required this.headerTitle,
required this.chartTitle,
required this.emptyTitle,
required this.emptyBody,
});
final List<PlayerWithTeam> entries;
final int Function(PlayerWithTeam) statSelector;
final String statLabel;
final String chartLabel;
final String headerTitle;
final String chartTitle;
final String emptyTitle;
final String emptyBody;
@override
Widget build(BuildContext context) {
// Drop players who haven't scored anything in the active category so the
// chart and list stay meaningful when the season just started.
final ranked = entries.where((e) => statSelector(e) > 0).toList();
if (ranked.isEmpty) {
return _EmptyState(
icon: Icons.bar_chart_outlined,
title: emptyTitle,
body: emptyBody,
);
}
final top = ranked.take(6).toList(growable: false);
return ListView(
padding: const EdgeInsets.symmetric(vertical: 12),
children: [
_SectionHeader(label: chartTitle),
StatBarChart(
valueLabel: chartLabel,
data: [
for (final e in top)
StatBarDatum(label: e.player.name, value: statSelector(e)),
],
),
const SizedBox(height: 16),
_SectionHeader(label: headerTitle),
for (var i = 0; i < ranked.length; i++)
LeaderboardTile.player(
rank: i + 1,
entry: ranked[i],
statValue: statSelector(ranked[i]),
statLabel: statLabel,
navContext: context,
),
const SizedBox(height: 24),
],
);
}
}
// ---------------------------------------------------------------------------
// Shared bits
// ---------------------------------------------------------------------------
class _SectionHeader extends StatelessWidget {
const _SectionHeader({required this.label});
final String label;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Padding(
padding: const EdgeInsets.fromLTRB(20, 4, 20, 8),
child: Text(
label,
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w700,
),
),
);
}
}
class _EmptyState extends StatelessWidget {
const _EmptyState({
required this.icon,
required this.title,
required this.body,
});
final IconData icon;
final String title;
final String body;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, size: 64, color: theme.colorScheme.onSurfaceVariant),
const SizedBox(height: 16),
Text(title, style: theme.textTheme.titleMedium),
const SizedBox(height: 8),
Text(
body,
textAlign: TextAlign.center,
style: theme.textTheme.bodyMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
],
),
),
);
}
}
class _ErrorState extends StatelessWidget {
const _ErrorState({required this.message, required this.onRetry});
final String message;
final VoidCallback onRetry;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
return Center(
child: Padding(
padding: const EdgeInsets.all(32),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.error_outline,
size: 64,
color: theme.colorScheme.error,
),
const SizedBox(height: 16),
Text('Could not load stats', style: theme.textTheme.titleMedium),
const SizedBox(height: 8),
Text(
message,
textAlign: TextAlign.center,
style: theme.textTheme.bodySmall?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
const SizedBox(height: 16),
FilledButton.tonalIcon(
onPressed: onRetry,
icon: const Icon(Icons.refresh),
label: const Text('Try again'),
),
],
),
),
);
}
}
@@ -0,0 +1,197 @@
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import '../../../teams/domain/team.dart';
import '../../application/stats_notifier.dart';
/// Ranked row used in every leaderboard list on the Stats screen.
///
/// Use either [LeaderboardTile.player] for the player leaderboards or
/// [LeaderboardTile.team] for the league standings — both share the rank
/// medal styling and tap affordances.
class LeaderboardTile extends StatelessWidget {
const LeaderboardTile._({
required this.rank,
required this.title,
required this.subtitle,
required this.trailingValue,
required this.trailingLabel,
this.onTap,
});
/// Player leaderboard variant. Tapping navigates to the player's team page.
factory LeaderboardTile.player({
Key? key,
required int rank,
required PlayerWithTeam entry,
required int statValue,
required String statLabel,
BuildContext? navContext,
}) {
return LeaderboardTile._(
rank: rank,
title: entry.player.name,
subtitle: entry.team.name,
trailingValue: statValue,
trailingLabel: statLabel,
onTap: navContext == null
? null
: () => navContext.go('/teams/${entry.team.id}'),
);
}
/// Team standings variant. Tapping navigates to the team detail page.
factory LeaderboardTile.team({
Key? key,
required int rank,
required Team team,
BuildContext? navContext,
}) {
final points = team.wins * 3 + team.draws;
return LeaderboardTile._(
rank: rank,
title: team.name,
subtitle: '${team.wins}W · ${team.draws}D · ${team.losses}L',
trailingValue: points,
trailingLabel: 'pts',
onTap: navContext == null
? null
: () => navContext.go('/teams/${team.id}'),
);
}
final int rank;
final String title;
final String subtitle;
final int trailingValue;
final String trailingLabel;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
return Card(
clipBehavior: Clip.antiAlias,
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 4),
child: InkWell(
onTap: onTap,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
child: Row(
children: [
_RankMedal(rank: rank),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.titleSmall?.copyWith(
fontWeight: FontWeight.w700,
),
),
const SizedBox(height: 2),
Text(
subtitle,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: theme.textTheme.bodySmall?.copyWith(
color: scheme.onSurfaceVariant,
),
),
],
),
),
const SizedBox(width: 12),
_TrailingStat(value: trailingValue, label: trailingLabel),
],
),
),
),
);
}
}
class _RankMedal extends StatelessWidget {
const _RankMedal({required this.rank});
final int rank;
// Podium medal colors — only hardcoded colors in the feature.
static const _gold = Color(0xFFFFD700);
static const _silver = Color(0xFFC0C0C0);
static const _bronze = Color(0xFFCD7F32);
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final isPodium = rank >= 1 && rank <= 3;
final medalColor = switch (rank) {
1 => _gold,
2 => _silver,
3 => _bronze,
_ => scheme.surfaceContainerHighest,
};
final textColor = isPodium ? Colors.black : scheme.onSurfaceVariant;
return Container(
width: 34,
height: 34,
alignment: Alignment.center,
decoration: BoxDecoration(
color: medalColor,
shape: BoxShape.circle,
border: isPodium
? null
: Border.all(color: scheme.outlineVariant, width: 1),
),
child: Text(
'$rank',
style: TextStyle(
color: textColor,
fontWeight: FontWeight.w800,
fontSize: 13,
),
),
);
}
}
class _TrailingStat extends StatelessWidget {
const _TrailingStat({required this.value, required this.label});
final int value;
final String label;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
return Column(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'$value',
style: theme.textTheme.titleMedium?.copyWith(
color: scheme.primary,
fontWeight: FontWeight.w800,
),
),
Text(
label,
style: theme.textTheme.labelSmall?.copyWith(
color: scheme.onSurfaceVariant,
letterSpacing: 0.4,
),
),
],
);
}
}
@@ -0,0 +1,214 @@
import 'package:fl_chart/fl_chart.dart';
import 'package:flutter/material.dart';
/// A single labelled bar in [StatBarChart].
class StatBarDatum {
const StatBarDatum({required this.label, required this.value});
/// Short label rendered along the X axis (kept terse so it fits).
final String label;
final int value;
}
/// Lightweight wrapper around [BarChart] for the top-6 leaderboards. Renders
/// vertical bars with a numeric Y axis and the supplied [data] labels on X.
class StatBarChart extends StatelessWidget {
const StatBarChart({
super.key,
required this.data,
required this.valueLabel,
this.height = 280,
});
/// Sorted list of bars to render (highest first); only the first 6 are used.
final List<StatBarDatum> data;
/// Used for the Y axis title, e.g. "Goals".
final String valueLabel;
final double height;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
final visible = data.take(6).toList(growable: false);
if (visible.isEmpty) {
return SizedBox(
height: height,
child: Center(
child: Text(
'No data yet',
style: theme.textTheme.bodyMedium?.copyWith(
color: scheme.onSurfaceVariant,
),
),
),
);
}
final maxValue = visible
.map((d) => d.value)
.fold<int>(0, (a, b) => a > b ? a : b);
// Round the y-axis ceiling up to the nearest sensible interval so the
// grid lines land on whole numbers.
final yMax = maxValue <= 4 ? 4.0 : (maxValue + 2).toDouble();
final interval = yMax <= 6 ? 1.0 : (yMax / 5).ceilToDouble();
return Padding(
padding: const EdgeInsets.fromLTRB(12, 4, 16, 8),
child: SizedBox(
height: height,
child: BarChart(
BarChartData(
alignment: BarChartAlignment.spaceAround,
maxY: yMax,
minY: 0,
barTouchData: BarTouchData(
enabled: true,
touchTooltipData: BarTouchTooltipData(
getTooltipColor: (_) => scheme.surfaceContainerHigh,
tooltipBorder: BorderSide(color: scheme.outlineVariant),
getTooltipItem: (group, _, rod, _) {
final datum = visible[group.x];
return BarTooltipItem(
'${datum.label}\n',
theme.textTheme.bodySmall!.copyWith(
color: scheme.onSurface,
fontWeight: FontWeight.w700,
),
children: [
TextSpan(
text: '${rod.toY.toInt()} $valueLabel',
style: theme.textTheme.bodySmall?.copyWith(
color: scheme.primary,
fontWeight: FontWeight.w700,
),
),
],
);
},
),
),
gridData: FlGridData(
show: true,
drawVerticalLine: false,
horizontalInterval: interval,
getDrawingHorizontalLine: (_) => FlLine(
color: scheme.outlineVariant.withValues(alpha: 0.4),
strokeWidth: 1,
),
),
borderData: FlBorderData(show: false),
titlesData: FlTitlesData(
show: true,
topTitles: const AxisTitles(
sideTitles: SideTitles(showTitles: false),
),
rightTitles: const AxisTitles(
sideTitles: SideTitles(showTitles: false),
),
leftTitles: AxisTitles(
axisNameWidget: Padding(
padding: const EdgeInsets.only(bottom: 6),
child: Text(
valueLabel,
style: theme.textTheme.labelSmall?.copyWith(
color: scheme.onSurfaceVariant,
letterSpacing: 0.5,
),
),
),
axisNameSize: 18,
sideTitles: SideTitles(
showTitles: true,
interval: interval,
reservedSize: 32,
getTitlesWidget: (value, meta) {
if (value == 0 || value > yMax) {
return const SizedBox.shrink();
}
return Padding(
padding: const EdgeInsets.only(right: 4),
child: Text(
value.toInt().toString(),
style: theme.textTheme.labelSmall?.copyWith(
color: scheme.onSurfaceVariant,
),
),
);
},
),
),
bottomTitles: AxisTitles(
sideTitles: SideTitles(
showTitles: true,
reservedSize: 36,
interval: 1,
getTitlesWidget: (value, meta) {
final index = value.toInt();
if (index < 0 || index >= visible.length) {
return const SizedBox.shrink();
}
return Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
_shortLabel(visible[index].label),
textAlign: TextAlign.center,
style: theme.textTheme.labelSmall?.copyWith(
color: scheme.onSurfaceVariant,
fontWeight: FontWeight.w600,
),
),
);
},
),
),
),
barGroups: [
for (var i = 0; i < visible.length; i++)
BarChartGroupData(
x: i,
barRods: [
BarChartRodData(
toY: visible[i].value.toDouble(),
color: scheme.primary,
width: 22,
borderRadius: const BorderRadius.vertical(
top: Radius.circular(6),
),
backDrawRodData: BackgroundBarChartRodData(
show: true,
toY: yMax,
color: scheme.surfaceContainerHighest
.withValues(alpha: 0.5),
),
),
],
),
],
),
),
),
);
}
/// Compresses long names like "Marcus Reed" → "M. Reed" so X-axis labels
/// don't overflow on phone widths.
static String _shortLabel(String full) {
final parts = full.trim().split(RegExp(r'\s+'));
if (parts.length < 2) {
return parts.first.length > 10
? '${parts.first.substring(0, 9)}'
: parts.first;
}
final last = parts.last;
final first = parts.first;
final initial = first.isEmpty ? '' : '${first[0]}. ';
final candidate = '$initial$last';
if (candidate.length <= 12) return candidate;
return '${candidate.substring(0, 11)}';
}
}
@@ -0,0 +1,30 @@
import 'package:flutter/material.dart';
/// Top tab strip for the Stats screen. Hosted inside an [AppBar] `bottom:`
/// slot and driven by an ambient [DefaultTabController].
class StatsFilterBar extends StatelessWidget implements PreferredSizeWidget {
const StatsFilterBar({super.key});
static const double _height = 48;
@override
Size get preferredSize => const Size.fromHeight(_height);
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
return TabBar(
isScrollable: false,
labelColor: scheme.primary,
unselectedLabelColor: scheme.onSurfaceVariant,
indicatorColor: scheme.primary,
indicatorSize: TabBarIndicatorSize.label,
labelStyle: const TextStyle(fontWeight: FontWeight.w700),
tabs: const [
Tab(text: 'Standings'),
Tab(text: 'Top Scorers'),
Tab(text: 'Top Assists'),
],
);
}
}