Refactor app to focus on match results instead of tasks

- Introduced MatchRepository and MatchResultsViewModel to handle match data.
- Replaced task-related code with match-related functionality in the app.
- Added match results view and updated navigation to reflect changes.
- Removed task-related models, services, and view models.
- Added JSON data for match results and integrated it into the app.
- Updated tests to validate match results loading and UI behavior.
This commit is contained in:
kejaro committed 2026-09-27 19:34:46 +01:00
1 parent ffc2051e20
commit 4d377c1336
17 files changed
+500 -658

No files matched your search

@@ -1,191 +0,0 @@
import 'package:flutter/material.dart';
import '../../../../domain/models/task_item.dart';
import '../view_models/dashboard_view_model.dart';
class DashboardView extends StatelessWidget {
const DashboardView({super.key, required this.viewModel});
final DashboardViewModel viewModel;
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: viewModel,
builder: (context, _) {
if (viewModel.isLoading) {
return const Center(child: CircularProgressIndicator());
}
final tasks = viewModel.tasks;
return ListView(
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 12.0),
children: [
_buildSummaryCard(context),
const SizedBox(height: 16),
_buildCategoryFilter(context),
const SizedBox(height: 12),
if (tasks.isEmpty)
_buildEmptyState(context)
else
...tasks.map((task) => _buildTaskCard(context, task)),
],
);
},
);
}
Widget _buildSummaryCard(BuildContext context) {
final colorScheme = Theme.of(context).colorScheme;
final textTheme = Theme.of(context).textTheme;
return Card(
color: colorScheme.surfaceContainerHighest.withAlpha(128),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'Task Progress',
style: textTheme.titleMedium?.copyWith(
fontWeight: FontWeight.bold,
),
),
Text(
'${viewModel.completedCount}/${viewModel.totalCount}',
style: textTheme.titleMedium?.copyWith(
color: colorScheme.primary,
fontWeight: FontWeight.bold,
),
),
],
),
const SizedBox(height: 12),
ClipRRect(
borderRadius: BorderRadius.circular(8),
child: LinearProgressIndicator(
value: viewModel.completionProgress,
minHeight: 10,
backgroundColor: colorScheme.surfaceContainerHighest,
),
),
const SizedBox(height: 8),
Text(
'${(viewModel.completionProgress * 100).round()}% completed',
style: textTheme.bodySmall?.copyWith(
color: colorScheme.onSurfaceVariant,
),
),
],
),
),
);
}
Widget _buildCategoryFilter(BuildContext context) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: viewModel.availableCategories.map((category) {
final isSelected = viewModel.selectedCategory == category;
return Padding(
padding: const EdgeInsets.only(right: 8.0),
child: FilterChip(
label: Text(category),
selected: isSelected,
onSelected: (_) => viewModel.setCategoryFilter(category),
),
);
}).toList(),
),
);
}
Widget _buildTaskCard(BuildContext context, TaskItem task) {
final colorScheme = Theme.of(context).colorScheme;
return Card(
margin: const EdgeInsets.only(bottom: 8.0),
child: ListTile(
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
leading: Checkbox(
value: task.isCompleted,
onChanged: (_) => viewModel.toggleTaskCompletion(task),
),
title: Text(
task.title,
style: TextStyle(
fontWeight: FontWeight.w600,
decoration: task.isCompleted
? TextDecoration.lineThrough
: TextDecoration.none,
color: task.isCompleted ? colorScheme.outline : null,
),
),
subtitle: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (task.description.isNotEmpty) ...[
const SizedBox(height: 4),
Text(
task.description,
style: TextStyle(
color: task.isCompleted ? colorScheme.outline : null,
),
),
],
const SizedBox(height: 6),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
decoration: BoxDecoration(
color: colorScheme.secondaryContainer,
borderRadius: BorderRadius.circular(6),
),
child: Text(
task.category,
style: TextStyle(
fontSize: 12,
color: colorScheme.onSecondaryContainer,
),
),
),
],
),
trailing: IconButton(
icon: const Icon(Icons.delete_outline),
tooltip: 'Delete task',
onPressed: () => viewModel.deleteTask(task.id),
),
),
);
}
Widget _buildEmptyState(BuildContext context) {
final theme = Theme.of(context);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 48.0),
child: Center(
child: Column(
children: [
Icon(
Icons.done_all,
size: 56,
color: theme.colorScheme.outlineVariant,
),
const SizedBox(height: 12),
Text(
'No tasks in this category',
style: theme.textTheme.titleMedium?.copyWith(
color: theme.colorScheme.onSurfaceVariant,
),
),
],
),
),
);
}
}
@@ -0,0 +1,129 @@
import 'package:flutter/material.dart';
import '../../../../domain/models/hockey_game.dart' show CardType, Match, Team;
import '../view_models/match_results_view_model.dart';
class MatchResultsView extends StatelessWidget {
const MatchResultsView({super.key, required this.viewModel});
final MatchResultsViewModel viewModel;
@override
Widget build(BuildContext context) {
return ListenableBuilder(
listenable: viewModel,
builder: (context, _) {
if (viewModel.isLoading) {
return const Center(child: CircularProgressIndicator());
}
if (viewModel.errorMessage != null) {
return Center(child: Text(viewModel.errorMessage!));
}
if (viewModel.matches.isEmpty) {
return const Center(child: Text('No match results available.'));
}
return ListView.builder(
padding: const EdgeInsets.all(16),
itemCount: viewModel.matches.length,
itemBuilder: (context, index) => _MatchCard(
match: viewModel.matches[index],
),
);
},
);
}
}
class _MatchCard extends StatelessWidget {
const _MatchCard({required this.match});
final Match match;
@override
Widget build(BuildContext context) {
final colors = Theme.of(context).colorScheme;
final textTheme = Theme.of(context).textTheme;
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')}';
return Card(
margin: const EdgeInsets.only(bottom: 12),
child: Padding(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(dateLabel, style: textTheme.labelLarge),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('Home'),
Text(
'${match.homeScore} : ${match.awayScore}',
style: textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.bold,
color: colors.primary,
),
),
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,
)),
],
],
),
),
);
}
}
class _EventLine extends StatelessWidget {
const _EventLine({
required this.icon,
required this.label,
required this.seconds,
});
final IconData icon;
final String label;
final int seconds;
@override
Widget build(BuildContext context) {
final minute = seconds ~/ 60;
final second = (seconds % 60).toString().padLeft(2, '0');
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: Row(
children: [
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),
],
),
);
}
}
String _teamName(Team team) => team == Team.home ? 'Home' : 'Away';
String _cardName(CardType type) => switch (type) {
CardType.red => 'Red',
CardType.yellow => 'Yellow',
CardType.green => 'Green',
};