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,63 +0,0 @@
import '../../domain/models/task_item.dart';
class TaskItemModel {
const TaskItemModel({
required this.id,
required this.title,
required this.description,
required this.isCompleted,
required this.category,
required this.createdAt,
});
final String id;
final String title;
final String description;
final bool isCompleted;
final String category;
final String createdAt;
factory TaskItemModel.fromJson(Map<String, dynamic> json) {
return TaskItemModel(
id: json['id'] as String,
title: json['title'] as String,
description: json['description'] as String? ?? '',
isCompleted: json['isCompleted'] as bool? ?? false,
category: json['category'] as String? ?? 'General',
createdAt: json['createdAt'] as String,
);
}
Map<String, dynamic> toJson() {
return {
'id': id,
'title': title,
'description': description,
'isCompleted': isCompleted,
'category': category,
'createdAt': createdAt,
};
}
TaskItem toDomain() {
return TaskItem(
id: id,
title: title,
description: description,
isCompleted: isCompleted,
category: category,
createdAt: DateTime.tryParse(createdAt) ?? DateTime.now(),
);
}
factory TaskItemModel.fromDomain(TaskItem item) {
return TaskItemModel(
id: item.id,
title: item.title,
description: item.description,
isCompleted: item.isCompleted,
category: item.category,
createdAt: item.createdAt.toIso8601String(),
);
}
}
@@ -0,0 +1,18 @@
import 'dart:convert';
import 'package:flutter/services.dart';
import '../../domain/models/hockey_game.dart';
class MatchRepository {
MatchRepository({AssetBundle? bundle}) : _bundle = bundle ?? rootBundle;
final AssetBundle _bundle;
Future<List<Match>> loadMatches() async {
final contents = await _bundle.loadString('lib/data/results.json');
final data = jsonDecode(contents) as Map<String, dynamic>;
return (data['games'] as List<dynamic>)
.map((game) => Match.fromJson(game as Map<String, dynamic>))
.toList();
}
}
@@ -1,53 +0,0 @@
import '../../domain/models/task_item.dart';
import '../models/task_item_model.dart';
import '../services/mock_task_service.dart';
class TaskRepository {
TaskRepository({required this._service});
final MockTaskService _service;
List<TaskItem>? _cachedTasks;
Future<List<TaskItem>> getTasks({bool forceRefresh = false}) async {
if (!forceRefresh && _cachedTasks != null) {
return _cachedTasks!;
}
final models = await _service.fetchTasks();
_cachedTasks = models.map((m) => m.toDomain()).toList();
return _cachedTasks!;
}
Future<TaskItem> createTask({
required String title,
required String description,
required String category,
}) async {
final newItem = TaskItem(
id: DateTime.now().millisecondsSinceEpoch.toString(),
title: title,
description: description,
category: category,
createdAt: DateTime.now(),
);
await _service.addTask(TaskItemModel.fromDomain(newItem));
_cachedTasks?.insert(0, newItem);
return newItem;
}
Future<void> toggleTaskStatus(TaskItem item) async {
final updated = item.copyWith(isCompleted: !item.isCompleted);
await _service.updateTask(TaskItemModel.fromDomain(updated));
if (_cachedTasks != null) {
final index = _cachedTasks!.indexWhere((t) => t.id == item.id);
if (index != -1) {
_cachedTasks![index] = updated;
}
}
}
Future<void> removeTask(String id) async {
await _service.deleteTask(id);
_cachedTasks?.removeWhere((t) => t.id == id);
}
}
+117
View File
@@ -0,0 +1,117 @@
{
"games": [
{ "datetime": "2023-10-01T12:00:00Z",
"awayScore": 0,
"homeScore": 1,
"cards": [
{
"card_type": 0,
"datetime": "2023-10-01T12:25:00Z",
"duration": 120,
"player": 5,
"elapsed": 125,
"team": 1
},
{
"card_type": 1,
"datetime": "2023-10-01T12:35:00Z",
"duration": 120,
"player": 8,
"elapsed": 235,
"team": 0
}
],
"goals": [
{
"datetime": "2023-10-01T12:15:00Z",
"player": 32,
"score": 1,
"elapsed": 88,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"elapsed": 66,
"team": 0
}
]
},
{ "datetime": "2023-11-01T12:00:00Z",
"awayScore": 0,
"homeScore": 1,
"cards": [
{
"card_type": 1,
"datetime": "2023-11-01T12:25:00Z",
"duration": 120,
"player": 5,
"elapsed": 125,
"team": 1
},
{
"card_type": 0,
"datetime": "2023-10-01T12:35:00Z",
"duration": 120,
"player": 8,
"elapsed": 235,
"team": 0
}
],
"goals": [
{
"datetime": "2023-10-01T12:15:00Z",
"player": 32,
"elapsed": 88,
"team": 1
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"elapsed": 32,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"elapsed": 66,
"team": 0
}
]
},
{ "datetime": "2023-11-01T12:00:00Z",
"awayScore": 0,
"homeScore": 1,
"cards": [
{
"card_type": 1,
"datetime": "2023-11-01T12:25:00Z",
"duration": 120,
"player": 5,
"elapsed": 125,
"team": 1
}
],
"goals": [
{
"datetime": "2023-10-01T12:15:00Z",
"player": 32,
"elapsed": 88,
"team": 1
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"elapsed": 32,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"elapsed": 66,
"team": 0
}
]
}
]
}
@@ -1,55 +0,0 @@
import '../models/task_item_model.dart';
class MockTaskService {
final List<Map<String, dynamic>> _rawStorage = [
{
'id': '1',
'title': 'Explore Material 3 Layouts',
'description': 'Test responsiveness on both iPhone and Android screen sizes.',
'isCompleted': true,
'category': 'Design',
'createdAt': DateTime.now().subtract(const Duration(hours: 4)).toIso8601String(),
},
{
'id': '2',
'title': 'Test Light & Dark Modes',
'description': 'Ensure contrast and colors look great in both themes.',
'isCompleted': false,
'category': 'Theme',
'createdAt': DateTime.now().subtract(const Duration(hours: 2)).toIso8601String(),
},
{
'id': '3',
'title': 'Verify Accessibility & Touch Targets',
'description': 'Ensure tap targets adhere to >= 48x48 logical pixels with semantic labels.',
'isCompleted': false,
'category': 'A11y',
'createdAt': DateTime.now().subtract(const Duration(minutes: 30)).toIso8601String(),
},
];
Future<List<TaskItemModel>> fetchTasks() async {
// Simulate brief network/storage delay
await Future.delayed(const Duration(milliseconds: 250));
return _rawStorage.map(TaskItemModel.fromJson).toList();
}
Future<TaskItemModel> addTask(TaskItemModel task) async {
await Future.delayed(const Duration(milliseconds: 150));
_rawStorage.insert(0, task.toJson());
return task;
}
Future<void> updateTask(TaskItemModel task) async {
await Future.delayed(const Duration(milliseconds: 150));
final index = _rawStorage.indexWhere((e) => e['id'] == task.id);
if (index != -1) {
_rawStorage[index] = task.toJson();
}
}
Future<void> deleteTask(String id) async {
await Future.delayed(const Duration(milliseconds: 150));
_rawStorage.removeWhere((e) => e['id'] == id);
}
}