Compare commits

..
2 Commits
Author SHA1 Message Date
kejaro 1ecbd7b6b1 update 2026-09-27 22:22:16 +01:00
kejaro 212410f716 update 2026-09-27 21:41:56 +01:00
41 changed files with 1168 additions and 187 deletions

No files matched your search

Binary file not shown.

Before

Width:  |  Height:  |  Size: 544 B

After

Width:  |  Height:  |  Size: 2.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 442 B

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 721 B

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

@@ -442,7 +442,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
@@ -500,7 +500,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = AppIcon;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
@@ -1,122 +1 @@
{
"images" : [
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Icon-App-20x20@2x.png",
"scale" : "2x"
},
{
"size" : "20x20",
"idiom" : "iphone",
"filename" : "Icon-App-20x20@3x.png",
"scale" : "3x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@1x.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "iphone",
"filename" : "Icon-App-29x29@3x.png",
"scale" : "3x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon-App-40x40@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "iphone",
"filename" : "Icon-App-40x40@3x.png",
"scale" : "3x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon-App-60x60@2x.png",
"scale" : "2x"
},
{
"size" : "60x60",
"idiom" : "iphone",
"filename" : "Icon-App-60x60@3x.png",
"scale" : "3x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon-App-20x20@1x.png",
"scale" : "1x"
},
{
"size" : "20x20",
"idiom" : "ipad",
"filename" : "Icon-App-20x20@2x.png",
"scale" : "2x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon-App-29x29@1x.png",
"scale" : "1x"
},
{
"size" : "29x29",
"idiom" : "ipad",
"filename" : "Icon-App-29x29@2x.png",
"scale" : "2x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-App-40x40@1x.png",
"scale" : "1x"
},
{
"size" : "40x40",
"idiom" : "ipad",
"filename" : "Icon-App-40x40@2x.png",
"scale" : "2x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-App-76x76@1x.png",
"scale" : "1x"
},
{
"size" : "76x76",
"idiom" : "ipad",
"filename" : "Icon-App-76x76@2x.png",
"scale" : "2x"
},
{
"size" : "83.5x83.5",
"idiom" : "ipad",
"filename" : "Icon-App-83.5x83.5@2x.png",
"scale" : "2x"
},
{
"size" : "1024x1024",
"idiom" : "ios-marketing",
"filename" : "Icon-App-1024x1024@1x.png",
"scale" : "1x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
{"images":[{"size":"20x20","idiom":"iphone","filename":"Icon-App-20x20@2x.png","scale":"2x"},{"size":"20x20","idiom":"iphone","filename":"Icon-App-20x20@3x.png","scale":"3x"},{"size":"29x29","idiom":"iphone","filename":"Icon-App-29x29@1x.png","scale":"1x"},{"size":"29x29","idiom":"iphone","filename":"Icon-App-29x29@2x.png","scale":"2x"},{"size":"29x29","idiom":"iphone","filename":"Icon-App-29x29@3x.png","scale":"3x"},{"size":"40x40","idiom":"iphone","filename":"Icon-App-40x40@2x.png","scale":"2x"},{"size":"40x40","idiom":"iphone","filename":"Icon-App-40x40@3x.png","scale":"3x"},{"size":"57x57","idiom":"iphone","filename":"Icon-App-57x57@1x.png","scale":"1x"},{"size":"57x57","idiom":"iphone","filename":"Icon-App-57x57@2x.png","scale":"2x"},{"size":"60x60","idiom":"iphone","filename":"Icon-App-60x60@2x.png","scale":"2x"},{"size":"60x60","idiom":"iphone","filename":"Icon-App-60x60@3x.png","scale":"3x"},{"size":"20x20","idiom":"ipad","filename":"Icon-App-20x20@1x.png","scale":"1x"},{"size":"20x20","idiom":"ipad","filename":"Icon-App-20x20@2x.png","scale":"2x"},{"size":"29x29","idiom":"ipad","filename":"Icon-App-29x29@1x.png","scale":"1x"},{"size":"29x29","idiom":"ipad","filename":"Icon-App-29x29@2x.png","scale":"2x"},{"size":"40x40","idiom":"ipad","filename":"Icon-App-40x40@1x.png","scale":"1x"},{"size":"40x40","idiom":"ipad","filename":"Icon-App-40x40@2x.png","scale":"2x"},{"size":"50x50","idiom":"ipad","filename":"Icon-App-50x50@1x.png","scale":"1x"},{"size":"50x50","idiom":"ipad","filename":"Icon-App-50x50@2x.png","scale":"2x"},{"size":"72x72","idiom":"ipad","filename":"Icon-App-72x72@1x.png","scale":"1x"},{"size":"72x72","idiom":"ipad","filename":"Icon-App-72x72@2x.png","scale":"2x"},{"size":"76x76","idiom":"ipad","filename":"Icon-App-76x76@1x.png","scale":"1x"},{"size":"76x76","idiom":"ipad","filename":"Icon-App-76x76@2x.png","scale":"2x"},{"size":"83.5x83.5","idiom":"ipad","filename":"Icon-App-83.5x83.5@2x.png","scale":"2x"},{"size":"1024x1024","idiom":"ios-marketing","filename":"Icon-App-1024x1024@1x.png","scale":"1x"}],"info":{"version":1,"author":"xcode"}}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 295 B

After

Width:  |  Height:  |  Size: 749 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 450 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 282 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 462 B

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 704 B

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 406 B

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 586 B

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 862 B

After

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 762 B

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 6.6 KiB

+24 -22
View File
@@ -8,7 +8,9 @@ import 'ui/features/dashboard/views/match_results_view.dart';
import 'ui/features/settings/views/settings_view.dart';
class MobileApp extends StatefulWidget {
const MobileApp({super.key});
const MobileApp({super.key, this.matchRepository});
final MatchRepository? matchRepository;
@override
State<MobileApp> createState() => _MobileAppState();
@@ -17,14 +19,14 @@ class MobileApp extends StatefulWidget {
class _MobileAppState extends State<MobileApp> {
late final ThemeController _themeController;
late final MatchResultsViewModel _matchResultsViewModel;
int _currentTabIndex = 0;
bool _showSettings = false;
@override
void initState() {
super.initState();
_themeController = ThemeController();
_matchResultsViewModel = MatchResultsViewModel(
repository: MatchRepository(),
repository: widget.matchRepository ?? MatchRepository(),
);
_matchResultsViewModel.loadMatches();
}
@@ -49,25 +51,30 @@ class _MobileAppState extends State<MobileApp> {
themeMode: _themeController.themeMode,
home: Builder(
builder: (context) {
final isDarkMode = Theme.of(context).brightness == Brightness.dark;
return ResponsiveScaffold(
selectedIndex: _currentTabIndex,
selectedIndex: 0,
onDestinationSelected: (index) {
setState(() => _currentTabIndex = index);
if (index == 0) {
setState(() => _showSettings = false);
}
},
appBarTitle: Text(
_currentTabIndex == 0 ? 'Match Results' : 'Settings',
_showSettings ? 'Settings' : 'Match Results',
style: const TextStyle(fontWeight: FontWeight.bold),
),
actions: [
IconButton(
icon: Icon(
isDarkMode ? Icons.light_mode : Icons.dark_mode,
if (_showSettings)
IconButton(
icon: const Icon(Icons.arrow_back_rounded),
tooltip: 'Back to results',
onPressed: () => setState(() => _showSettings = false),
)
else
IconButton(
icon: const Icon(Icons.settings_outlined),
tooltip: 'Settings',
onPressed: () => setState(() => _showSettings = true),
),
tooltip: isDarkMode ? 'Switch to light mode' : 'Switch to dark mode',
onPressed: _themeController.toggleTheme,
),
],
destinations: const [
NavigationDestinationItem(
@@ -75,15 +82,10 @@ class _MobileAppState extends State<MobileApp> {
selectedIcon: Icon(Icons.sports_hockey),
label: 'Results',
),
NavigationDestinationItem(
icon: Icon(Icons.settings_outlined),
selectedIcon: Icon(Icons.settings),
label: 'Settings',
),
],
body: _currentTabIndex == 0
? MatchResultsView(viewModel: _matchResultsViewModel)
: SettingsView(themeController: _themeController),
body: _showSettings
? SettingsView(themeController: _themeController)
: MatchResultsView(viewModel: _matchResultsViewModel),
);
},
),
+7
View File
@@ -0,0 +1,7 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
␍<!-- Uploaded to: SVG Repo, www.svgrepo.com, Transformed by: SVG Repo Mixer Tools -->
<svg height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-51.2 -51.2 614.40 614.40" xml:space="preserve" fill="#000000">
␍<g id="SVGRepo_bgCarrier" stroke-width="0"/>
␍<g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"/>
␍<g id="SVGRepo_iconCarrier"> <path style="fill:#51be23;" d="M477.636,176.632H275.3v74.67h-56v-74.67c-62.643,0-115.734,40.856-134.118,97.365 c-7.301-4.213-15.774-6.626-24.811-6.626c-27.45,0-49.702,22.252-49.702,49.703c0,27.449,22.253,49.701,49.702,49.701 c8.906,0,17.266-2.344,24.496-6.449c18.083,57.017,71.43,98.34,134.432,98.34c77.882,0,141.017-63.138,141.017-141.015l-0.017-1.44 l117.336-26.88c12.699-2.907,23.695-10.667,23.695-23.696v-65.304C501.331,187.297,490.67,176.632,477.636,176.632z"/> <g> <path style="fill:#000003;" d="M477.636,165.963H275.3c-5.893,0-10.669,4.779-10.669,10.669v64.002h-34.663v-64.002 c0-5.89-4.776-10.669-10.669-10.669c-61.963,0-116.914,37.203-140.205,93.708c-6.016-1.957-12.338-2.969-18.724-2.969 C27.083,256.702,0,283.785,0,317.074c0,33.288,27.083,60.37,60.371,60.37c6.233,0,12.413-0.967,18.304-2.838 c10.406,25.771,27.594,48.022,50.196,64.831c26.296,19.56,57.567,29.897,90.428,29.897c81.262,0,147.804-64.233,151.523-144.588 l109.194-25.015c19.729-4.517,31.984-17.582,31.984-34.096v-65.304C512,181.381,496.585,165.963,477.636,165.963z M490.663,265.635 c0,8.817-10.775,12.236-15.409,13.299l-117.336,26.878c-4.866,1.115-8.308,5.453-8.286,10.446l0.017,1.394 c0,71.874-58.474,130.346-130.348,130.346c-57.082,0-107.019-36.528-124.263-90.897c-0.973-3.067-3.279-5.533-6.275-6.707 c-1.257-0.492-2.578-0.736-3.894-0.736c-1.825,0-3.642,0.467-5.267,1.392c-5.827,3.307-12.476,5.057-19.228,5.057 c-21.524,0-39.035-17.509-39.035-39.033c0-21.523,17.511-39.035,39.034-39.035c6.851,0,13.586,1.797,19.477,5.197 c2.788,1.611,6.154,1.876,9.156,0.721c3.004-1.152,5.328-3.599,6.324-6.659c16.403-50.423,61.152-85.348,113.303-89.565v63.571 c0,5.89,4.776,10.669,10.669,10.669h56c5.892,0,10.669-4.779,10.669-10.669v-64.002h191.667c7.182,0,13.026,5.845,13.026,13.03 V265.635z"/> <path style="fill:#000003;" d="M219.3,405.332h-0.138c-5.889-0.173-10.799,4.476-10.964,10.365 c-0.166,5.89,4.473,10.8,10.364,10.964c0.249,0.009,0.495,0.009,0.738,0.009c5.892,0,10.669-4.776,10.669-10.669 C229.969,410.111,225.192,405.332,219.3,405.332z"/> <path style="fill:#000003;" d="M192.592,401.167c-36.47-11.665-60.973-45.226-60.973-83.516c0-7.662,1.006-15.297,2.99-22.69 c1.526-5.691-1.85-11.541-7.541-13.069c-5.692-1.526-11.541,1.85-13.069,7.541c-2.467,9.195-3.717,18.692-3.717,28.218 c0,47.607,30.467,89.338,75.812,103.839c1.081,0.346,2.175,0.511,3.252,0.511c4.515,0,8.71-2.89,10.16-7.422 C201.299,408.967,198.204,402.962,192.592,401.167z"/> <path style="fill:#000003;" d="M60.371,306.403c-5.874,0-10.667,4.794-10.667,10.667c0,5.879,4.792,10.669,10.667,10.669 s10.669-4.79,10.669-10.669C71.04,311.198,66.245,306.403,60.371,306.403z"/> <path style="fill:#000003;" d="M247.301,124.235c5.892,0,10.669-4.779,10.669-10.669v-60.23c0-5.89-4.776-10.669-10.669-10.669 c-5.891,0-10.669,4.779-10.669,10.669v60.23C236.633,119.456,241.409,124.235,247.301,124.235z"/> <path style="fill:#000003;" d="M189.619,140.298c2.083,2.081,4.814,3.124,7.543,3.124c2.73,0,5.461-1.042,7.544-3.124 c4.166-4.167,4.166-10.923,0.001-15.089l-43.315-43.317c-4.165-4.163-10.921-4.165-15.088,0 c-4.166,4.167-4.166,10.923-0.001,15.089L189.619,140.298z"/> <path style="fill:#000003;" d="M318.415,122.445c2.73,0,5.46-1.042,7.543-3.124l22.339-22.339c4.165-4.165,4.166-10.921,0-15.089 c-4.167-4.163-10.922-4.165-15.089,0l-22.339,22.34c-4.166,4.165-4.166,10.921-0.001,15.089 C312.953,121.402,315.682,122.445,318.415,122.445z"/> <path style="fill:#000003;" d="M297.44,143.421c2.737,0,5.471-1.046,7.556-3.136l0.177-0.177c4.16-4.174,4.151-10.927-0.023-15.088 c-4.171-4.161-10.927-4.151-15.088,0.022l-0.178,0.177c-4.159,4.174-4.15,10.927,0.023,15.088 C291.989,142.384,294.714,143.421,297.44,143.421z"/> </g> </g>
␍</svg>

After

Width:  |  Height:  |  Size: 4.1 KiB

@@ -1,18 +1,68 @@
import 'dart:convert';
import 'dart:io';
import 'package:flutter/services.dart';
import 'package:path_provider/path_provider.dart';
import '../../domain/models/hockey_game.dart';
class MatchRepository {
MatchRepository({AssetBundle? bundle}) : _bundle = bundle ?? rootBundle;
MatchRepository({
AssetBundle? bundle,
Future<Directory> Function()? documentsDirectoryProvider,
}) : _bundle = bundle ?? rootBundle,
_documentsDirectoryProvider =
documentsDirectoryProvider ?? getApplicationDocumentsDirectory;
final AssetBundle _bundle;
final Future<Directory> Function() _documentsDirectoryProvider;
Future<List<Match>> loadMatches() async {
Future<List<Match>> loadSourceMatches() 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();
}
Future<StoredMatchData> loadStoredData() async {
final file = await _storageFile();
if (!await file.exists()) {
return const StoredMatchData(matches: [], sourceCursor: 0);
}
final data = jsonDecode(await file.readAsString()) as Map<String, dynamic>;
final storedMatches = data['matches'] as List<dynamic>? ?? const [];
final sourceCursor = data['sourceCursor'];
return StoredMatchData(
matches: storedMatches
.map((match) => Match.fromJson(match as Map<String, dynamic>))
.toList(),
sourceCursor: sourceCursor is int && sourceCursor >= 0 ? sourceCursor : 0,
);
}
Future<void> saveStoredData(List<Match> matches, int sourceCursor) async {
final file = await _storageFile();
await file.writeAsString(
jsonEncode({
'sourceCursor': sourceCursor,
'matches': matches.map((match) => match.toJson()).toList(),
}),
flush: true,
);
}
Future<File> _storageFile() async {
final directory = await _documentsDirectoryProvider();
await directory.create(recursive: true);
return File('${directory.path}${Platform.pathSeparator}match-results.json');
}
}
class StoredMatchData {
const StoredMatchData({required this.matches, required this.sourceCursor});
final List<Match> matches;
final int sourceCursor;
}
+720
View File
@@ -37,6 +37,726 @@
"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,
"goal_type": 1,
"elapsed": 88,
"team": 2
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"goal_type": 0,
"elapsed": 32,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 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,
"goal_type": 2,
"team": 1
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"elapsed": 32,
"goal_type": 1,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"elapsed": 66,
"goal_type": 0,
"team": 0
}
]
},
{ "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": 2,
"datetime": "2023-10-01T12:35:00Z",
"duration": 120,
"player": 8,
"elapsed": 235,
"team": 0
}
],
"goals": [
{
"datetime": "2023-10-01T12:15:00Z",
"player": 32,
"goal_type": 1,
"elapsed": 88,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 0,
"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,
"goal_type": 1,
"elapsed": 88,
"team": 2
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"goal_type": 0,
"elapsed": 32,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 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,
"goal_type": 2,
"team": 1
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"elapsed": 32,
"goal_type": 1,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"elapsed": 66,
"goal_type": 0,
"team": 0
}
]
},
{ "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": 2,
"datetime": "2023-10-01T12:35:00Z",
"duration": 120,
"player": 8,
"elapsed": 235,
"team": 0
}
],
"goals": [
{
"datetime": "2023-10-01T12:15:00Z",
"player": 32,
"goal_type": 1,
"elapsed": 88,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 0,
"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,
"goal_type": 1,
"elapsed": 88,
"team": 2
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"goal_type": 0,
"elapsed": 32,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 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,
"goal_type": 2,
"team": 1
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"elapsed": 32,
"goal_type": 1,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"elapsed": 66,
"goal_type": 0,
"team": 0
}
]
},
{ "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": 2,
"datetime": "2023-10-01T12:35:00Z",
"duration": 120,
"player": 8,
"elapsed": 235,
"team": 0
}
],
"goals": [
{
"datetime": "2023-10-01T12:15:00Z",
"player": 32,
"goal_type": 1,
"elapsed": 88,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 0,
"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,
"goal_type": 1,
"elapsed": 88,
"team": 2
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"goal_type": 0,
"elapsed": 32,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 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,
"goal_type": 2,
"team": 1
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"elapsed": 32,
"goal_type": 1,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"elapsed": 66,
"goal_type": 0,
"team": 0
}
]
},
{ "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": 2,
"datetime": "2023-10-01T12:35:00Z",
"duration": 120,
"player": 8,
"elapsed": 235,
"team": 0
}
],
"goals": [
{
"datetime": "2023-10-01T12:15:00Z",
"player": 32,
"goal_type": 1,
"elapsed": 88,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 0,
"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,
"goal_type": 1,
"elapsed": 88,
"team": 2
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"goal_type": 0,
"elapsed": 32,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 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,
"goal_type": 2,
"team": 1
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"elapsed": 32,
"goal_type": 1,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"elapsed": 66,
"goal_type": 0,
"team": 0
}
]
},
{ "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": 2,
"datetime": "2023-10-01T12:35:00Z",
"duration": 120,
"player": 8,
"elapsed": 235,
"team": 0
}
],
"goals": [
{
"datetime": "2023-10-01T12:15:00Z",
"player": 32,
"goal_type": 1,
"elapsed": 88,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 0,
"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,
"goal_type": 1,
"elapsed": 88,
"team": 2
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"goal_type": 0,
"elapsed": 32,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 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,
"goal_type": 2,
"team": 1
},
{
"datetime": "2023-10-01T12:20:00Z",
"player": 32,
"elapsed": 32,
"goal_type": 1,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"elapsed": 66,
"goal_type": 0,
"team": 0
}
]
},
{ "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": 2,
"datetime": "2023-10-01T12:35:00Z",
"duration": 120,
"player": 8,
"elapsed": 235,
"team": 0
}
],
"goals": [
{
"datetime": "2023-10-01T12:15:00Z",
"player": 32,
"goal_type": 1,
"elapsed": 88,
"team": 1
},
{
"datetime": "2023-10-01T12:30:00Z",
"player": 2,
"goal_type": 0,
"elapsed": 66,
"team": 0
}
]
},
{ "datetime": "2023-11-01T12:00:00Z",
"awayScore": 0,
@@ -0,0 +1,111 @@
import 'dart:async';
import '../../domain/models/hockey_game.dart';
import '../repositories/match_repository.dart';
class MatchDataService {
MatchDataService({
required this.repository,
this.updateInterval = const Duration(seconds: 1),
}) : assert(updateInterval > Duration.zero);
final MatchRepository repository;
final Duration updateInterval;
Timer? _timer;
List<Match> _matches = [];
List<Match> _sourceMatches = [];
int _sourceCursor = 0;
bool _isStarted = false;
bool _isDelivering = false;
bool _isDisposed = false;
Future<void> _writeQueue = Future<void>.value();
void Function(List<Match>)? _onMatchesChanged;
void Function(Object)? _onError;
Future<void> start({
required void Function(List<Match>) onMatchesChanged,
required void Function(Object) onError,
}) async {
if (_isStarted) return;
_isStarted = true;
_onMatchesChanged = onMatchesChanged;
_onError = onError;
final storedData = await repository.loadStoredData();
_matches = List.of(storedData.matches);
_sourceCursor = storedData.sourceCursor;
_notifyMatchesChanged();
_sourceMatches = await repository.loadSourceMatches();
await _deliverNextMatch();
if (_sourceCursor < _sourceMatches.length && !_isDisposed) {
_timer = Timer.periodic(updateInterval, (_) {
unawaited(_deliverNextMatch().catchError(_handleError));
});
}
}
Future<void> removeMatch(Match match) async {
final matchIndex = _matches.indexWhere(
(candidate) => identical(candidate, match),
);
if (matchIndex == -1) return;
final updatedMatches = List<Match>.of(_matches)..removeAt(matchIndex);
_matches = updatedMatches;
_notifyMatchesChanged();
await _persist(updatedMatches, _sourceCursor);
}
Future<void> _deliverNextMatch() async {
if (_isDisposed || _isDelivering || _sourceCursor >= _sourceMatches.length) {
_timer?.cancel();
_timer = null;
return;
}
_isDelivering = true;
try {
final updatedMatches = [..._matches, _sourceMatches[_sourceCursor]];
final nextCursor = _sourceCursor + 1;
await _persist(updatedMatches, nextCursor);
if (_isDisposed) return;
_matches = updatedMatches;
_sourceCursor = nextCursor;
_notifyMatchesChanged();
if (_sourceCursor >= _sourceMatches.length) {
_timer?.cancel();
_timer = null;
}
} finally {
_isDelivering = false;
}
}
Future<void> _persist(List<Match> matches, int sourceCursor) {
final previousWrite = _writeQueue.catchError((Object _) {});
final nextWrite = previousWrite.then(
(_) => repository.saveStoredData(matches, sourceCursor),
);
_writeQueue = nextWrite;
return nextWrite;
}
void _notifyMatchesChanged() {
_onMatchesChanged?.call(List.unmodifiable(_matches));
}
void _handleError(Object error) {
_onError?.call(error);
}
void dispose() {
_isDisposed = true;
_timer?.cancel();
_timer = null;
}
}
@@ -86,17 +86,19 @@ class ResponsiveScaffold extends StatelessWidget {
child: body,
),
),
bottomNavigationBar: NavigationBar(
selectedIndex: selectedIndex,
onDestinationSelected: onDestinationSelected,
destinations: destinations.map((d) {
return NavigationDestination(
icon: d.icon,
selectedIcon: d.selectedIcon,
label: d.label,
);
}).toList(),
),
bottomNavigationBar: destinations.length >= 2
? NavigationBar(
selectedIndex: selectedIndex,
onDestinationSelected: onDestinationSelected,
destinations: destinations.map((d) {
return NavigationDestination(
icon: d.icon,
selectedIcon: d.selectedIcon,
label: d.label,
);
}).toList(),
)
: null,
floatingActionButton: floatingActionButton,
);
},
@@ -1,11 +1,20 @@
import 'package:flutter/foundation.dart';
import 'dart:async';
import '../../../../data/repositories/match_repository.dart';
import '../../../../data/services/match_data_service.dart';
import '../../../../domain/models/hockey_game.dart';
class MatchResultsViewModel extends ChangeNotifier {
MatchResultsViewModel({required this.repository});
MatchResultsViewModel({
required MatchRepository repository,
Duration updateInterval = const Duration(seconds: 1),
}) : _dataService = MatchDataService(
repository: repository,
updateInterval: updateInterval,
);
final MatchRepository repository;
final MatchDataService _dataService;
List<Match> _matches = [];
bool _isLoading = false;
String? _errorMessage;
@@ -14,13 +23,31 @@ class MatchResultsViewModel extends ChangeNotifier {
bool get isLoading => _isLoading;
String? get errorMessage => _errorMessage;
Future<void> removeMatch(Match match) async {
try {
await _dataService.removeMatch(match);
} catch (_) {
_errorMessage = 'Unable to save match results.';
notifyListeners();
}
}
Future<void> loadMatches() async {
_isLoading = true;
_errorMessage = null;
notifyListeners();
try {
_matches = await repository.loadMatches();
await _dataService.start(
onMatchesChanged: (matches) {
_matches = matches;
notifyListeners();
},
onError: (_) {
_errorMessage = 'Unable to save match results.';
notifyListeners();
},
);
} catch (error) {
_errorMessage = 'Unable to load match results.';
} finally {
@@ -28,4 +55,10 @@ class MatchResultsViewModel extends ChangeNotifier {
notifyListeners();
}
}
@override
void dispose() {
_dataService.dispose();
super.dispose();
}
}
@@ -16,21 +16,47 @@ class MatchResultsView extends StatelessWidget {
return ListenableBuilder(
listenable: viewModel,
builder: (context, _) {
final matches = viewModel.matches;
if (viewModel.isLoading) {
return const Center(child: CircularProgressIndicator());
}
if (viewModel.errorMessage != null) {
return Center(child: Text(viewModel.errorMessage!));
}
if (viewModel.matches.isEmpty) {
if (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]),
itemCount: matches.length,
findChildIndexCallback: (key) {
if (key is! ValueKey<Match>) return null;
final index = matches.indexWhere(
(match) => identical(match, key.value),
);
return index == -1 ? null : index;
},
itemBuilder: (context, index) {
final match = matches[index];
return Dismissible(
key: ValueKey(match),
direction: DismissDirection.endToStart,
background: Container(
alignment: Alignment.centerRight,
padding: const EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.circular(12),
),
child: const Icon(Icons.delete_outline, color: Colors.white),
),
onDismissed: (_) => viewModel.removeMatch(match),
child: _MatchCard(match: match),
);
},
);
},
);
@@ -54,10 +80,7 @@ class _MatchCardState extends State<_MatchCard> {
final match = widget.match;
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')} ${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}';
final dateLabel = _exportDate(match.datetime);
return Card(
margin: const EdgeInsets.only(bottom: 12),
@@ -245,7 +268,7 @@ String _teamName(Team team) => team == Team.home ? 'Home' : 'Away';
String _matchShareText(Match match) {
final buffer = StringBuffer()
..writeln('Match result')
..writeln(match.datetime)
..writeln(_exportDate(match.datetime))
..writeln('Home ${match.homeScore} - ${match.awayScore} Away');
if (match.goals.isNotEmpty) {
@@ -277,6 +300,33 @@ String _formatTime(int seconds) {
return '$minute:$second';
}
String _exportDate(String rawDateTime) {
final parsed = DateTime.tryParse(rawDateTime)?.toLocal();
if (parsed == null) {
return rawDateTime;
}
final weekday = _weekdayName(parsed.weekday);
final day = parsed.day.toString().padLeft(2, '0');
final month = parsed.month.toString().padLeft(2, '0');
final year = parsed.year.toString().substring(2);
final hour = parsed.hour.toString().padLeft(2, '0');
final minute = parsed.minute.toString().padLeft(2, '0');
return '$weekday $day-$month-$year $hour:$minute';
}
String _weekdayName(int weekday) => switch (weekday) {
DateTime.monday => 'Mon',
DateTime.tuesday => 'Tue',
DateTime.wednesday => 'Wed',
DateTime.thursday => 'Thu',
DateTime.friday => 'Fri',
DateTime.saturday => 'Sat',
DateTime.sunday => 'Sun',
_ => 'Unknown',
};
String _goalTypeName(GoalType type) => switch (type) {
GoalType.fieldGoal => 'Field goal',
GoalType.shortCorner => 'Short corner',
+57 -1
View File
@@ -1,6 +1,14 @@
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
sha256: "6c5bcd986e06b94e3c40244af471750840a3d2341d1f9763a1100a14add517b4"
url: "https://pub.dev"
source: hosted
version: "4.3.0"
args:
dependency: transitive
description:
@@ -33,6 +41,22 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.4.1"
checked_yaml:
dependency: transitive
description:
name: checked_yaml
sha256: "959525d3162f249993882720d52b7e0c833978df229be20702b33d48d91de70f"
url: "https://pub.dev"
source: hosted
version: "2.0.4"
cli_util:
dependency: transitive
description:
name: cli_util
sha256: ff6785f7e9e3c38ac98b2fb035701789de90154024a75b6cb926445e83197d1c
url: "https://pub.dev"
source: hosted
version: "0.4.2"
clock:
dependency: transitive
description:
@@ -118,6 +142,14 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_launcher_icons:
dependency: "direct dev"
description:
name: flutter_launcher_icons
sha256: "10f13781741a2e3972126fae08393d3c4e01fa4cd7473326b94b72cf594195e7"
url: "https://pub.dev"
source: hosted
version: "0.14.4"
flutter_lints:
dependency: "direct dev"
description:
@@ -168,6 +200,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.1.2"
image:
dependency: transitive
description:
name: image
sha256: a1e7f4951e538a568e14b856702afc9ae1d2f4b202daced8d22c1b9cd211ce89
url: "https://pub.dev"
source: hosted
version: "4.10.1"
jni:
dependency: transitive
description:
@@ -192,6 +232,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.0.0"
json_annotation:
dependency: transitive
description:
name: json_annotation
sha256: "2a743920d81b7910627f68ee2c9ac1fc0bfee32b9fc3403587d7c6791ca12f80"
url: "https://pub.dev"
source: hosted
version: "4.12.0"
leak_tracker:
dependency: transitive
description:
@@ -297,7 +345,7 @@ packages:
source: hosted
version: "1.1.0"
path_provider:
dependency: transitive
dependency: "direct main"
description:
name: path_provider
sha256: a7f4874f987173da295a61c181b8ee71dab59b332a486b391babf26a1b884825
@@ -368,6 +416,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.1.8"
posix:
dependency: transitive
description:
name: posix
sha256: bc1bad54ad2b735816e31f8d4600cfde6c7839975085ddfbca48b6c9f7c4044e
url: "https://pub.dev"
source: hosted
version: "6.5.2"
pub_semver:
dependency: transitive
description:
+9
View File
@@ -32,6 +32,7 @@ dependencies:
sdk: flutter
flutter_svg: ^2.1.0
path_provider: ^2.1.6
share_plus: ^11.0.0
# The following adds the Cupertino Icons font to your application.
@@ -48,6 +49,7 @@ dev_dependencies:
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
flutter_lints: ^6.0.0
flutter_launcher_icons: ^0.14.4
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
@@ -64,6 +66,13 @@ flutter:
- lib/data/results.json
- lib/data/icons/
flutter_icons:
android: true
ios: true
image_path: "assets/icon.png"
min_sdk_android: 21
remove_alpha_ios: true
# To add assets to your application, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
@@ -1,3 +1,5 @@
import 'dart:io';
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';
@@ -6,18 +8,58 @@ void main() {
TestWidgetsFlutterBinding.ensureInitialized();
test('loads match results and their events from bundled JSON', () async {
final viewModel = MatchResultsViewModel(repository: MatchRepository());
final matches = await MatchRepository().loadSourceMatches();
expect(matches, hasLength(21));
expect(matches.first.homeScore, 1);
expect(matches.first.goals, hasLength(2));
expect(matches.first.goals.first.seconds, 88);
expect(matches.first.goals.first.team.name, 'away');
expect(matches.first.cards.first.cardType.name, 'red');
});
test('simulates periodic receipt and persists received matches', () async {
final directory = await Directory.systemTemp.createTemp('match-results-');
addTearDown(() => directory.delete(recursive: true));
final repository = MatchRepository(
documentsDirectoryProvider: () async => directory,
);
final viewModel = MatchResultsViewModel(
repository: repository,
updateInterval: const Duration(milliseconds: 10),
);
addTearDown(viewModel.dispose);
await viewModel.loadMatches();
expect(viewModel.matches, hasLength(1));
await Future<void>.delayed(const Duration(milliseconds: 30));
expect(viewModel.matches.length, greaterThan(1));
final storedData = await repository.loadStoredData();
expect(storedData.matches, hasLength(viewModel.matches.length));
expect(storedData.sourceCursor, viewModel.matches.length);
});
test('resumes simulation from the persisted source cursor', () async {
final directory = await Directory.systemTemp.createTemp('match-results-');
addTearDown(() => directory.delete(recursive: true));
final repository = MatchRepository(
documentsDirectoryProvider: () async => directory,
);
final sourceMatches = await repository.loadSourceMatches();
await repository.saveStoredData([sourceMatches.first], 1);
final viewModel = MatchResultsViewModel(
repository: repository,
updateInterval: const Duration(hours: 1),
);
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');
expect(viewModel.matches, hasLength(2));
expect(viewModel.matches.first.datetime, sourceMatches.first.datetime);
expect(viewModel.matches.last.datetime, sourceMatches[1].datetime);
expect((await repository.loadStoredData()).sourceCursor, 2);
});
}
+26 -6
View File
@@ -1,30 +1,41 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mobile_app/app.dart';
import 'package:mobile_app/data/repositories/match_repository.dart';
void main() {
testWidgets('App smoke test - renders match results, navigates to settings', (
WidgetTester tester,
) async {
await tester.pumpWidget(const MobileApp());
final directory = await Directory.systemTemp.createTemp('match-results-');
addTearDown(() => directory.delete(recursive: true));
await tester.pumpWidget(
MobileApp(
matchRepository: MatchRepository(
documentsDirectoryProvider: () async => directory,
),
),
);
await tester.pumpAndSettle();
expect(find.text('Match Results'), findsOneWidget);
expect(find.text('Home'), findsWidgets);
expect(find.text('Away'), findsWidgets);
expect(
find.textContaining(RegExp(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}')),
find.textContaining(RegExp(r'[A-Z][a-z]{2} \d{2}-\d{2}-\d{2} \d{2}:\d{2}')),
findsWidgets,
);
expect(find.text('Field goal · Away · #32'), findsNothing);
expect(find.byType(ExpansionTile), findsWidgets);
await tester.tap(
find.textContaining(RegExp(r'\d{4}-\d{2}-\d{2} \d{2}:\d{2}')).first,
find.textContaining(RegExp(r'[A-Z][a-z]{2} \d{2}-\d{2}-\d{2} \d{2}:\d{2}')).first,
);
await tester.pumpAndSettle();
expect(find.text('Field goal · Away · #32'), findsWidgets);
expect(find.textContaining('card · Away · #5 · 120s'), findsWidgets);
expect(find.text('Field goal'), findsWidgets);
expect(find.text('Away'), findsWidgets);
expect(find.byType(Divider), findsNothing);
final matchTile = tester.widget<ExpansionTile>(
find.byType(ExpansionTile).first,
@@ -49,5 +60,14 @@ void main() {
await tester.pumpAndSettle();
expect(find.text('Match Results'), findsOneWidget);
final firstMatchFinder = find.byType(Dismissible).first;
final firstMatch = tester.widget<Dismissible>(firstMatchFinder);
final firstMatchKey = firstMatch.key;
await tester.fling(firstMatchFinder, const Offset(-600, 0), 1000);
await tester.pumpAndSettle();
expect(find.byKey(firstMatchKey!), findsNothing);
});
}