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:
1 parent
ffc2051e20
commit
4d377c1336
17 files changed
+500
-658
No files matched your search
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "mobile_app",
|
||||
"cwd": "mobile_app",
|
||||
"request": "launch",
|
||||
"type": "dart"
|
||||
},
|
||||
{
|
||||
"name": "mobile_app (profile mode)",
|
||||
"cwd": "mobile_app",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"flutterMode": "profile"
|
||||
},
|
||||
{
|
||||
"name": "mobile_app (release mode)",
|
||||
"cwd": "mobile_app",
|
||||
"request": "launch",
|
||||
"type": "dart",
|
||||
"flutterMode": "release"
|
||||
}
|
||||
]
|
||||
}
|
||||
+16
-106
@@ -1,11 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'data/repositories/task_repository.dart';
|
||||
import 'data/services/mock_task_service.dart';
|
||||
import 'data/repositories/match_repository.dart';
|
||||
import 'ui/core/theme/app_theme.dart';
|
||||
import 'ui/core/theme/theme_controller.dart';
|
||||
import 'ui/core/widgets/responsive_scaffold.dart';
|
||||
import 'ui/features/dashboard/view_models/dashboard_view_model.dart';
|
||||
import 'ui/features/dashboard/views/dashboard_view.dart';
|
||||
import 'ui/features/dashboard/view_models/match_results_view_model.dart';
|
||||
import 'ui/features/dashboard/views/match_results_view.dart';
|
||||
import 'ui/features/settings/views/settings_view.dart';
|
||||
|
||||
class MobileApp extends StatefulWidget {
|
||||
@@ -17,107 +16,26 @@ class MobileApp extends StatefulWidget {
|
||||
|
||||
class _MobileAppState extends State<MobileApp> {
|
||||
late final ThemeController _themeController;
|
||||
late final TaskRepository _taskRepository;
|
||||
late final DashboardViewModel _dashboardViewModel;
|
||||
late final MatchResultsViewModel _matchResultsViewModel;
|
||||
int _currentTabIndex = 0;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_themeController = ThemeController();
|
||||
_taskRepository = TaskRepository(service: MockTaskService());
|
||||
_dashboardViewModel = DashboardViewModel(repository: _taskRepository);
|
||||
_dashboardViewModel.loadTasks();
|
||||
_matchResultsViewModel = MatchResultsViewModel(
|
||||
repository: MatchRepository(),
|
||||
);
|
||||
_matchResultsViewModel.loadMatches();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_dashboardViewModel.dispose();
|
||||
_matchResultsViewModel.dispose();
|
||||
_themeController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _showAddTaskDialog(BuildContext context) {
|
||||
final titleController = TextEditingController();
|
||||
final descriptionController = TextEditingController();
|
||||
String selectedCategory = 'General';
|
||||
|
||||
showDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setDialogState) {
|
||||
return AlertDialog(
|
||||
title: const Text('New Task'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: titleController,
|
||||
autofocus: true,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Title',
|
||||
hintText: 'Enter task title',
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextField(
|
||||
controller: descriptionController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Description',
|
||||
hintText: 'Optional details',
|
||||
),
|
||||
maxLines: 2,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: selectedCategory,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Category',
|
||||
),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'General', child: Text('General')),
|
||||
DropdownMenuItem(value: 'Design', child: Text('Design')),
|
||||
DropdownMenuItem(value: 'Theme', child: Text('Theme')),
|
||||
DropdownMenuItem(value: 'A11y', child: Text('A11y')),
|
||||
],
|
||||
onChanged: (val) {
|
||||
if (val != null) {
|
||||
setDialogState(() => selectedCategory = val);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
final title = titleController.text.trim();
|
||||
if (title.isNotEmpty) {
|
||||
_dashboardViewModel.addTask(
|
||||
title: title,
|
||||
description: descriptionController.text.trim(),
|
||||
category: selectedCategory,
|
||||
);
|
||||
Navigator.of(dialogContext).pop();
|
||||
}
|
||||
},
|
||||
child: const Text('Add Task'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListenableBuilder(
|
||||
@@ -130,8 +48,8 @@ class _MobileAppState extends State<MobileApp> {
|
||||
darkTheme: AppTheme.darkTheme,
|
||||
themeMode: _themeController.themeMode,
|
||||
home: Builder(
|
||||
builder: (innerContext) {
|
||||
final isDarkMode = Theme.of(innerContext).brightness == Brightness.dark;
|
||||
builder: (context) {
|
||||
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
|
||||
|
||||
return ResponsiveScaffold(
|
||||
selectedIndex: _currentTabIndex,
|
||||
@@ -139,7 +57,7 @@ class _MobileAppState extends State<MobileApp> {
|
||||
setState(() => _currentTabIndex = index);
|
||||
},
|
||||
appBarTitle: Text(
|
||||
_currentTabIndex == 0 ? 'Dashboard' : 'Settings',
|
||||
_currentTabIndex == 0 ? 'Match Results' : 'Settings',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
actions: [
|
||||
@@ -151,19 +69,11 @@ class _MobileAppState extends State<MobileApp> {
|
||||
onPressed: _themeController.toggleTheme,
|
||||
),
|
||||
],
|
||||
floatingActionButton: _currentTabIndex == 0
|
||||
? FloatingActionButton.extended(
|
||||
onPressed: () => _showAddTaskDialog(innerContext),
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Add Task'),
|
||||
tooltip: 'Create a new task',
|
||||
)
|
||||
: null,
|
||||
destinations: const [
|
||||
NavigationDestinationItem(
|
||||
icon: Icon(Icons.dashboard_outlined),
|
||||
selectedIcon: Icon(Icons.dashboard),
|
||||
label: 'Dashboard',
|
||||
icon: Icon(Icons.sports_hockey_outlined),
|
||||
selectedIcon: Icon(Icons.sports_hockey),
|
||||
label: 'Results',
|
||||
),
|
||||
NavigationDestinationItem(
|
||||
icon: Icon(Icons.settings_outlined),
|
||||
@@ -172,7 +82,7 @@ class _MobileAppState extends State<MobileApp> {
|
||||
),
|
||||
],
|
||||
body: _currentTabIndex == 0
|
||||
? DashboardView(viewModel: _dashboardViewModel)
|
||||
? MatchResultsView(viewModel: _matchResultsViewModel)
|
||||
: SettingsView(themeController: _themeController),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
enum CardType { red, yellow, green }
|
||||
|
||||
enum Team { home, away }
|
||||
|
||||
enum GoalType { fieldGoal, shortCorner, penaltyStroke }
|
||||
|
||||
class Card {
|
||||
final String datetime;
|
||||
final int player;
|
||||
final CardType cardType;
|
||||
final int seconds;
|
||||
final Team team;
|
||||
final int duration;
|
||||
|
||||
Card({
|
||||
required this.datetime,
|
||||
required this.player,
|
||||
required this.cardType,
|
||||
required this.seconds,
|
||||
required this.team,
|
||||
required this.duration,
|
||||
});
|
||||
}
|
||||
|
||||
class Goal {
|
||||
final String datetime;
|
||||
final int player;
|
||||
final GoalType goalType;
|
||||
final int seconds;
|
||||
final Team team;
|
||||
|
||||
Goal({
|
||||
required this.datetime,
|
||||
required this.player,
|
||||
required this.goalType,
|
||||
required this.seconds,
|
||||
required this.team,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
class Match {
|
||||
Match({
|
||||
required this.datetime,
|
||||
required this.homeScore,
|
||||
required this.awayScore,
|
||||
required this.goals,
|
||||
required this.cards,
|
||||
});
|
||||
|
||||
final String datetime;
|
||||
final int homeScore;
|
||||
final int awayScore;
|
||||
final List<Goal> goals;
|
||||
final List<Card> cards;
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'datetime': datetime,
|
||||
'homeScore': homeScore,
|
||||
'awayScore': awayScore,
|
||||
'goals': goals.map((goal) => {
|
||||
'datetime': goal.datetime,
|
||||
'player': goal.player,
|
||||
'goal_type': goal.goalType.index,
|
||||
'elapsed': goal.seconds,
|
||||
'team': goal.team.index,
|
||||
}).toList(),
|
||||
'cards': cards.map((card) => {
|
||||
'datetime': card.datetime,
|
||||
'player': card.player,
|
||||
'card_type': card.cardType.index,
|
||||
'elapsed': card.seconds,
|
||||
'team': card.team.index,
|
||||
'duration': card.duration,
|
||||
}).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
factory Match.fromJson(Map<String, dynamic> json) {
|
||||
return Match(
|
||||
datetime: json['datetime'] as String,
|
||||
homeScore: json['homeScore'] as int,
|
||||
awayScore: json['awayScore'] as int,
|
||||
goals: ((json['goals'] as List<dynamic>?) ?? []).map((goalJson) {
|
||||
final goal = goalJson as Map<String, dynamic>;
|
||||
return Goal(
|
||||
datetime: goal['datetime'] as String,
|
||||
player: goal['player'] as int,
|
||||
goalType: _enumValue(
|
||||
GoalType.values,
|
||||
goal['goal_type'] ?? goal['goalType'],
|
||||
GoalType.fieldGoal,
|
||||
),
|
||||
seconds: (goal['elapsed'] ?? goal['seconds'] ?? 0) as int,
|
||||
team: _enumValue(Team.values, goal['team'], Team.home),
|
||||
);
|
||||
}).toList(),
|
||||
cards: ((json['cards'] as List<dynamic>?) ?? []).map((cardJson) {
|
||||
final card = cardJson as Map<String, dynamic>;
|
||||
return Card(
|
||||
datetime: card['datetime'] as String,
|
||||
player: card['player'] as int,
|
||||
cardType: _enumValue(
|
||||
CardType.values,
|
||||
card['card_type'] ?? card['cardType'],
|
||||
CardType.red,
|
||||
),
|
||||
seconds: (card['elapsed'] ?? card['seconds'] ?? 0) as int,
|
||||
team: _enumValue(Team.values, card['team'], Team.home),
|
||||
duration: card['duration'] as int? ?? 0,
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
|
||||
static T _enumValue<T extends Enum>(List<T> values, dynamic value, T fallback) {
|
||||
if (value is int && value >= 0 && value < values.length) {
|
||||
return values[value];
|
||||
}
|
||||
if (value is String) {
|
||||
for (final item in values) {
|
||||
if (item.name == value.split('.').last) return item;
|
||||
}
|
||||
}
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
class TaskItem {
|
||||
const TaskItem({
|
||||
required this.id,
|
||||
required this.title,
|
||||
required this.description,
|
||||
this.isCompleted = false,
|
||||
required this.category,
|
||||
required this.createdAt,
|
||||
});
|
||||
|
||||
final String id;
|
||||
final String title;
|
||||
final String description;
|
||||
final bool isCompleted;
|
||||
final String category;
|
||||
final DateTime createdAt;
|
||||
|
||||
TaskItem copyWith({
|
||||
String? id,
|
||||
String? title,
|
||||
String? description,
|
||||
bool? isCompleted,
|
||||
String? category,
|
||||
DateTime? createdAt,
|
||||
}) {
|
||||
return TaskItem(
|
||||
id: id ?? this.id,
|
||||
title: title ?? this.title,
|
||||
description: description ?? this.description,
|
||||
isCompleted: isCompleted ?? this.isCompleted,
|
||||
category: category ?? this.category,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../../../../data/repositories/task_repository.dart';
|
||||
import '../../../../domain/models/task_item.dart';
|
||||
|
||||
class DashboardViewModel extends ChangeNotifier {
|
||||
DashboardViewModel({required this._repository});
|
||||
|
||||
final TaskRepository _repository;
|
||||
|
||||
List<TaskItem> _tasks = [];
|
||||
bool _isLoading = false;
|
||||
String _selectedCategory = 'All';
|
||||
|
||||
List<TaskItem> get tasks {
|
||||
if (_selectedCategory == 'All') {
|
||||
return List.unmodifiable(_tasks);
|
||||
}
|
||||
return List.unmodifiable(
|
||||
_tasks.where((t) => t.category == _selectedCategory),
|
||||
);
|
||||
}
|
||||
|
||||
bool get isLoading => _isLoading;
|
||||
String get selectedCategory => _selectedCategory;
|
||||
|
||||
int get totalCount => _tasks.length;
|
||||
int get completedCount => _tasks.where((t) => t.isCompleted).length;
|
||||
double get completionProgress =>
|
||||
_tasks.isEmpty ? 0.0 : completedCount / totalCount;
|
||||
|
||||
List<String> get availableCategories => [
|
||||
'All',
|
||||
'Design',
|
||||
'Theme',
|
||||
'A11y',
|
||||
'General',
|
||||
];
|
||||
|
||||
Future<void> loadTasks() async {
|
||||
_isLoading = true;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
_tasks = await _repository.getTasks();
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
void setCategoryFilter(String category) {
|
||||
if (_selectedCategory == category) return;
|
||||
_selectedCategory = category;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> toggleTaskCompletion(TaskItem item) async {
|
||||
await _repository.toggleTaskStatus(item);
|
||||
_tasks = await _repository.getTasks();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> addTask({
|
||||
required String title,
|
||||
required String description,
|
||||
required String category,
|
||||
}) async {
|
||||
await _repository.createTask(
|
||||
title: title,
|
||||
description: description,
|
||||
category: category,
|
||||
);
|
||||
_tasks = await _repository.getTasks();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future<void> deleteTask(String id) async {
|
||||
await _repository.removeTask(id);
|
||||
_tasks = await _repository.getTasks();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import '../../../../data/repositories/match_repository.dart';
|
||||
import '../../../../domain/models/hockey_game.dart';
|
||||
|
||||
class MatchResultsViewModel extends ChangeNotifier {
|
||||
MatchResultsViewModel({required this.repository});
|
||||
|
||||
final MatchRepository repository;
|
||||
List<Match> _matches = [];
|
||||
bool _isLoading = false;
|
||||
String? _errorMessage;
|
||||
|
||||
List<Match> get matches => List.unmodifiable(_matches);
|
||||
bool get isLoading => _isLoading;
|
||||
String? get errorMessage => _errorMessage;
|
||||
|
||||
Future<void> loadMatches() async {
|
||||
_isLoading = true;
|
||||
_errorMessage = null;
|
||||
notifyListeners();
|
||||
|
||||
try {
|
||||
_matches = await repository.loadMatches();
|
||||
} catch (error) {
|
||||
_errorMessage = 'Unable to load match results.';
|
||||
} finally {
|
||||
_isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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',
|
||||
};
|
||||
@@ -57,6 +57,9 @@ flutter:
|
||||
# the material Icons class.
|
||||
uses-material-design: true
|
||||
|
||||
assets:
|
||||
- lib/data/results.json
|
||||
|
||||
# To add assets to your application, add an assets section, like this:
|
||||
# assets:
|
||||
# - images/a_dot_burr.jpeg
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mobile_app/data/repositories/task_repository.dart';
|
||||
import 'package:mobile_app/data/services/mock_task_service.dart';
|
||||
import 'package:mobile_app/ui/features/dashboard/view_models/dashboard_view_model.dart';
|
||||
|
||||
void main() {
|
||||
group('DashboardViewModel', () {
|
||||
late MockTaskService service;
|
||||
late TaskRepository repository;
|
||||
late DashboardViewModel viewModel;
|
||||
|
||||
setUp(() {
|
||||
service = MockTaskService();
|
||||
repository = TaskRepository(service: service);
|
||||
viewModel = DashboardViewModel(repository: repository);
|
||||
});
|
||||
|
||||
test('initial state has empty tasks and not loading', () {
|
||||
expect(viewModel.tasks, isEmpty);
|
||||
expect(viewModel.isLoading, isFalse);
|
||||
expect(viewModel.selectedCategory, 'All');
|
||||
});
|
||||
|
||||
test('loadTasks fetches items from repository', () async {
|
||||
await viewModel.loadTasks();
|
||||
|
||||
expect(viewModel.tasks.isNotEmpty, isTrue);
|
||||
expect(viewModel.isLoading, isFalse);
|
||||
expect(viewModel.totalCount, greaterThan(0));
|
||||
});
|
||||
|
||||
test('toggleTaskCompletion toggles status', () async {
|
||||
await viewModel.loadTasks();
|
||||
final initialItem = viewModel.tasks.first;
|
||||
final initialStatus = initialItem.isCompleted;
|
||||
|
||||
await viewModel.toggleTaskCompletion(initialItem);
|
||||
|
||||
final updatedItem = viewModel.tasks.firstWhere((t) => t.id == initialItem.id);
|
||||
expect(updatedItem.isCompleted, equals(!initialStatus));
|
||||
});
|
||||
|
||||
test('category filter filters task list', () async {
|
||||
await viewModel.loadTasks();
|
||||
viewModel.setCategoryFilter('Design');
|
||||
|
||||
expect(viewModel.selectedCategory, equals('Design'));
|
||||
expect(viewModel.tasks.every((t) => t.category == 'Design'), isTrue);
|
||||
});
|
||||
|
||||
test('addTask adds a new task to list', () async {
|
||||
await viewModel.loadTasks();
|
||||
final countBefore = viewModel.totalCount;
|
||||
|
||||
await viewModel.addTask(
|
||||
title: 'New Unit Test Task',
|
||||
description: 'Verify adding tasks',
|
||||
category: 'A11y',
|
||||
);
|
||||
|
||||
expect(viewModel.totalCount, equals(countBefore + 1));
|
||||
expect(viewModel.tasks.any((t) => t.title == 'New Unit Test Task'), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mobile_app/data/repositories/match_repository.dart';
|
||||
import 'package:mobile_app/ui/features/dashboard/view_models/match_results_view_model.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test('loads match results and their events from bundled JSON', () async {
|
||||
final viewModel = MatchResultsViewModel(repository: MatchRepository());
|
||||
addTearDown(viewModel.dispose);
|
||||
|
||||
await viewModel.loadMatches();
|
||||
|
||||
expect(viewModel.isLoading, isFalse);
|
||||
expect(viewModel.errorMessage, isNull);
|
||||
expect(viewModel.matches, hasLength(3));
|
||||
expect(viewModel.matches.first.homeScore, 1);
|
||||
expect(viewModel.matches.first.goals, hasLength(2));
|
||||
expect(viewModel.matches.first.goals.first.seconds, 88);
|
||||
expect(viewModel.matches.first.goals.first.team.name, 'away');
|
||||
expect(viewModel.matches.first.cards.first.cardType.name, 'red');
|
||||
});
|
||||
}
|
||||
@@ -2,15 +2,14 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mobile_app/app.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('App smoke test - renders dashboard, navigates to settings',
|
||||
testWidgets('App smoke test - renders match results, navigates to settings',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(const MobileApp());
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify Dashboard is visible
|
||||
expect(find.text('Dashboard'), findsWidgets);
|
||||
expect(find.text('Task Progress'), findsOneWidget);
|
||||
expect(find.text('Add Task'), findsOneWidget);
|
||||
expect(find.text('Match Results'), findsOneWidget);
|
||||
expect(find.text('Home'), findsWidgets);
|
||||
expect(find.text('Away'), findsWidgets);
|
||||
|
||||
// Switch to Settings tab
|
||||
final settingsNav = find.text('Settings');
|
||||
@@ -24,10 +23,10 @@ void main() {
|
||||
expect(find.text('Android & iOS (iPhone/iPad)'), findsOneWidget);
|
||||
|
||||
// Switch back to Dashboard
|
||||
final dashboardNav = find.text('Dashboard');
|
||||
await tester.tap(dashboardNav.first);
|
||||
final resultsNav = find.text('Results');
|
||||
await tester.tap(resultsNav.first);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('Task Progress'), findsOneWidget);
|
||||
expect(find.text('Match Results'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user