Compare commits
220 Commits
enhancemen
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f0379e97c7 | |||
| c2394c3733 | |||
| 88766652b9 | |||
| 2a1573ee2d | |||
| cfb07bfe28 | |||
| d741990f2f | |||
| 76121eb4fb | |||
| d5ee6449b0 | |||
| 7d9757abb6 | |||
| d94d51c6ea | |||
|
|
803cf8a972 | ||
|
|
13be75a65b | ||
| aef12bd65a | |||
| 02d79574dd | |||
| fdd0e7579a | |||
| cd2770be26 | |||
| e196d6e5ef | |||
| bc3beac866 | |||
| aa936a938d | |||
| 2811ea892e | |||
| 4b1d3923a0 | |||
| 0f824bb30a | |||
| 21c74b74bc | |||
| 6e45e9435b | |||
| a78614851b | |||
| 8df9a27dc7 | |||
| 52180eeb6d | |||
| 0893667e41 | |||
| 1dc5286c6b | |||
|
|
f140ebae2e | ||
| a487e4071f | |||
|
|
99044c0ea0 | ||
| 69effa2b7d | |||
| 5db008c274 | |||
| feaa0709a7 | |||
|
|
2fea3597fe | ||
|
|
7b2314a25e | ||
|
|
7f6c1cb9a6 | ||
| dcfed75a93 | |||
| 7fa434782c | |||
| bdcee85eb9 | |||
| 072dba1cde | |||
| 3c7c4598ff | |||
| 1a20d7b64c | |||
| ec94e12ed7 | |||
| 9fc308554c | |||
| 42cef337aa | |||
|
|
d9980edf0e | ||
|
|
4c084cae4a | ||
|
|
cecfd5da4e | ||
| 5289660327 | |||
| 16e1f542f5 | |||
| e4ae526d93 | |||
| 2f65316a51 | |||
| 31abb7f1e4 | |||
| 132966f3d2 | |||
| 77095725de | |||
| d081a597db | |||
| bdc3453d7f | |||
| 678ab90af3 | |||
| a038c22ba6 | |||
| 22fcff73bd | |||
|
|
4a67dae456 | ||
| 3c22b084d6 | |||
| 7f923f6dff | |||
| 87856e6548 | |||
| cb7804cf55 | |||
| 304fa82a93 | |||
| f84a645e61 | |||
| b0073addf8 | |||
| b5c17ac5a9 | |||
| 4451f9e2a9 | |||
| 1d4fdae84b | |||
| 60862de4c4 | |||
| 6899bb0c3c | |||
| 55a22b292f | |||
| db30b0fd5a | |||
| 5ee0d59377 | |||
| f22595e678 | |||
| 25fe10eb9a | |||
| 5a318f9760 | |||
| 0051990168 | |||
| 7e21c65026 | |||
| cc23c03f6b | |||
| d77b5f20f9 | |||
| 3c3bf506cb | |||
| 8afba5680b | |||
| 7103765054 | |||
| bc01a6de9a | |||
| ad87dca674 | |||
| 633a21d829 | |||
| 81f63c1c07 | |||
| fc6c74b377 | |||
| 15d09f381a | |||
| f97c341b81 | |||
| 7bf03ec388 | |||
| 0bfaba4225 | |||
| bbb7914fc5 | |||
| 86dbc9afb0 | |||
| 73aea0d0f5 | |||
| ed9e3af768 | |||
| d93ead40b6 | |||
| 3374a80c27 | |||
| 534d19efc3 | |||
| d9a26a8cf7 | |||
| 8e05e9d61b | |||
| 179ac2fe21 | |||
| 2b78617924 | |||
| 175a9cb349 | |||
| 18f0626e95 | |||
| d99a04549a | |||
| cc1ecc4c86 | |||
| 16cdf9db3e | |||
| da494ed146 | |||
| af0242c44f | |||
| cd63f5cf06 | |||
| 8c3282b954 | |||
| 1c0fb9f3ab | |||
| bfca41bd36 | |||
| 92b8ef0877 | |||
| 5428064c53 | |||
| 27916456db | |||
| 58fe38fd72 | |||
| ecd03dfd9d | |||
| 05c6625bf3 | |||
| 9821af39fe | |||
| c1789458e0 | |||
| e19f696714 | |||
| 9cb35dc4a1 | |||
| b8b65c4ca1 | |||
| 356cb1fb43 | |||
| 4c8896d2d9 | |||
| 31c8598222 | |||
| 884680d329 | |||
| 5ae569f2e7 | |||
| 37d6ad81fd | |||
| cea6c36407 | |||
| 1b300faea9 | |||
| dac5cc8a89 | |||
| bafbde7d03 | |||
| fdea594a1e | |||
| 856ce43c49 | |||
| 5c8b93072f | |||
| 94fdd7026d | |||
| 966f7caa54 | |||
| 88bea48956 | |||
| a2e66b9c80 | |||
| d7a006dd87 | |||
| 12856342a8 | |||
| b0a5145490 | |||
| 7a80c1a792 | |||
| c73f37507f | |||
| 1e730cebe6 | |||
| 7eb25221d7 | |||
| f9722bc762 | |||
| f2917a6813 | |||
| b29cd6dff4 | |||
| 1d92084da6 | |||
| 7732c6ceb9 | |||
| a747d91c5d | |||
| 06a9c0cd84 | |||
| 9ad5c4ad6f | |||
| 9b3d61e5b0 | |||
| df0a5207c2 | |||
| 4f0a1eec6d | |||
| 24b60bb18b | |||
| c8532adfde | |||
| 76186787e7 | |||
| f05114a99e | |||
| d96494f608 | |||
| 0eaf3d251b | |||
| 0567fce02b | |||
| 74ea540b39 | |||
| d578a7f9bd | |||
| 0e5ad1c3d9 | |||
| c4b249b199 | |||
| 99cea1e703 | |||
| 7b7c41b96c | |||
| d0059b44a8 | |||
| 3b3d298ff5 | |||
| e1626225ac | |||
| 93ced81e7e | |||
| 23cdddfbd9 | |||
| 5d2fed74ac | |||
| 0d0806dfbb | |||
| 27ff599a88 | |||
| c4094a547e | |||
| 701500c7e2 | |||
| 062c2681bf | |||
| 7cff48ebc0 | |||
| 708157df54 | |||
| f1f3fd7b6e | |||
| 7bc75d60a7 | |||
| a1ed17355a | |||
| 45abc79f95 | |||
| c214a26c54 | |||
| 6c0cb92e56 | |||
| b4ba4f8d74 | |||
| f60c11fc08 | |||
| d2d0a82c9b | |||
| 1044ee9bea | |||
| 32e812127d | |||
| 4500d85f78 | |||
| c8bf03f462 | |||
| 7ecccb13c2 | |||
| 4fc1959704 | |||
| 1e03507f75 | |||
| e37a98fdcc | |||
| 6ae0471fa2 | |||
| a1a995777b | |||
| 3d12f0c160 | |||
| 10aad47124 | |||
| 75b62d0854 | |||
| 527f163346 | |||
| 6ae7166d34 | |||
| b4ccb567b5 | |||
| bcd7bf751b | |||
| 4dbc106e38 | |||
| 236a737fd1 | |||
| 94b113eb95 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -195,3 +195,4 @@ app.*.map.json
|
|||||||
/android/app/debug
|
/android/app/debug
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
/devtools_options.yaml
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
|
android:screenOrientation="portrait"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
android:taskAffinity=""
|
android:taskAffinity=""
|
||||||
android:theme="@style/LaunchTheme"
|
android:theme="@style/LaunchTheme"
|
||||||
|
|||||||
@@ -2,178 +2,103 @@
|
|||||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"games": {
|
"players": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": [
|
"items": {
|
||||||
{
|
"type": "object",
|
||||||
"type": "object",
|
"properties": {
|
||||||
"properties": {
|
"id": {
|
||||||
"id": {
|
"type": "string"
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"players": {
|
|
||||||
"type": [
|
|
||||||
"array",
|
|
||||||
"null"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"id",
|
|
||||||
"createdAt",
|
|
||||||
"name"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"group": {
|
"createdAt": {
|
||||||
"type": [
|
"type": "string"
|
||||||
"object",
|
|
||||||
"null"
|
|
||||||
],
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"members": {
|
|
||||||
"type": "array",
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"id",
|
|
||||||
"createdAt",
|
|
||||||
"name"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"id",
|
|
||||||
"createdAt",
|
|
||||||
"name",
|
|
||||||
"members"
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
"winner": {
|
"name": {
|
||||||
"type": ["object","null"]
|
"type": "string"
|
||||||
},
|
}
|
||||||
"required": [
|
},
|
||||||
"id",
|
"required": [
|
||||||
"createdAt",
|
"id",
|
||||||
"name"
|
"createdAt",
|
||||||
]
|
"name"
|
||||||
}
|
]
|
||||||
]
|
}
|
||||||
},
|
},
|
||||||
"groups": {
|
"groups": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": [
|
"items": {
|
||||||
{
|
"type": "object",
|
||||||
"type": "object",
|
"properties": {
|
||||||
"properties": {
|
"id": {
|
||||||
"id": {
|
"type": "string"
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"members": {
|
|
||||||
"type": "array",
|
|
||||||
"items": [
|
|
||||||
{
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"createdAt": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"name": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"required": [
|
|
||||||
"id",
|
|
||||||
"createdAt",
|
|
||||||
"name"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"required": [
|
"name": {
|
||||||
"id",
|
"type": "string"
|
||||||
"createdAt",
|
},
|
||||||
"name",
|
"createdAt": {
|
||||||
"members"
|
"type": "string"
|
||||||
]
|
},
|
||||||
}
|
"memberIds": {
|
||||||
]
|
"type": "array",
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"createdAt",
|
||||||
|
"memberIds"
|
||||||
|
]
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"players": {
|
"matches": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"items": [
|
"items": {
|
||||||
{
|
"type": "object",
|
||||||
"type": [
|
"properties": {
|
||||||
"object",
|
"id": {
|
||||||
"null"
|
"type": "string"
|
||||||
],
|
},
|
||||||
"properties": {
|
"name": {
|
||||||
"id": {
|
"type": "string"
|
||||||
"type": "string"
|
},
|
||||||
},
|
"createdAt": {
|
||||||
"createdAt": {
|
"type": "string"
|
||||||
"type": "string"
|
},
|
||||||
},
|
"groupId": {
|
||||||
"name": {
|
"anyOf": [
|
||||||
|
{"type": "string"},
|
||||||
|
{"type": "null"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"playerIds": {
|
||||||
|
"type": "array",
|
||||||
|
"items": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"winnerId": {
|
||||||
"id",
|
"anyOf": [
|
||||||
"createdAt",
|
{"type": "string"},
|
||||||
"name"
|
{"type": "null"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
},
|
||||||
|
"required": [
|
||||||
|
"id",
|
||||||
|
"name",
|
||||||
|
"createdAt",
|
||||||
|
"groupId",
|
||||||
|
"playerIds"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
"required": [
|
||||||
|
"players",
|
||||||
|
"groups",
|
||||||
|
"matches"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -31,8 +31,6 @@
|
|||||||
<key>UISupportedInterfaceOrientations</key>
|
<key>UISupportedInterfaceOrientations</key>
|
||||||
<array>
|
<array>
|
||||||
<string>UIInterfaceOrientationPortrait</string>
|
<string>UIInterfaceOrientationPortrait</string>
|
||||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
|
||||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
|
||||||
</array>
|
</array>
|
||||||
<key>UISupportedInterfaceOrientations~ipad</key>
|
<key>UISupportedInterfaceOrientations~ipad</key>
|
||||||
<array>
|
<array>
|
||||||
|
|||||||
5
l10n.yaml
Normal file
5
l10n.yaml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
arb-dir: lib/l10n/arb
|
||||||
|
template-arb-file: app_en.arb
|
||||||
|
output-localization-file: app_localizations.dart
|
||||||
|
output-dir: lib/l10n/generated
|
||||||
|
nullable-getter: false
|
||||||
6
lib/core/constants.dart
Normal file
6
lib/core/constants.dart
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
class Constants {
|
||||||
|
Constants._(); // Private constructor to prevent instantiation
|
||||||
|
|
||||||
|
/// Minimum duration of all app skeletons
|
||||||
|
static Duration minimumSkeletonDuration = const Duration(milliseconds: 250);
|
||||||
|
}
|
||||||
@@ -1,35 +1,59 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class CustomTheme {
|
class CustomTheme {
|
||||||
|
CustomTheme._(); // Private constructor to prevent instantiation
|
||||||
|
|
||||||
|
// ==================== Colors ====================
|
||||||
static Color primaryColor = const Color(0xFF7505E4);
|
static Color primaryColor = const Color(0xFF7505E4);
|
||||||
static Color secondaryColor = const Color(0xFFAFA2FF);
|
static Color secondaryColor = const Color(0xFFAFA2FF);
|
||||||
static Color backgroundColor = const Color(0xFF0B0B0B);
|
static Color backgroundColor = const Color(0xFF0B0B0B);
|
||||||
static Color boxColor = const Color(0xFF101010);
|
static Color boxColor = const Color(0xFF101010);
|
||||||
static Color onBoxColor = const Color(0xFF181818);
|
static Color onBoxColor = const Color(0xFF181818);
|
||||||
static Color boxBorder = const Color(0xFF272727);
|
static Color boxBorder = const Color(0xFF272727);
|
||||||
|
static const Color textColor = Colors.white;
|
||||||
|
|
||||||
|
// ==================== Border Radius ====================
|
||||||
|
static const double standardBorderRadius = 12.0;
|
||||||
|
static BorderRadius get standardBorderRadiusAll =>
|
||||||
|
BorderRadius.circular(standardBorderRadius);
|
||||||
|
|
||||||
|
// ==================== Padding & Margins ====================
|
||||||
|
static const EdgeInsets standardMargin = EdgeInsets.symmetric(
|
||||||
|
horizontal: 12,
|
||||||
|
vertical: 10,
|
||||||
|
);
|
||||||
|
static const EdgeInsets tileMargin = EdgeInsets.symmetric(
|
||||||
|
horizontal: 12,
|
||||||
|
vertical: 5,
|
||||||
|
);
|
||||||
|
|
||||||
|
// ==================== Decorations ====================
|
||||||
static BoxDecoration standardBoxDecoration = BoxDecoration(
|
static BoxDecoration standardBoxDecoration = BoxDecoration(
|
||||||
color: boxColor,
|
color: boxColor,
|
||||||
border: Border.all(color: boxBorder),
|
border: Border.all(color: boxBorder),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: standardBorderRadiusAll,
|
||||||
);
|
);
|
||||||
|
|
||||||
static BoxDecoration highlightedBoxDecoration = BoxDecoration(
|
static BoxDecoration highlightedBoxDecoration = BoxDecoration(
|
||||||
color: boxColor,
|
color: boxColor,
|
||||||
border: Border.all(color: primaryColor),
|
border: Border.all(color: primaryColor),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: standardBorderRadiusAll,
|
||||||
boxShadow: [BoxShadow(color: primaryColor.withAlpha(120), blurRadius: 12)],
|
boxShadow: [BoxShadow(color: primaryColor.withAlpha(120), blurRadius: 12)],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// ==================== App Bar Theme ====================
|
||||||
static AppBarTheme appBarTheme = AppBarTheme(
|
static AppBarTheme appBarTheme = AppBarTheme(
|
||||||
backgroundColor: backgroundColor,
|
backgroundColor: backgroundColor,
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: textColor,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
|
scrolledUnderElevation: 0,
|
||||||
|
centerTitle: true,
|
||||||
titleTextStyle: const TextStyle(
|
titleTextStyle: const TextStyle(
|
||||||
color: Colors.white,
|
color: textColor,
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
iconTheme: const IconThemeData(color: Colors.white),
|
iconTheme: const IconThemeData(color: textColor),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
|
|
||||||
/// Button types used for styling the [CustomWidthButton]
|
/// Button types used for styling the [CustomWidthButton]
|
||||||
|
/// - [ButtonType.primary]: Primary button style.
|
||||||
|
/// - [ButtonType.secondary]: Secondary button style.
|
||||||
|
/// - [ButtonType.tertiary]: Tertiary button style.
|
||||||
enum ButtonType { primary, secondary, tertiary }
|
enum ButtonType { primary, secondary, tertiary }
|
||||||
|
|
||||||
/// Result types for import operations in the [SettingsView]
|
/// Result types for import operations in the [SettingsView]
|
||||||
@@ -23,9 +29,24 @@ enum ImportResult {
|
|||||||
/// - [ExportResult.unknownException]: An exception occurred during export.
|
/// - [ExportResult.unknownException]: An exception occurred during export.
|
||||||
enum ExportResult { success, canceled, unknownException }
|
enum ExportResult { success, canceled, unknownException }
|
||||||
|
|
||||||
/// Different rulesets available for games
|
/// Different rulesets available for matches
|
||||||
/// - [Ruleset.singleWinner]: The game is won by a single player
|
/// - [Ruleset.singleWinner]: The match is won by a single player
|
||||||
/// - [Ruleset.singleLoser]: The game is lost by a single player
|
/// - [Ruleset.singleLoser]: The match is lost by a single player
|
||||||
/// - [Ruleset.mostPoints]: The player with the most points wins.
|
/// - [Ruleset.mostPoints]: The player with the most points wins.
|
||||||
/// - [Ruleset.lastPoints]: The player with the fewest points wins.
|
/// - [Ruleset.leastPoints]: The player with the fewest points wins.
|
||||||
enum Ruleset { singleWinner, singleLoser, mostPoints, lastPoints }
|
enum Ruleset { singleWinner, singleLoser, mostPoints, leastPoints }
|
||||||
|
|
||||||
|
/// Translates a [Ruleset] enum value to its corresponding localized string.
|
||||||
|
String translateRulesetToString(Ruleset ruleset, BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
switch (ruleset) {
|
||||||
|
case Ruleset.singleWinner:
|
||||||
|
return loc.single_winner;
|
||||||
|
case Ruleset.singleLoser:
|
||||||
|
return loc.single_loser;
|
||||||
|
case Ruleset.mostPoints:
|
||||||
|
return loc.most_points;
|
||||||
|
case Ruleset.leastPoints:
|
||||||
|
return loc.least_points;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,320 +0,0 @@
|
|||||||
import 'package:drift/drift.dart';
|
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
|
||||||
import 'package:game_tracker/data/db/tables/game_table.dart';
|
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
|
||||||
|
|
||||||
part 'game_dao.g.dart';
|
|
||||||
|
|
||||||
@DriftAccessor(tables: [GameTable])
|
|
||||||
class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
|
||||||
GameDao(super.db);
|
|
||||||
|
|
||||||
/// Retrieves all games from the database.
|
|
||||||
Future<List<Game>> getAllGames() async {
|
|
||||||
final query = select(gameTable);
|
|
||||||
final result = await query.get();
|
|
||||||
|
|
||||||
return Future.wait(
|
|
||||||
result.map((row) async {
|
|
||||||
final group = await db.groupGameDao.getGroupOfGame(gameId: row.id);
|
|
||||||
final players = await db.playerGameDao.getPlayersOfGame(gameId: row.id);
|
|
||||||
final winner = row.winnerId != null
|
|
||||||
? await db.playerDao.getPlayerById(playerId: row.winnerId!)
|
|
||||||
: null;
|
|
||||||
return Game(
|
|
||||||
id: row.id,
|
|
||||||
name: row.name,
|
|
||||||
group: group,
|
|
||||||
players: players,
|
|
||||||
createdAt: row.createdAt,
|
|
||||||
winner: winner,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieves a [Game] by its [gameId].
|
|
||||||
Future<Game> getGameById({required String gameId}) async {
|
|
||||||
final query = select(gameTable)..where((g) => g.id.equals(gameId));
|
|
||||||
final result = await query.getSingle();
|
|
||||||
|
|
||||||
List<Player>? players;
|
|
||||||
if (await db.playerGameDao.gameHasPlayers(gameId: gameId)) {
|
|
||||||
players = await db.playerGameDao.getPlayersOfGame(gameId: gameId);
|
|
||||||
}
|
|
||||||
Group? group;
|
|
||||||
if (await db.groupGameDao.gameHasGroup(gameId: gameId)) {
|
|
||||||
group = await db.groupGameDao.getGroupOfGame(gameId: gameId);
|
|
||||||
}
|
|
||||||
Player? winner;
|
|
||||||
if (result.winnerId != null) {
|
|
||||||
winner = await db.playerDao.getPlayerById(playerId: result.winnerId!);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Game(
|
|
||||||
id: result.id,
|
|
||||||
name: result.name,
|
|
||||||
players: players,
|
|
||||||
group: group,
|
|
||||||
winner: winner,
|
|
||||||
createdAt: result.createdAt,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Adds a new [Game] to the database.
|
|
||||||
/// Also adds associated players and group if they exist.
|
|
||||||
Future<void> addGame({required Game game}) async {
|
|
||||||
await db.transaction(() async {
|
|
||||||
await into(gameTable).insert(
|
|
||||||
GameTableCompanion.insert(
|
|
||||||
id: game.id,
|
|
||||||
name: game.name,
|
|
||||||
winnerId: Value(game.winner?.id),
|
|
||||||
createdAt: game.createdAt,
|
|
||||||
),
|
|
||||||
mode: InsertMode.insertOrReplace,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (game.players != null) {
|
|
||||||
await db.playerDao.addPlayersAsList(players: game.players!);
|
|
||||||
for (final p in game.players ?? []) {
|
|
||||||
await db.playerGameDao.addPlayerToGame(
|
|
||||||
gameId: game.id,
|
|
||||||
playerId: p.id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (game.group != null) {
|
|
||||||
await db.groupDao.addGroup(group: game.group!);
|
|
||||||
await db.groupGameDao.addGroupToGame(
|
|
||||||
gameId: game.id,
|
|
||||||
groupId: game.group!.id,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Adds multiple [Game]s to the database in a batch operation.
|
|
||||||
/// Also adds associated players and groups if they exist.
|
|
||||||
/// If the [games] list is empty, the method returns immediately.
|
|
||||||
Future<void> addGamesAsList({required List<Game> games}) async {
|
|
||||||
if (games.isEmpty) return;
|
|
||||||
await db.transaction(() async {
|
|
||||||
// Add all games in batch
|
|
||||||
await db.batch(
|
|
||||||
(b) => b.insertAll(
|
|
||||||
gameTable,
|
|
||||||
games
|
|
||||||
.map(
|
|
||||||
(game) => GameTableCompanion.insert(
|
|
||||||
id: game.id,
|
|
||||||
name: game.name,
|
|
||||||
createdAt: game.createdAt,
|
|
||||||
winnerId: Value(game.winner?.id),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
mode: InsertMode.insertOrReplace,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add all groups of the games in batch
|
|
||||||
await db.batch(
|
|
||||||
(b) => b.insertAll(
|
|
||||||
db.groupTable,
|
|
||||||
games
|
|
||||||
.where((game) => game.group != null)
|
|
||||||
.map(
|
|
||||||
(game) => GroupTableCompanion.insert(
|
|
||||||
id: game.group!.id,
|
|
||||||
name: game.group!.name,
|
|
||||||
createdAt: game.group!.createdAt,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
mode: InsertMode.insertOrReplace,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add all players of the games in batch (unique)
|
|
||||||
final uniquePlayers = <String, Player>{};
|
|
||||||
for (final game in games) {
|
|
||||||
if (game.players != null) {
|
|
||||||
for (final p in game.players!) {
|
|
||||||
uniquePlayers[p.id] = p;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Also include members of groups
|
|
||||||
if (game.group != null) {
|
|
||||||
for (final m in game.group!.members) {
|
|
||||||
uniquePlayers[m.id] = m;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uniquePlayers.isNotEmpty) {
|
|
||||||
await db.batch(
|
|
||||||
(b) => b.insertAll(
|
|
||||||
db.playerTable,
|
|
||||||
uniquePlayers.values
|
|
||||||
.map(
|
|
||||||
(p) => PlayerTableCompanion.insert(
|
|
||||||
id: p.id,
|
|
||||||
name: p.name,
|
|
||||||
createdAt: p.createdAt,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
mode: InsertMode.insertOrReplace,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add all player-game associations in batch
|
|
||||||
await db.batch((b) {
|
|
||||||
for (final game in games) {
|
|
||||||
if (game.players != null) {
|
|
||||||
for (final p in game.players ?? []) {
|
|
||||||
b.insert(
|
|
||||||
db.playerGameTable,
|
|
||||||
PlayerGameTableCompanion.insert(
|
|
||||||
gameId: game.id,
|
|
||||||
playerId: p.id,
|
|
||||||
),
|
|
||||||
mode: InsertMode.insertOrReplace,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add all player-group associations in batch
|
|
||||||
await db.batch((b) {
|
|
||||||
for (final game in games) {
|
|
||||||
if (game.group != null) {
|
|
||||||
for (final m in game.group!.members) {
|
|
||||||
b.insert(
|
|
||||||
db.playerGroupTable,
|
|
||||||
PlayerGroupTableCompanion.insert(
|
|
||||||
playerId: m.id,
|
|
||||||
groupId: game.group!.id,
|
|
||||||
),
|
|
||||||
mode: InsertMode.insertOrReplace,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add all group-game associations in batch
|
|
||||||
await db.batch((b) {
|
|
||||||
for (final game in games) {
|
|
||||||
if (game.group != null) {
|
|
||||||
b.insert(
|
|
||||||
db.groupGameTable,
|
|
||||||
GroupGameTableCompanion.insert(
|
|
||||||
gameId: game.id,
|
|
||||||
groupId: game.group!.id,
|
|
||||||
),
|
|
||||||
mode: InsertMode.insertOrReplace,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deletes the game with the given [gameId] from the database.
|
|
||||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
|
||||||
Future<bool> deleteGame({required String gameId}) async {
|
|
||||||
final query = delete(gameTable)..where((g) => g.id.equals(gameId));
|
|
||||||
final rowsAffected = await query.go();
|
|
||||||
return rowsAffected > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieves the number of games in the database.
|
|
||||||
Future<int> getGameCount() async {
|
|
||||||
final count =
|
|
||||||
await (selectOnly(gameTable)..addColumns([gameTable.id.count()]))
|
|
||||||
.map((row) => row.read(gameTable.id.count()))
|
|
||||||
.getSingle();
|
|
||||||
return count ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a game with the given [gameId] exists in the database.
|
|
||||||
/// Returns `true` if the game exists, otherwise `false`.
|
|
||||||
Future<bool> gameExists({required String gameId}) async {
|
|
||||||
final query = select(gameTable)..where((g) => g.id.equals(gameId));
|
|
||||||
final result = await query.getSingleOrNull();
|
|
||||||
return result != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Deletes all games from the database.
|
|
||||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
|
||||||
Future<bool> deleteAllGames() async {
|
|
||||||
final query = delete(gameTable);
|
|
||||||
final rowsAffected = await query.go();
|
|
||||||
return rowsAffected > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Sets the winner of the game with the given [gameId] to the player with
|
|
||||||
/// the given [winnerId].
|
|
||||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
|
||||||
Future<bool> setWinner({
|
|
||||||
required String gameId,
|
|
||||||
required String winnerId,
|
|
||||||
}) async {
|
|
||||||
final query = update(gameTable)..where((g) => g.id.equals(gameId));
|
|
||||||
final rowsAffected = await query.write(
|
|
||||||
GameTableCompanion(winnerId: Value(winnerId)),
|
|
||||||
);
|
|
||||||
return rowsAffected > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieves the winner of the game with the given [gameId].
|
|
||||||
/// Returns the [Player] who won the game, or `null` if no winner is set.
|
|
||||||
Future<Player?> getWinner({required String gameId}) async {
|
|
||||||
final query = select(gameTable)..where((g) => g.id.equals(gameId));
|
|
||||||
final result = await query.getSingleOrNull();
|
|
||||||
if (result == null || result.winnerId == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final winner = await db.playerDao.getPlayerById(playerId: result.winnerId!);
|
|
||||||
return winner;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Removes the winner of the game with the given [gameId].
|
|
||||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
|
||||||
Future<bool> removeWinner({required String gameId}) async {
|
|
||||||
final query = update(gameTable)..where((g) => g.id.equals(gameId));
|
|
||||||
final rowsAffected = await query.write(
|
|
||||||
const GameTableCompanion(winnerId: Value(null)),
|
|
||||||
);
|
|
||||||
return rowsAffected > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if the game with the given [gameId] has a winner set.
|
|
||||||
/// Returns `true` if a winner is set, otherwise `false`.
|
|
||||||
Future<bool> hasWinner({required String gameId}) async {
|
|
||||||
final query = select(gameTable)
|
|
||||||
..where((g) => g.id.equals(gameId) & g.winnerId.isNotNull());
|
|
||||||
final result = await query.getSingleOrNull();
|
|
||||||
return result != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Changes the title of the game with the given [gameId] to [newName].
|
|
||||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
|
||||||
Future<bool> updateGameName({
|
|
||||||
required String gameId,
|
|
||||||
required String newName,
|
|
||||||
}) async {
|
|
||||||
final query = update(gameTable)..where((g) => g.id.equals(gameId));
|
|
||||||
final rowsAffected = await query.write(
|
|
||||||
GameTableCompanion(name: Value(newName)),
|
|
||||||
);
|
|
||||||
return rowsAffected > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'game_dao.dart';
|
|
||||||
|
|
||||||
// ignore_for_file: type=lint
|
|
||||||
mixin _$GameDaoMixin on DatabaseAccessor<AppDatabase> {
|
|
||||||
$GameTableTable get gameTable => attachedDatabase.gameTable;
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/db/tables/group_table.dart';
|
import 'package:game_tracker/data/db/tables/group_table.dart';
|
||||||
|
import 'package:game_tracker/data/db/tables/player_group_table.dart';
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
|
||||||
part 'group_dao.g.dart';
|
part 'group_dao.g.dart';
|
||||||
|
|
||||||
@DriftAccessor(tables: [GroupTable])
|
@DriftAccessor(tables: [GroupTable, PlayerGroupTable])
|
||||||
class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||||
GroupDao(super.db);
|
GroupDao(super.db);
|
||||||
|
|
||||||
@@ -94,6 +95,8 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Insert unique groups in batch
|
// Insert unique groups in batch
|
||||||
|
// Using insertOrIgnore to avoid triggering cascade deletes on
|
||||||
|
// player_group associations when groups already exist
|
||||||
await db.batch(
|
await db.batch(
|
||||||
(b) => b.insertAll(
|
(b) => b.insertAll(
|
||||||
groupTable,
|
groupTable,
|
||||||
@@ -106,7 +109,7 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
mode: InsertMode.insertOrReplace,
|
mode: InsertMode.insertOrIgnore,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -119,6 +122,8 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (uniquePlayers.isNotEmpty) {
|
if (uniquePlayers.isNotEmpty) {
|
||||||
|
// Using insertOrIgnore to avoid triggering cascade deletes on
|
||||||
|
// player_group associations when players already exist
|
||||||
await db.batch(
|
await db.batch(
|
||||||
(b) => b.insertAll(
|
(b) => b.insertAll(
|
||||||
db.playerTable,
|
db.playerTable,
|
||||||
@@ -131,7 +136,7 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
mode: InsertMode.insertOrReplace,
|
mode: InsertMode.insertOrIgnore,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,4 +5,7 @@ part of 'group_dao.dart';
|
|||||||
// ignore_for_file: type=lint
|
// ignore_for_file: type=lint
|
||||||
mixin _$GroupDaoMixin on DatabaseAccessor<AppDatabase> {
|
mixin _$GroupDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||||
$GroupTableTable get groupTable => attachedDatabase.groupTable;
|
$GroupTableTable get groupTable => attachedDatabase.groupTable;
|
||||||
|
$PlayerTableTable get playerTable => attachedDatabase.playerTable;
|
||||||
|
$PlayerGroupTableTable get playerGroupTable =>
|
||||||
|
attachedDatabase.playerGroupTable;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,98 +0,0 @@
|
|||||||
import 'package:drift/drift.dart';
|
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
|
||||||
import 'package:game_tracker/data/db/tables/group_game_table.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
|
||||||
|
|
||||||
part 'group_game_dao.g.dart';
|
|
||||||
|
|
||||||
@DriftAccessor(tables: [GroupGameTable])
|
|
||||||
class GroupGameDao extends DatabaseAccessor<AppDatabase>
|
|
||||||
with _$GroupGameDaoMixin {
|
|
||||||
GroupGameDao(super.db);
|
|
||||||
|
|
||||||
/// Associates a group with a game by inserting a record into the
|
|
||||||
/// [GroupGameTable].
|
|
||||||
Future<void> addGroupToGame({
|
|
||||||
required String gameId,
|
|
||||||
required String groupId,
|
|
||||||
}) async {
|
|
||||||
if (await gameHasGroup(gameId: gameId)) {
|
|
||||||
throw Exception('Game already has a group');
|
|
||||||
}
|
|
||||||
await into(groupGameTable).insert(
|
|
||||||
GroupGameTableCompanion.insert(groupId: groupId, gameId: gameId),
|
|
||||||
mode: InsertMode.insertOrReplace,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieves the [Group] associated with the given [gameId].
|
|
||||||
/// Returns `null` if no group is found.
|
|
||||||
Future<Group?> getGroupOfGame({required String gameId}) async {
|
|
||||||
final result = await (select(
|
|
||||||
groupGameTable,
|
|
||||||
)..where((g) => g.gameId.equals(gameId))).getSingleOrNull();
|
|
||||||
|
|
||||||
if (result == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
final group = await db.groupDao.getGroupById(groupId: result.groupId);
|
|
||||||
return group;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if there is a group associated with the given [gameId].
|
|
||||||
/// Returns `true` if there is a group, otherwise `false`.
|
|
||||||
Future<bool> gameHasGroup({required String gameId}) async {
|
|
||||||
final count =
|
|
||||||
await (selectOnly(groupGameTable)
|
|
||||||
..where(groupGameTable.gameId.equals(gameId))
|
|
||||||
..addColumns([groupGameTable.groupId.count()]))
|
|
||||||
.map((row) => row.read(groupGameTable.groupId.count()))
|
|
||||||
.getSingle();
|
|
||||||
return (count ?? 0) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a specific group is associated with a specific game.
|
|
||||||
/// Returns `true` if the group is in the game, otherwise `false`.
|
|
||||||
Future<bool> isGroupInGame({
|
|
||||||
required String gameId,
|
|
||||||
required String groupId,
|
|
||||||
}) async {
|
|
||||||
final count =
|
|
||||||
await (selectOnly(groupGameTable)
|
|
||||||
..where(
|
|
||||||
groupGameTable.gameId.equals(gameId) &
|
|
||||||
groupGameTable.groupId.equals(groupId),
|
|
||||||
)
|
|
||||||
..addColumns([groupGameTable.groupId.count()]))
|
|
||||||
.map((row) => row.read(groupGameTable.groupId.count()))
|
|
||||||
.getSingle();
|
|
||||||
return (count ?? 0) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Removes the association of a group from a game based on [groupId] and
|
|
||||||
/// [gameId].
|
|
||||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
|
||||||
Future<bool> removeGroupFromGame({
|
|
||||||
required String gameId,
|
|
||||||
required String groupId,
|
|
||||||
}) async {
|
|
||||||
final query = delete(groupGameTable)
|
|
||||||
..where((g) => g.gameId.equals(gameId) & g.groupId.equals(groupId));
|
|
||||||
final rowsAffected = await query.go();
|
|
||||||
return rowsAffected > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Updates the group associated with a game to [newGroupId] based on
|
|
||||||
/// [gameId].
|
|
||||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
|
||||||
Future<bool> updateGroupOfGame({
|
|
||||||
required String gameId,
|
|
||||||
required String newGroupId,
|
|
||||||
}) async {
|
|
||||||
final updatedRows =
|
|
||||||
await (update(groupGameTable)..where((g) => g.gameId.equals(gameId)))
|
|
||||||
.write(GroupGameTableCompanion(groupId: Value(newGroupId)));
|
|
||||||
return updatedRows > 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'group_game_dao.dart';
|
|
||||||
|
|
||||||
// ignore_for_file: type=lint
|
|
||||||
mixin _$GroupGameDaoMixin on DatabaseAccessor<AppDatabase> {
|
|
||||||
$GroupTableTable get groupTable => attachedDatabase.groupTable;
|
|
||||||
$GameTableTable get gameTable => attachedDatabase.gameTable;
|
|
||||||
$GroupGameTableTable get groupGameTable => attachedDatabase.groupGameTable;
|
|
||||||
}
|
|
||||||
98
lib/data/dao/group_match_dao.dart
Normal file
98
lib/data/dao/group_match_dao.dart
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
import 'package:drift/drift.dart';
|
||||||
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
|
import 'package:game_tracker/data/db/tables/group_match_table.dart';
|
||||||
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
|
||||||
|
part 'group_match_dao.g.dart';
|
||||||
|
|
||||||
|
@DriftAccessor(tables: [GroupMatchTable])
|
||||||
|
class GroupMatchDao extends DatabaseAccessor<AppDatabase>
|
||||||
|
with _$GroupMatchDaoMixin {
|
||||||
|
GroupMatchDao(super.db);
|
||||||
|
|
||||||
|
/// Associates a group with a match by inserting a record into the
|
||||||
|
/// [GroupMatchTable].
|
||||||
|
Future<void> addGroupToMatch({
|
||||||
|
required String matchId,
|
||||||
|
required String groupId,
|
||||||
|
}) async {
|
||||||
|
if (await matchHasGroup(matchId: matchId)) {
|
||||||
|
throw Exception('Match already has a group');
|
||||||
|
}
|
||||||
|
await into(groupMatchTable).insert(
|
||||||
|
GroupMatchTableCompanion.insert(groupId: groupId, matchId: matchId),
|
||||||
|
mode: InsertMode.insertOrIgnore,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieves the [Group] associated with the given [matchId].
|
||||||
|
/// Returns `null` if no group is found.
|
||||||
|
Future<Group?> getGroupOfMatch({required String matchId}) async {
|
||||||
|
final result = await (select(
|
||||||
|
groupMatchTable,
|
||||||
|
)..where((g) => g.matchId.equals(matchId))).getSingleOrNull();
|
||||||
|
|
||||||
|
if (result == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
final group = await db.groupDao.getGroupById(groupId: result.groupId);
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks if there is a group associated with the given [matchId].
|
||||||
|
/// Returns `true` if there is a group, otherwise `false`.
|
||||||
|
Future<bool> matchHasGroup({required String matchId}) async {
|
||||||
|
final count =
|
||||||
|
await (selectOnly(groupMatchTable)
|
||||||
|
..where(groupMatchTable.matchId.equals(matchId))
|
||||||
|
..addColumns([groupMatchTable.groupId.count()]))
|
||||||
|
.map((row) => row.read(groupMatchTable.groupId.count()))
|
||||||
|
.getSingle();
|
||||||
|
return (count ?? 0) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks if a specific group is associated with a specific match.
|
||||||
|
/// Returns `true` if the group is in the match, otherwise `false`.
|
||||||
|
Future<bool> isGroupInMatch({
|
||||||
|
required String matchId,
|
||||||
|
required String groupId,
|
||||||
|
}) async {
|
||||||
|
final count =
|
||||||
|
await (selectOnly(groupMatchTable)
|
||||||
|
..where(
|
||||||
|
groupMatchTable.matchId.equals(matchId) &
|
||||||
|
groupMatchTable.groupId.equals(groupId),
|
||||||
|
)
|
||||||
|
..addColumns([groupMatchTable.groupId.count()]))
|
||||||
|
.map((row) => row.read(groupMatchTable.groupId.count()))
|
||||||
|
.getSingle();
|
||||||
|
return (count ?? 0) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the association of a group from a match based on [groupId] and
|
||||||
|
/// [matchId].
|
||||||
|
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||||
|
Future<bool> removeGroupFromMatch({
|
||||||
|
required String matchId,
|
||||||
|
required String groupId,
|
||||||
|
}) async {
|
||||||
|
final query = delete(groupMatchTable)
|
||||||
|
..where((g) => g.matchId.equals(matchId) & g.groupId.equals(groupId));
|
||||||
|
final rowsAffected = await query.go();
|
||||||
|
return rowsAffected > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Updates the group associated with a match to [newGroupId] based on
|
||||||
|
/// [matchId].
|
||||||
|
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||||
|
Future<bool> updateGroupOfMatch({
|
||||||
|
required String matchId,
|
||||||
|
required String newGroupId,
|
||||||
|
}) async {
|
||||||
|
final updatedRows =
|
||||||
|
await (update(groupMatchTable)..where((g) => g.matchId.equals(matchId)))
|
||||||
|
.write(GroupMatchTableCompanion(groupId: Value(newGroupId)));
|
||||||
|
return updatedRows > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
10
lib/data/dao/group_match_dao.g.dart
Normal file
10
lib/data/dao/group_match_dao.g.dart
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'group_match_dao.dart';
|
||||||
|
|
||||||
|
// ignore_for_file: type=lint
|
||||||
|
mixin _$GroupMatchDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||||
|
$GroupTableTable get groupTable => attachedDatabase.groupTable;
|
||||||
|
$MatchTableTable get matchTable => attachedDatabase.matchTable;
|
||||||
|
$GroupMatchTableTable get groupMatchTable => attachedDatabase.groupMatchTable;
|
||||||
|
}
|
||||||
326
lib/data/dao/match_dao.dart
Normal file
326
lib/data/dao/match_dao.dart
Normal file
@@ -0,0 +1,326 @@
|
|||||||
|
import 'package:drift/drift.dart';
|
||||||
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
|
import 'package:game_tracker/data/db/tables/match_table.dart';
|
||||||
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
|
||||||
|
part 'match_dao.g.dart';
|
||||||
|
|
||||||
|
@DriftAccessor(tables: [MatchTable])
|
||||||
|
class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||||
|
MatchDao(super.db);
|
||||||
|
|
||||||
|
/// Retrieves all matches from the database.
|
||||||
|
Future<List<Match>> getAllMatches() async {
|
||||||
|
final query = select(matchTable);
|
||||||
|
final result = await query.get();
|
||||||
|
|
||||||
|
return Future.wait(
|
||||||
|
result.map((row) async {
|
||||||
|
final group = await db.groupMatchDao.getGroupOfMatch(matchId: row.id);
|
||||||
|
final players = await db.playerMatchDao.getPlayersOfMatch(
|
||||||
|
matchId: row.id,
|
||||||
|
);
|
||||||
|
final winner = row.winnerId != null
|
||||||
|
? await db.playerDao.getPlayerById(playerId: row.winnerId!)
|
||||||
|
: null;
|
||||||
|
return Match(
|
||||||
|
id: row.id,
|
||||||
|
name: row.name,
|
||||||
|
group: group,
|
||||||
|
players: players,
|
||||||
|
createdAt: row.createdAt,
|
||||||
|
winner: winner,
|
||||||
|
);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieves a [Match] by its [matchId].
|
||||||
|
Future<Match> getMatchById({required String matchId}) async {
|
||||||
|
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
||||||
|
final result = await query.getSingle();
|
||||||
|
|
||||||
|
List<Player>? players;
|
||||||
|
if (await db.playerMatchDao.matchHasPlayers(matchId: matchId)) {
|
||||||
|
players = await db.playerMatchDao.getPlayersOfMatch(matchId: matchId);
|
||||||
|
}
|
||||||
|
Group? group;
|
||||||
|
if (await db.groupMatchDao.matchHasGroup(matchId: matchId)) {
|
||||||
|
group = await db.groupMatchDao.getGroupOfMatch(matchId: matchId);
|
||||||
|
}
|
||||||
|
Player? winner;
|
||||||
|
if (result.winnerId != null) {
|
||||||
|
winner = await db.playerDao.getPlayerById(playerId: result.winnerId!);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Match(
|
||||||
|
id: result.id,
|
||||||
|
name: result.name,
|
||||||
|
players: players,
|
||||||
|
group: group,
|
||||||
|
winner: winner,
|
||||||
|
createdAt: result.createdAt,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds a new [Match] to the database. Also adds players and group
|
||||||
|
/// associations. This method assumes that the players and groups added to
|
||||||
|
/// this match are already present in the database.
|
||||||
|
Future<void> addMatch({required Match match}) async {
|
||||||
|
await db.transaction(() async {
|
||||||
|
await into(matchTable).insert(
|
||||||
|
MatchTableCompanion.insert(
|
||||||
|
id: match.id,
|
||||||
|
name: match.name,
|
||||||
|
winnerId: Value(match.winner?.id),
|
||||||
|
createdAt: match.createdAt,
|
||||||
|
),
|
||||||
|
mode: InsertMode.insertOrReplace,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (match.players != null) {
|
||||||
|
for (final p in match.players ?? []) {
|
||||||
|
await db.playerMatchDao.addPlayerToMatch(
|
||||||
|
matchId: match.id,
|
||||||
|
playerId: p.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (match.group != null) {
|
||||||
|
await db.groupMatchDao.addGroupToMatch(
|
||||||
|
matchId: match.id,
|
||||||
|
groupId: match.group!.id,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Adds multiple [Match]s to the database in a batch operation.
|
||||||
|
/// Also adds associated players and groups if they exist.
|
||||||
|
/// If the [matches] list is empty, the method returns immediately.
|
||||||
|
/// This Method should only be used to import matches from a different device.
|
||||||
|
Future<void> addMatchAsList({required List<Match> matches}) async {
|
||||||
|
if (matches.isEmpty) return;
|
||||||
|
await db.transaction(() async {
|
||||||
|
// Add all matches in batch
|
||||||
|
await db.batch(
|
||||||
|
(b) => b.insertAll(
|
||||||
|
matchTable,
|
||||||
|
matches
|
||||||
|
.map(
|
||||||
|
(match) => MatchTableCompanion.insert(
|
||||||
|
id: match.id,
|
||||||
|
name: match.name,
|
||||||
|
createdAt: match.createdAt,
|
||||||
|
winnerId: Value(match.winner?.id),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
mode: InsertMode.insertOrReplace,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add all groups of the matches in batch
|
||||||
|
// Using insertOrIgnore to avoid overwriting existing groups (which would
|
||||||
|
// trigger cascade deletes on player_group associations)
|
||||||
|
await db.batch(
|
||||||
|
(b) => b.insertAll(
|
||||||
|
db.groupTable,
|
||||||
|
matches
|
||||||
|
.where((match) => match.group != null)
|
||||||
|
.map(
|
||||||
|
(matches) => GroupTableCompanion.insert(
|
||||||
|
id: matches.group!.id,
|
||||||
|
name: matches.group!.name,
|
||||||
|
createdAt: matches.group!.createdAt,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
mode: InsertMode.insertOrIgnore,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add all players of the matches in batch (unique)
|
||||||
|
final uniquePlayers = <String, Player>{};
|
||||||
|
for (final match in matches) {
|
||||||
|
if (match.players != null) {
|
||||||
|
for (final p in match.players!) {
|
||||||
|
uniquePlayers[p.id] = p;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Also include members of groups
|
||||||
|
if (match.group != null) {
|
||||||
|
for (final m in match.group!.members) {
|
||||||
|
uniquePlayers[m.id] = m;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (uniquePlayers.isNotEmpty) {
|
||||||
|
// Using insertOrIgnore to avoid triggering cascade deletes on
|
||||||
|
// player_group/player_match associations when players already exist
|
||||||
|
await db.batch(
|
||||||
|
(b) => b.insertAll(
|
||||||
|
db.playerTable,
|
||||||
|
uniquePlayers.values
|
||||||
|
.map(
|
||||||
|
(p) => PlayerTableCompanion.insert(
|
||||||
|
id: p.id,
|
||||||
|
name: p.name,
|
||||||
|
createdAt: p.createdAt,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList(),
|
||||||
|
mode: InsertMode.insertOrIgnore,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add all player-match associations in batch
|
||||||
|
await db.batch((b) {
|
||||||
|
for (final match in matches) {
|
||||||
|
if (match.players != null) {
|
||||||
|
for (final p in match.players ?? []) {
|
||||||
|
b.insert(
|
||||||
|
db.playerMatchTable,
|
||||||
|
PlayerMatchTableCompanion.insert(
|
||||||
|
matchId: match.id,
|
||||||
|
playerId: p.id,
|
||||||
|
),
|
||||||
|
mode: InsertMode.insertOrIgnore,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add all player-group associations in batch
|
||||||
|
await db.batch((b) {
|
||||||
|
for (final match in matches) {
|
||||||
|
if (match.group != null) {
|
||||||
|
for (final m in match.group!.members) {
|
||||||
|
b.insert(
|
||||||
|
db.playerGroupTable,
|
||||||
|
PlayerGroupTableCompanion.insert(
|
||||||
|
playerId: m.id,
|
||||||
|
groupId: match.group!.id,
|
||||||
|
),
|
||||||
|
mode: InsertMode.insertOrIgnore,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add all group-match associations in batch
|
||||||
|
await db.batch((b) {
|
||||||
|
for (final match in matches) {
|
||||||
|
if (match.group != null) {
|
||||||
|
b.insert(
|
||||||
|
db.groupMatchTable,
|
||||||
|
GroupMatchTableCompanion.insert(
|
||||||
|
matchId: match.id,
|
||||||
|
groupId: match.group!.id,
|
||||||
|
),
|
||||||
|
mode: InsertMode.insertOrIgnore,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deletes the match with the given [matchId] from the database.
|
||||||
|
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||||
|
Future<bool> deleteMatch({required String matchId}) async {
|
||||||
|
final query = delete(matchTable)..where((g) => g.id.equals(matchId));
|
||||||
|
final rowsAffected = await query.go();
|
||||||
|
return rowsAffected > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieves the number of matches in the database.
|
||||||
|
Future<int> getMatchCount() async {
|
||||||
|
final count =
|
||||||
|
await (selectOnly(matchTable)..addColumns([matchTable.id.count()]))
|
||||||
|
.map((row) => row.read(matchTable.id.count()))
|
||||||
|
.getSingle();
|
||||||
|
return count ?? 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks if a match with the given [matchId] exists in the database.
|
||||||
|
/// Returns `true` if the match exists, otherwise `false`.
|
||||||
|
Future<bool> matchExists({required String matchId}) async {
|
||||||
|
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
||||||
|
final result = await query.getSingleOrNull();
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Deletes all matches from the database.
|
||||||
|
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||||
|
Future<bool> deleteAllMatches() async {
|
||||||
|
final query = delete(matchTable);
|
||||||
|
final rowsAffected = await query.go();
|
||||||
|
return rowsAffected > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sets the winner of the match with the given [matchId] to the player with
|
||||||
|
/// the given [winnerId].
|
||||||
|
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||||
|
Future<bool> setWinner({
|
||||||
|
required String matchId,
|
||||||
|
required String winnerId,
|
||||||
|
}) async {
|
||||||
|
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||||
|
final rowsAffected = await query.write(
|
||||||
|
MatchTableCompanion(winnerId: Value(winnerId)),
|
||||||
|
);
|
||||||
|
return rowsAffected > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieves the winner of the match with the given [matchId].
|
||||||
|
/// Returns the [Player] who won the match, or `null` if no winner is set.
|
||||||
|
Future<Player?> getWinner({required String matchId}) async {
|
||||||
|
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
||||||
|
final result = await query.getSingleOrNull();
|
||||||
|
if (result == null || result.winnerId == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
final winner = await db.playerDao.getPlayerById(playerId: result.winnerId!);
|
||||||
|
return winner;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the winner of the match with the given [matchId].
|
||||||
|
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||||
|
Future<bool> removeWinner({required String matchId}) async {
|
||||||
|
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||||
|
final rowsAffected = await query.write(
|
||||||
|
const MatchTableCompanion(winnerId: Value(null)),
|
||||||
|
);
|
||||||
|
return rowsAffected > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks if the match with the given [matchId] has a winner set.
|
||||||
|
/// Returns `true` if a winner is set, otherwise `false`.
|
||||||
|
Future<bool> hasWinner({required String matchId}) async {
|
||||||
|
final query = select(matchTable)
|
||||||
|
..where((g) => g.id.equals(matchId) & g.winnerId.isNotNull());
|
||||||
|
final result = await query.getSingleOrNull();
|
||||||
|
return result != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Changes the title of the match with the given [matchId] to [newName].
|
||||||
|
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||||
|
Future<bool> updateMatchName({
|
||||||
|
required String matchId,
|
||||||
|
required String newName,
|
||||||
|
}) async {
|
||||||
|
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||||
|
final rowsAffected = await query.write(
|
||||||
|
MatchTableCompanion(name: Value(newName)),
|
||||||
|
);
|
||||||
|
return rowsAffected > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
8
lib/data/dao/match_dao.g.dart
Normal file
8
lib/data/dao/match_dao.g.dart
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'match_dao.dart';
|
||||||
|
|
||||||
|
// ignore_for_file: type=lint
|
||||||
|
mixin _$MatchDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||||
|
$MatchTableTable get matchTable => attachedDatabase.matchTable;
|
||||||
|
}
|
||||||
@@ -50,6 +50,8 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Adds multiple [players] to the database in a batch operation.
|
/// Adds multiple [players] to the database in a batch operation.
|
||||||
|
/// Uses insertOrIgnore to avoid triggering cascade deletes on
|
||||||
|
/// player_group associations when players already exist.
|
||||||
Future<bool> addPlayersAsList({required List<Player> players}) async {
|
Future<bool> addPlayersAsList({required List<Player> players}) async {
|
||||||
if (players.isEmpty) return false;
|
if (players.isEmpty) return false;
|
||||||
|
|
||||||
@@ -65,7 +67,7 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.toList(),
|
.toList(),
|
||||||
mode: InsertMode.insertOrReplace,
|
mode: InsertMode.insertOrIgnore,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,128 +0,0 @@
|
|||||||
import 'package:drift/drift.dart';
|
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
|
||||||
import 'package:game_tracker/data/db/tables/player_game_table.dart';
|
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
|
||||||
|
|
||||||
part 'player_game_dao.g.dart';
|
|
||||||
|
|
||||||
@DriftAccessor(tables: [PlayerGameTable])
|
|
||||||
class PlayerGameDao extends DatabaseAccessor<AppDatabase>
|
|
||||||
with _$PlayerGameDaoMixin {
|
|
||||||
PlayerGameDao(super.db);
|
|
||||||
|
|
||||||
/// Associates a player with a game by inserting a record into the
|
|
||||||
/// [PlayerGameTable].
|
|
||||||
Future<void> addPlayerToGame({
|
|
||||||
required String gameId,
|
|
||||||
required String playerId,
|
|
||||||
}) async {
|
|
||||||
await into(playerGameTable).insert(
|
|
||||||
PlayerGameTableCompanion.insert(playerId: playerId, gameId: gameId),
|
|
||||||
mode: InsertMode.insertOrReplace,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieves a list of [Player]s associated with the given [gameId].
|
|
||||||
/// Returns null if no players are found.
|
|
||||||
Future<List<Player>?> getPlayersOfGame({required String gameId}) async {
|
|
||||||
final result = await (select(
|
|
||||||
playerGameTable,
|
|
||||||
)..where((p) => p.gameId.equals(gameId))).get();
|
|
||||||
|
|
||||||
if (result.isEmpty) return null;
|
|
||||||
|
|
||||||
final futures = result.map(
|
|
||||||
(row) => db.playerDao.getPlayerById(playerId: row.playerId),
|
|
||||||
);
|
|
||||||
final players = await Future.wait(futures);
|
|
||||||
return players;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if there are any players associated with the given [gameId].
|
|
||||||
/// Returns `true` if there are players, otherwise `false`.
|
|
||||||
Future<bool> gameHasPlayers({required String gameId}) async {
|
|
||||||
final count =
|
|
||||||
await (selectOnly(playerGameTable)
|
|
||||||
..where(playerGameTable.gameId.equals(gameId))
|
|
||||||
..addColumns([playerGameTable.playerId.count()]))
|
|
||||||
.map((row) => row.read(playerGameTable.playerId.count()))
|
|
||||||
.getSingle();
|
|
||||||
return (count ?? 0) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Checks if a specific player is associated with a specific game.
|
|
||||||
/// Returns `true` if the player is in the game, otherwise `false`.
|
|
||||||
Future<bool> isPlayerInGame({
|
|
||||||
required String gameId,
|
|
||||||
required String playerId,
|
|
||||||
}) async {
|
|
||||||
final count =
|
|
||||||
await (selectOnly(playerGameTable)
|
|
||||||
..where(playerGameTable.gameId.equals(gameId))
|
|
||||||
..where(playerGameTable.playerId.equals(playerId))
|
|
||||||
..addColumns([playerGameTable.playerId.count()]))
|
|
||||||
.map((row) => row.read(playerGameTable.playerId.count()))
|
|
||||||
.getSingle();
|
|
||||||
return (count ?? 0) > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Removes the association of a player with a game by deleting the record
|
|
||||||
/// from the [PlayerGameTable].
|
|
||||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
|
||||||
Future<bool> removePlayerFromGame({
|
|
||||||
required String gameId,
|
|
||||||
required String playerId,
|
|
||||||
}) async {
|
|
||||||
final query = delete(playerGameTable)
|
|
||||||
..where((pg) => pg.gameId.equals(gameId))
|
|
||||||
..where((pg) => pg.playerId.equals(playerId));
|
|
||||||
final rowsAffected = await query.go();
|
|
||||||
return rowsAffected > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Updates the players associated with a game based on the provided
|
|
||||||
/// [newPlayer] list. It adds new players and removes players that are no
|
|
||||||
/// longer associated with the game.
|
|
||||||
Future<void> updatePlayersFromGame({
|
|
||||||
required String gameId,
|
|
||||||
required List<Player> newPlayer,
|
|
||||||
}) async {
|
|
||||||
final currentPlayers = await getPlayersOfGame(gameId: gameId);
|
|
||||||
// Create sets of player IDs for easy comparison
|
|
||||||
final currentPlayerIds = currentPlayers?.map((p) => p.id).toSet() ?? {};
|
|
||||||
final newPlayerIdsSet = newPlayer.map((p) => p.id).toSet();
|
|
||||||
|
|
||||||
// Determine players to add and remove
|
|
||||||
final playersToAdd = newPlayerIdsSet.difference(currentPlayerIds);
|
|
||||||
final playersToRemove = currentPlayerIds.difference(newPlayerIdsSet);
|
|
||||||
|
|
||||||
db.transaction(() async {
|
|
||||||
// Remove old players
|
|
||||||
if (playersToRemove.isNotEmpty) {
|
|
||||||
await (delete(playerGameTable)..where(
|
|
||||||
(pg) =>
|
|
||||||
pg.gameId.equals(gameId) &
|
|
||||||
pg.playerId.isIn(playersToRemove.toList()),
|
|
||||||
))
|
|
||||||
.go();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add new players
|
|
||||||
if (playersToAdd.isNotEmpty) {
|
|
||||||
final inserts = playersToAdd
|
|
||||||
.map(
|
|
||||||
(id) =>
|
|
||||||
PlayerGameTableCompanion.insert(playerId: id, gameId: gameId),
|
|
||||||
)
|
|
||||||
.toList();
|
|
||||||
await Future.wait(
|
|
||||||
inserts.map(
|
|
||||||
(c) => into(
|
|
||||||
playerGameTable,
|
|
||||||
).insert(c, mode: InsertMode.insertOrReplace),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
|
||||||
|
|
||||||
part of 'player_game_dao.dart';
|
|
||||||
|
|
||||||
// ignore_for_file: type=lint
|
|
||||||
mixin _$PlayerGameDaoMixin on DatabaseAccessor<AppDatabase> {
|
|
||||||
$PlayerTableTable get playerTable => attachedDatabase.playerTable;
|
|
||||||
$GameTableTable get gameTable => attachedDatabase.gameTable;
|
|
||||||
$PlayerGameTableTable get playerGameTable => attachedDatabase.playerGameTable;
|
|
||||||
}
|
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/db/tables/player_group_table.dart';
|
import 'package:game_tracker/data/db/tables/player_group_table.dart';
|
||||||
|
import 'package:game_tracker/data/db/tables/player_table.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
|
||||||
part 'player_group_dao.g.dart';
|
part 'player_group_dao.g.dart';
|
||||||
|
|
||||||
@DriftAccessor(tables: [PlayerGroupTable])
|
@DriftAccessor(tables: [PlayerGroupTable, PlayerTable])
|
||||||
class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
|
class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
|
||||||
with _$PlayerGroupDaoMixin {
|
with _$PlayerGroupDaoMixin {
|
||||||
PlayerGroupDao(super.db);
|
PlayerGroupDao(super.db);
|
||||||
|
|||||||
130
lib/data/dao/player_match_dao.dart
Normal file
130
lib/data/dao/player_match_dao.dart
Normal file
@@ -0,0 +1,130 @@
|
|||||||
|
import 'package:drift/drift.dart';
|
||||||
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
|
import 'package:game_tracker/data/db/tables/player_match_table.dart';
|
||||||
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
|
||||||
|
part 'player_match_dao.g.dart';
|
||||||
|
|
||||||
|
@DriftAccessor(tables: [PlayerMatchTable])
|
||||||
|
class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||||
|
with _$PlayerMatchDaoMixin {
|
||||||
|
PlayerMatchDao(super.db);
|
||||||
|
|
||||||
|
/// Associates a player with a match by inserting a record into the
|
||||||
|
/// [PlayerMatchTable].
|
||||||
|
Future<void> addPlayerToMatch({
|
||||||
|
required String matchId,
|
||||||
|
required String playerId,
|
||||||
|
}) async {
|
||||||
|
await into(playerMatchTable).insert(
|
||||||
|
PlayerMatchTableCompanion.insert(playerId: playerId, matchId: matchId),
|
||||||
|
mode: InsertMode.insertOrIgnore,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Retrieves a list of [Player]s associated with the given [matchId].
|
||||||
|
/// Returns null if no players are found.
|
||||||
|
Future<List<Player>?> getPlayersOfMatch({required String matchId}) async {
|
||||||
|
final result = await (select(
|
||||||
|
playerMatchTable,
|
||||||
|
)..where((p) => p.matchId.equals(matchId))).get();
|
||||||
|
|
||||||
|
if (result.isEmpty) return null;
|
||||||
|
|
||||||
|
final futures = result.map(
|
||||||
|
(row) => db.playerDao.getPlayerById(playerId: row.playerId),
|
||||||
|
);
|
||||||
|
final players = await Future.wait(futures);
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks if there are any players associated with the given [matchId].
|
||||||
|
/// Returns `true` if there are players, otherwise `false`.
|
||||||
|
Future<bool> matchHasPlayers({required String matchId}) async {
|
||||||
|
final count =
|
||||||
|
await (selectOnly(playerMatchTable)
|
||||||
|
..where(playerMatchTable.matchId.equals(matchId))
|
||||||
|
..addColumns([playerMatchTable.playerId.count()]))
|
||||||
|
.map((row) => row.read(playerMatchTable.playerId.count()))
|
||||||
|
.getSingle();
|
||||||
|
return (count ?? 0) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks if a specific player is associated with a specific match.
|
||||||
|
/// Returns `true` if the player is in the match, otherwise `false`.
|
||||||
|
Future<bool> isPlayerInMatch({
|
||||||
|
required String matchId,
|
||||||
|
required String playerId,
|
||||||
|
}) async {
|
||||||
|
final count =
|
||||||
|
await (selectOnly(playerMatchTable)
|
||||||
|
..where(playerMatchTable.matchId.equals(matchId))
|
||||||
|
..where(playerMatchTable.playerId.equals(playerId))
|
||||||
|
..addColumns([playerMatchTable.playerId.count()]))
|
||||||
|
.map((row) => row.read(playerMatchTable.playerId.count()))
|
||||||
|
.getSingle();
|
||||||
|
return (count ?? 0) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes the association of a player with a match by deleting the record
|
||||||
|
/// from the [PlayerMatchTable].
|
||||||
|
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||||
|
Future<bool> removePlayerFromMatch({
|
||||||
|
required String matchId,
|
||||||
|
required String playerId,
|
||||||
|
}) async {
|
||||||
|
final query = delete(playerMatchTable)
|
||||||
|
..where((pg) => pg.matchId.equals(matchId))
|
||||||
|
..where((pg) => pg.playerId.equals(playerId));
|
||||||
|
final rowsAffected = await query.go();
|
||||||
|
return rowsAffected > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Updates the players associated with a match based on the provided
|
||||||
|
/// [newPlayer] list. It adds new players and removes players that are no
|
||||||
|
/// longer associated with the match.
|
||||||
|
Future<void> updatePlayersFromMatch({
|
||||||
|
required String matchId,
|
||||||
|
required List<Player> newPlayer,
|
||||||
|
}) async {
|
||||||
|
final currentPlayers = await getPlayersOfMatch(matchId: matchId);
|
||||||
|
// Create sets of player IDs for easy comparison
|
||||||
|
final currentPlayerIds = currentPlayers?.map((p) => p.id).toSet() ?? {};
|
||||||
|
final newPlayerIdsSet = newPlayer.map((p) => p.id).toSet();
|
||||||
|
|
||||||
|
// Determine players to add and remove
|
||||||
|
final playersToAdd = newPlayerIdsSet.difference(currentPlayerIds);
|
||||||
|
final playersToRemove = currentPlayerIds.difference(newPlayerIdsSet);
|
||||||
|
|
||||||
|
db.transaction(() async {
|
||||||
|
// Remove old players
|
||||||
|
if (playersToRemove.isNotEmpty) {
|
||||||
|
await (delete(playerMatchTable)..where(
|
||||||
|
(pg) =>
|
||||||
|
pg.matchId.equals(matchId) &
|
||||||
|
pg.playerId.isIn(playersToRemove.toList()),
|
||||||
|
))
|
||||||
|
.go();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new players
|
||||||
|
if (playersToAdd.isNotEmpty) {
|
||||||
|
final inserts = playersToAdd
|
||||||
|
.map(
|
||||||
|
(id) => PlayerMatchTableCompanion.insert(
|
||||||
|
playerId: id,
|
||||||
|
matchId: matchId,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
await Future.wait(
|
||||||
|
inserts.map(
|
||||||
|
(c) => into(
|
||||||
|
playerMatchTable,
|
||||||
|
).insert(c, mode: InsertMode.insertOrIgnore),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
11
lib/data/dao/player_match_dao.g.dart
Normal file
11
lib/data/dao/player_match_dao.g.dart
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'player_match_dao.dart';
|
||||||
|
|
||||||
|
// ignore_for_file: type=lint
|
||||||
|
mixin _$PlayerMatchDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||||
|
$PlayerTableTable get playerTable => attachedDatabase.playerTable;
|
||||||
|
$MatchTableTable get matchTable => attachedDatabase.matchTable;
|
||||||
|
$PlayerMatchTableTable get playerMatchTable =>
|
||||||
|
attachedDatabase.playerMatchTable;
|
||||||
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
import 'package:drift_flutter/drift_flutter.dart';
|
import 'package:drift_flutter/drift_flutter.dart';
|
||||||
import 'package:game_tracker/data/dao/game_dao.dart';
|
|
||||||
import 'package:game_tracker/data/dao/group_dao.dart';
|
import 'package:game_tracker/data/dao/group_dao.dart';
|
||||||
import 'package:game_tracker/data/dao/group_game_dao.dart';
|
import 'package:game_tracker/data/dao/group_match_dao.dart';
|
||||||
|
import 'package:game_tracker/data/dao/match_dao.dart';
|
||||||
import 'package:game_tracker/data/dao/player_dao.dart';
|
import 'package:game_tracker/data/dao/player_dao.dart';
|
||||||
import 'package:game_tracker/data/dao/player_game_dao.dart';
|
|
||||||
import 'package:game_tracker/data/dao/player_group_dao.dart';
|
import 'package:game_tracker/data/dao/player_group_dao.dart';
|
||||||
import 'package:game_tracker/data/db/tables/game_table.dart';
|
import 'package:game_tracker/data/dao/player_match_dao.dart';
|
||||||
import 'package:game_tracker/data/db/tables/group_game_table.dart';
|
import 'package:game_tracker/data/db/tables/group_match_table.dart';
|
||||||
import 'package:game_tracker/data/db/tables/group_table.dart';
|
import 'package:game_tracker/data/db/tables/group_table.dart';
|
||||||
import 'package:game_tracker/data/db/tables/player_game_table.dart';
|
import 'package:game_tracker/data/db/tables/match_table.dart';
|
||||||
import 'package:game_tracker/data/db/tables/player_group_table.dart';
|
import 'package:game_tracker/data/db/tables/player_group_table.dart';
|
||||||
|
import 'package:game_tracker/data/db/tables/player_match_table.dart';
|
||||||
import 'package:game_tracker/data/db/tables/player_table.dart';
|
import 'package:game_tracker/data/db/tables/player_table.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
@@ -20,18 +20,18 @@ part 'database.g.dart';
|
|||||||
tables: [
|
tables: [
|
||||||
PlayerTable,
|
PlayerTable,
|
||||||
GroupTable,
|
GroupTable,
|
||||||
GameTable,
|
MatchTable,
|
||||||
PlayerGroupTable,
|
PlayerGroupTable,
|
||||||
PlayerGameTable,
|
PlayerMatchTable,
|
||||||
GroupGameTable,
|
GroupMatchTable,
|
||||||
],
|
],
|
||||||
daos: [
|
daos: [
|
||||||
PlayerDao,
|
PlayerDao,
|
||||||
GroupDao,
|
GroupDao,
|
||||||
GameDao,
|
MatchDao,
|
||||||
PlayerGroupDao,
|
PlayerGroupDao,
|
||||||
PlayerGameDao,
|
PlayerMatchDao,
|
||||||
GroupGameDao,
|
GroupMatchDao,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
class AppDatabase extends _$AppDatabase {
|
class AppDatabase extends _$AppDatabase {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,13 +0,0 @@
|
|||||||
import 'package:drift/drift.dart';
|
|
||||||
import 'package:game_tracker/data/db/tables/game_table.dart';
|
|
||||||
import 'package:game_tracker/data/db/tables/group_table.dart';
|
|
||||||
|
|
||||||
class GroupGameTable extends Table {
|
|
||||||
TextColumn get groupId =>
|
|
||||||
text().references(GroupTable, #id, onDelete: KeyAction.cascade)();
|
|
||||||
TextColumn get gameId =>
|
|
||||||
text().references(GameTable, #id, onDelete: KeyAction.cascade)();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Set<Column<Object>> get primaryKey => {groupId, gameId};
|
|
||||||
}
|
|
||||||
13
lib/data/db/tables/group_match_table.dart
Normal file
13
lib/data/db/tables/group_match_table.dart
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import 'package:drift/drift.dart';
|
||||||
|
import 'package:game_tracker/data/db/tables/group_table.dart';
|
||||||
|
import 'package:game_tracker/data/db/tables/match_table.dart';
|
||||||
|
|
||||||
|
class GroupMatchTable extends Table {
|
||||||
|
TextColumn get groupId =>
|
||||||
|
text().references(GroupTable, #id, onDelete: KeyAction.cascade)();
|
||||||
|
TextColumn get matchId =>
|
||||||
|
text().references(MatchTable, #id, onDelete: KeyAction.cascade)();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Set<Column<Object>> get primaryKey => {groupId, matchId};
|
||||||
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart';
|
||||||
|
|
||||||
class GameTable extends Table {
|
class MatchTable extends Table {
|
||||||
TextColumn get id => text()();
|
TextColumn get id => text()();
|
||||||
TextColumn get name => text()();
|
TextColumn get name => text()();
|
||||||
late final winnerId = text().nullable()();
|
late final winnerId = text().nullable()();
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
import 'package:drift/drift.dart';
|
|
||||||
import 'package:game_tracker/data/db/tables/game_table.dart';
|
|
||||||
import 'package:game_tracker/data/db/tables/player_table.dart';
|
|
||||||
|
|
||||||
class PlayerGameTable extends Table {
|
|
||||||
TextColumn get playerId =>
|
|
||||||
text().references(PlayerTable, #id, onDelete: KeyAction.cascade)();
|
|
||||||
TextColumn get gameId =>
|
|
||||||
text().references(GameTable, #id, onDelete: KeyAction.cascade)();
|
|
||||||
|
|
||||||
@override
|
|
||||||
Set<Column<Object>> get primaryKey => {playerId, gameId};
|
|
||||||
}
|
|
||||||
13
lib/data/db/tables/player_match_table.dart
Normal file
13
lib/data/db/tables/player_match_table.dart
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import 'package:drift/drift.dart';
|
||||||
|
import 'package:game_tracker/data/db/tables/match_table.dart';
|
||||||
|
import 'package:game_tracker/data/db/tables/player_table.dart';
|
||||||
|
|
||||||
|
class PlayerMatchTable extends Table {
|
||||||
|
TextColumn get playerId =>
|
||||||
|
text().references(PlayerTable, #id, onDelete: KeyAction.cascade)();
|
||||||
|
TextColumn get matchId =>
|
||||||
|
text().references(MatchTable, #id, onDelete: KeyAction.cascade)();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Set<Column<Object>> get primaryKey => {playerId, matchId};
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ import 'package:game_tracker/data/dto/group.dart';
|
|||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
class Game {
|
class Match {
|
||||||
final String id;
|
final String id;
|
||||||
final DateTime createdAt;
|
final DateTime createdAt;
|
||||||
final String name;
|
final String name;
|
||||||
@@ -11,7 +11,7 @@ class Game {
|
|||||||
final Group? group;
|
final Group? group;
|
||||||
final Player? winner;
|
final Player? winner;
|
||||||
|
|
||||||
Game({
|
Match({
|
||||||
String? id,
|
String? id,
|
||||||
DateTime? createdAt,
|
DateTime? createdAt,
|
||||||
required this.name,
|
required this.name,
|
||||||
@@ -23,11 +23,11 @@ class Game {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'Game{\n\tid: $id,\n\tname: $name,\n\tplayers: $players,\n\tgroup: $group,\n\twinner: $winner\n}';
|
return 'Match{\n\tid: $id,\n\tname: $name,\n\tplayers: $players,\n\tgroup: $group,\n\twinner: $winner\n}';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a Game instance from a JSON object.
|
/// Creates a Match instance from a JSON object.
|
||||||
Game.fromJson(Map<String, dynamic> json)
|
Match.fromJson(Map<String, dynamic> json)
|
||||||
: id = json['id'],
|
: id = json['id'],
|
||||||
name = json['name'],
|
name = json['name'],
|
||||||
createdAt = DateTime.parse(json['createdAt']),
|
createdAt = DateTime.parse(json['createdAt']),
|
||||||
@@ -39,7 +39,7 @@ class Game {
|
|||||||
group = json['group'] != null ? Group.fromJson(json['group']) : null,
|
group = json['group'] != null ? Group.fromJson(json['group']) : null,
|
||||||
winner = json['winner'] != null ? Player.fromJson(json['winner']) : null;
|
winner = json['winner'] != null ? Player.fromJson(json['winner']) : null;
|
||||||
|
|
||||||
/// Converts the Game instance to a JSON object.
|
/// Converts the Match instance to a JSON object.
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
'id': id,
|
'id': id,
|
||||||
'createdAt': createdAt.toIso8601String(),
|
'createdAt': createdAt.toIso8601String(),
|
||||||
83
lib/l10n/arb/app_de.arb
Normal file
83
lib/l10n/arb/app_de.arb
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
{
|
||||||
|
"@@locale": "de",
|
||||||
|
"all_players": "Alle Spieler:innen",
|
||||||
|
"all_players_selected": "Alle Spieler:innen ausgewählt",
|
||||||
|
"amount_of_matches": "Anzahl der Spiele",
|
||||||
|
"cancel": "Abbrechen",
|
||||||
|
"choose_game": "Spielvorlage wählen",
|
||||||
|
"choose_group": "Gruppe wählen",
|
||||||
|
"choose_ruleset": "Regelwerk wählen",
|
||||||
|
"could_not_add_player": "Spieler:in {playerName} konnte nicht hinzugefügt werden",
|
||||||
|
"create_group": "Gruppe erstellen",
|
||||||
|
"create_match": "Spiel erstellen",
|
||||||
|
"create_new_group": "Neue Gruppe erstellen",
|
||||||
|
"create_new_match": "Neues Spiel erstellen",
|
||||||
|
"data_successfully_deleted": "Daten erfolgreich gelöscht",
|
||||||
|
"data_successfully_exported": "Daten erfolgreich exportiert",
|
||||||
|
"data_successfully_imported": "Daten erfolgreich importiert",
|
||||||
|
"days_ago": "vor {count} Tagen",
|
||||||
|
"delete": "Löschen",
|
||||||
|
"delete_all_data": "Alle Daten löschen?",
|
||||||
|
"error_creating_group": "Fehler beim Erstellen der Gruppe, bitte erneut versuchen",
|
||||||
|
"error_reading_file": "Fehler beim Lesen der Datei",
|
||||||
|
"export_canceled": "Export abgebrochen",
|
||||||
|
"export_data": "Daten exportieren",
|
||||||
|
"format_exception": "Formatfehler (siehe Konsole)",
|
||||||
|
"game": "Spielvorlage",
|
||||||
|
"game_name": "Spielvorlagenname",
|
||||||
|
"group": "Gruppe",
|
||||||
|
"group_name": "Gruppenname",
|
||||||
|
"groups": "Gruppen",
|
||||||
|
"home": "Startseite",
|
||||||
|
"import_canceled": "Import abgebrochen",
|
||||||
|
"import_data": "Daten importieren",
|
||||||
|
"info": "Info",
|
||||||
|
"invalid_schema": "Ungültiges Schema",
|
||||||
|
"least_points": "Niedrigste Punkte",
|
||||||
|
"match_in_progress": "Spiel läuft...",
|
||||||
|
"match_name": "Spieltitel",
|
||||||
|
"matches": "Spiele",
|
||||||
|
"menu": "Menü",
|
||||||
|
"most_points": "Höchste Punkte",
|
||||||
|
"no_data_available": "Keine Daten verfügbar",
|
||||||
|
"no_groups_created_yet": "Noch keine Gruppen erstellt",
|
||||||
|
"no_matches_created_yet": "Noch keine Spiele erstellt",
|
||||||
|
"no_players_created_yet": "Noch keine Spieler:in erstellt",
|
||||||
|
"no_players_found_with_that_name": "Keine Spieler:in mit diesem Namen gefunden",
|
||||||
|
"no_players_selected": "Keine Spieler:innen ausgewählt",
|
||||||
|
"no_recent_matches_available": "Keine letzten Spiele verfügbar",
|
||||||
|
"no_second_match_available": "Kein zweites Spiel verfügbar",
|
||||||
|
"no_statistics_available": "Keine Statistiken verfügbar",
|
||||||
|
"none": "Kein",
|
||||||
|
"none_group": "Keine",
|
||||||
|
"not_available": "Nicht verfügbar",
|
||||||
|
"player_name": "Spieler:innenname",
|
||||||
|
"players": "Spieler:innen",
|
||||||
|
"players_count": "{count} Spieler",
|
||||||
|
"quick_create": "Schnellzugriff",
|
||||||
|
"recent_matches": "Letzte Spiele",
|
||||||
|
"ruleset": "Regelwerk",
|
||||||
|
"ruleset_least_points": "Umgekehrte Wertung: Der/die Spieler:in mit den wenigsten Punkten gewinnt.",
|
||||||
|
"ruleset_most_points": "Traditionelles Regelwerk: Der/die Spieler:in mit den meisten Punkten gewinnt.",
|
||||||
|
"ruleset_single_loser": "Genau ein:e Verlierer:in wird bestimmt; der letzte Platz erhält die Strafe oder Konsequenz.",
|
||||||
|
"ruleset_single_winner": "Genau ein:e Gewinner:in wird gewählt; Unentschieden werden durch einen vordefinierten Tie-Breaker aufgelöst.",
|
||||||
|
"search_for_groups": "Nach Gruppen suchen",
|
||||||
|
"search_for_players": "Nach Spieler:innen suchen",
|
||||||
|
"select_winner": "Gewinner:in wählen:",
|
||||||
|
"selected_players": "Ausgewählte Spieler:innen",
|
||||||
|
"settings": "Einstellungen",
|
||||||
|
"single_loser": "Ein:e Verlierer:in",
|
||||||
|
"single_winner": "Ein:e Gewinner:in",
|
||||||
|
"statistics": "Statistiken",
|
||||||
|
"stats": "Statistiken",
|
||||||
|
"successfully_added_player": "Spieler:in {playerName} erfolgreich hinzugefügt",
|
||||||
|
"there_is_no_group_matching_your_search": "Es gibt keine Gruppe, die deiner Suche entspricht",
|
||||||
|
"this_cannot_be_undone": "Dies kann nicht rückgängig gemacht werden",
|
||||||
|
"today_at": "Heute um",
|
||||||
|
"undo": "Rückgängig",
|
||||||
|
"unknown_exception": "Unbekannter Fehler (siehe Konsole)",
|
||||||
|
"winner": "Gewinner:in",
|
||||||
|
"winrate": "Siegquote",
|
||||||
|
"wins": "Siege",
|
||||||
|
"yesterday_at": "Gestern um"
|
||||||
|
}
|
||||||
343
lib/l10n/arb/app_en.arb
Normal file
343
lib/l10n/arb/app_en.arb
Normal file
@@ -0,0 +1,343 @@
|
|||||||
|
{
|
||||||
|
"@@locale": "en",
|
||||||
|
"@all_players": {
|
||||||
|
"description": "Label for all players list"
|
||||||
|
},
|
||||||
|
"@all_players_selected": {
|
||||||
|
"description": "Message when all players are added to selection"
|
||||||
|
},
|
||||||
|
"@amount_of_matches": {
|
||||||
|
"description": "Label for amount of matches statistic"
|
||||||
|
},
|
||||||
|
"@app_name": {
|
||||||
|
"description": "The name of the App"
|
||||||
|
},
|
||||||
|
"@cancel": {
|
||||||
|
"description": "Cancel button text"
|
||||||
|
},
|
||||||
|
"@choose_game": {
|
||||||
|
"description": "Label for choosing a game"
|
||||||
|
},
|
||||||
|
"@choose_group": {
|
||||||
|
"description": "Label for choosing a group"
|
||||||
|
},
|
||||||
|
"@choose_ruleset": {
|
||||||
|
"description": "Label for choosing a ruleset"
|
||||||
|
},
|
||||||
|
"@could_not_add_player": {
|
||||||
|
"description": "Error message when adding a player fails"
|
||||||
|
},
|
||||||
|
"@create_group": {
|
||||||
|
"description": "Button text to create a group"
|
||||||
|
},
|
||||||
|
"@create_match": {
|
||||||
|
"description": "Button text to create a match"
|
||||||
|
},
|
||||||
|
"@create_new_group": {
|
||||||
|
"description": "Button text to create a new group"
|
||||||
|
},
|
||||||
|
"@create_new_match": {
|
||||||
|
"description": "Button text to create a new match"
|
||||||
|
},
|
||||||
|
"@data_successfully_deleted": {
|
||||||
|
"description": "Success message after deleting data"
|
||||||
|
},
|
||||||
|
"@data_successfully_exported": {
|
||||||
|
"description": "Success message after exporting data"
|
||||||
|
},
|
||||||
|
"@data_successfully_imported": {
|
||||||
|
"description": "Success message after importing data"
|
||||||
|
},
|
||||||
|
"@days_ago": {
|
||||||
|
"description": "Date format for days ago",
|
||||||
|
"placeholders": {
|
||||||
|
"count": {
|
||||||
|
"type": "int"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@delete": {
|
||||||
|
"description": "Delete button text"
|
||||||
|
},
|
||||||
|
"@delete_all_data": {
|
||||||
|
"description": "Confirmation dialog for deleting all data"
|
||||||
|
},
|
||||||
|
"@error_creating_group": {
|
||||||
|
"description": "Error message when group creation fails"
|
||||||
|
},
|
||||||
|
"@error_reading_file": {
|
||||||
|
"description": "Error message when file cannot be read"
|
||||||
|
},
|
||||||
|
"@export_canceled": {
|
||||||
|
"description": "Message when export is canceled"
|
||||||
|
},
|
||||||
|
"@export_data": {
|
||||||
|
"description": "Export data menu item"
|
||||||
|
},
|
||||||
|
"@format_exception": {
|
||||||
|
"description": "Error message for format exceptions"
|
||||||
|
},
|
||||||
|
"@game": {
|
||||||
|
"description": "Game label"
|
||||||
|
},
|
||||||
|
"@game_name": {
|
||||||
|
"description": "Placeholder for game name search"
|
||||||
|
},
|
||||||
|
"@group": {
|
||||||
|
"description": "Group label"
|
||||||
|
},
|
||||||
|
"@group_name": {
|
||||||
|
"description": "Placeholder for group name input"
|
||||||
|
},
|
||||||
|
"@groups": {
|
||||||
|
"description": "Label for groups"
|
||||||
|
},
|
||||||
|
"@home": {
|
||||||
|
"description": "Home tab label"
|
||||||
|
},
|
||||||
|
"@import_canceled": {
|
||||||
|
"description": "Message when import is canceled"
|
||||||
|
},
|
||||||
|
"@import_data": {
|
||||||
|
"description": "Import data menu item"
|
||||||
|
},
|
||||||
|
"@info": {
|
||||||
|
"description": "Info label"
|
||||||
|
},
|
||||||
|
"@invalid_schema": {
|
||||||
|
"description": "Error message for invalid schema"
|
||||||
|
},
|
||||||
|
"@least_points": {
|
||||||
|
"description": "Title for least points ruleset"
|
||||||
|
},
|
||||||
|
"@match_in_progress": {
|
||||||
|
"description": "Message when match is in progress"
|
||||||
|
},
|
||||||
|
"@match_name": {
|
||||||
|
"description": "Placeholder for match name input"
|
||||||
|
},
|
||||||
|
"@matches": {
|
||||||
|
"description": "Label for matches"
|
||||||
|
},
|
||||||
|
"@menu": {
|
||||||
|
"description": "Menu label"
|
||||||
|
},
|
||||||
|
"@most_points": {
|
||||||
|
"description": "Title for most points ruleset"
|
||||||
|
},
|
||||||
|
"@no_data_available": {
|
||||||
|
"description": "Message when no data in the statistic tiles is given"
|
||||||
|
},
|
||||||
|
"@no_groups_created_yet": {
|
||||||
|
"description": "Message when no groups exist"
|
||||||
|
},
|
||||||
|
"@no_matches_created_yet": {
|
||||||
|
"description": "Message when no matches exist"
|
||||||
|
},
|
||||||
|
"@no_players_created_yet": {
|
||||||
|
"description": "Message when no players exist"
|
||||||
|
},
|
||||||
|
"@no_players_found_with_that_name": {
|
||||||
|
"description": "Message when search returns no results"
|
||||||
|
},
|
||||||
|
"@no_players_selected": {
|
||||||
|
"description": "Message when no players are selected"
|
||||||
|
},
|
||||||
|
"@no_recent_matches_available": {
|
||||||
|
"description": "Message when no recent matches exist"
|
||||||
|
},
|
||||||
|
"@no_second_match_available": {
|
||||||
|
"description": "Message when no second match exists"
|
||||||
|
},
|
||||||
|
"@no_statistics_available": {
|
||||||
|
"description": "Message when no statistics are available, because no matches were played yet"
|
||||||
|
},
|
||||||
|
"@none": {
|
||||||
|
"description": "None option label"
|
||||||
|
},
|
||||||
|
"@none_group": {
|
||||||
|
"description": "None group option label"
|
||||||
|
},
|
||||||
|
"@not_available": {
|
||||||
|
"description": "Abbreviation for not available"
|
||||||
|
},
|
||||||
|
"@player_name": {
|
||||||
|
"description": "Placeholder for player name input"
|
||||||
|
},
|
||||||
|
"@players": {
|
||||||
|
"description": "Players label"
|
||||||
|
},
|
||||||
|
"@players_count": {
|
||||||
|
"description": "Shows the number of players",
|
||||||
|
"placeholders": {
|
||||||
|
"count": {
|
||||||
|
"type": "int"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@quick_create": {
|
||||||
|
"description": "Title for quick create section"
|
||||||
|
},
|
||||||
|
"@recent_matches": {
|
||||||
|
"description": "Title for recent matches section"
|
||||||
|
},
|
||||||
|
"@ruleset": {
|
||||||
|
"description": "Ruleset label"
|
||||||
|
},
|
||||||
|
"@ruleset_least_points": {
|
||||||
|
"description": "Description for least points ruleset"
|
||||||
|
},
|
||||||
|
"@ruleset_most_points": {
|
||||||
|
"description": "Description for most points ruleset"
|
||||||
|
},
|
||||||
|
"@ruleset_single_loser": {
|
||||||
|
"description": "Description for single loser ruleset"
|
||||||
|
},
|
||||||
|
"@ruleset_single_winner": {
|
||||||
|
"description": "Description for single winner ruleset"
|
||||||
|
},
|
||||||
|
"@search_for_groups": {
|
||||||
|
"description": "Hint text for group search input field"
|
||||||
|
},
|
||||||
|
"@search_for_players": {
|
||||||
|
"description": "Hint text for player search input field"
|
||||||
|
},
|
||||||
|
"@select_winner": {
|
||||||
|
"description": "Label to select the winner"
|
||||||
|
},
|
||||||
|
"@selected_players": {
|
||||||
|
"description": "Shows the number of selected players"
|
||||||
|
},
|
||||||
|
"@settings": {
|
||||||
|
"description": "Settings label"
|
||||||
|
},
|
||||||
|
"@single_loser": {
|
||||||
|
"description": "Title for single loser ruleset"
|
||||||
|
},
|
||||||
|
"@single_winner": {
|
||||||
|
"description": "Title for single winner ruleset"
|
||||||
|
},
|
||||||
|
"@statistics": {
|
||||||
|
"description": "Statistics tab label"
|
||||||
|
},
|
||||||
|
"@stats": {
|
||||||
|
"description": "Stats tab label (short)"
|
||||||
|
},
|
||||||
|
"@successfully_added_player": {
|
||||||
|
"description": "Success message when adding a player",
|
||||||
|
"placeholders": {
|
||||||
|
"playerName": {
|
||||||
|
"type": "String",
|
||||||
|
"example": "John"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@there_is_no_group_matching_your_search": {
|
||||||
|
"description": "Message when search returns no groups"
|
||||||
|
},
|
||||||
|
"@this_cannot_be_undone": {
|
||||||
|
"description": "Warning message for irreversible actions"
|
||||||
|
},
|
||||||
|
"@today_at": {
|
||||||
|
"description": "Date format for today"
|
||||||
|
},
|
||||||
|
"@undo": {
|
||||||
|
"description": "Undo button text"
|
||||||
|
},
|
||||||
|
"@unknown_exception": {
|
||||||
|
"description": "Error message for unknown exceptions"
|
||||||
|
},
|
||||||
|
"@winner": {
|
||||||
|
"description": "Winner label"
|
||||||
|
},
|
||||||
|
"@winrate": {
|
||||||
|
"description": "Label for winrate statistic"
|
||||||
|
},
|
||||||
|
"@wins": {
|
||||||
|
"description": "Label for wins statistic"
|
||||||
|
},
|
||||||
|
"@yesterday_at": {
|
||||||
|
"description": "Date format for yesterday"
|
||||||
|
},
|
||||||
|
"all_players": "All players",
|
||||||
|
"all_players_selected": "All players selected",
|
||||||
|
"amount_of_matches": "Amount of Matches",
|
||||||
|
"app_name": "Game Tracker",
|
||||||
|
"cancel": "Cancel",
|
||||||
|
"choose_game": "Choose Game",
|
||||||
|
"choose_group": "Choose Group",
|
||||||
|
"choose_ruleset": "Choose Ruleset",
|
||||||
|
"could_not_add_player": "Could not add player",
|
||||||
|
"create_group": "Create Group",
|
||||||
|
"create_match": "Create match",
|
||||||
|
"create_new_group": "Create new group",
|
||||||
|
"create_new_match": "Create new match",
|
||||||
|
"data_successfully_deleted": "Data successfully deleted",
|
||||||
|
"data_successfully_exported": "Data successfully exported",
|
||||||
|
"data_successfully_imported": "Data successfully imported",
|
||||||
|
"days_ago": "{count} days ago",
|
||||||
|
"delete": "Delete",
|
||||||
|
"delete_all_data": "Delete all data?",
|
||||||
|
"error_creating_group": "Error while creating group, please try again",
|
||||||
|
"error_reading_file": "Error reading file",
|
||||||
|
"export_canceled": "Export canceled",
|
||||||
|
"export_data": "Export data",
|
||||||
|
"format_exception": "Format Exception (see console)",
|
||||||
|
"game": "Game",
|
||||||
|
"game_name": "Game Name",
|
||||||
|
"group": "Group",
|
||||||
|
"group_name": "Group name",
|
||||||
|
"groups": "Groups",
|
||||||
|
"home": "Home",
|
||||||
|
"import_canceled": "Import canceled",
|
||||||
|
"import_data": "Import data",
|
||||||
|
"info": "Info",
|
||||||
|
"invalid_schema": "Invalid Schema",
|
||||||
|
"least_points": "Least Points",
|
||||||
|
"match_in_progress": "Match in progress...",
|
||||||
|
"match_name": "Match name",
|
||||||
|
"matches": "Matches",
|
||||||
|
"menu": "Menu",
|
||||||
|
"most_points": "Most Points",
|
||||||
|
"no_data_available": "No data available",
|
||||||
|
"no_groups_created_yet": "No groups created yet",
|
||||||
|
"no_matches_created_yet": "No matches created yet",
|
||||||
|
"no_players_created_yet": "No players created yet",
|
||||||
|
"no_players_found_with_that_name": "No players found with that name",
|
||||||
|
"no_players_selected": "No players selected",
|
||||||
|
"no_recent_matches_available": "No recent matches available",
|
||||||
|
"no_second_match_available": "No second match available",
|
||||||
|
"no_statistics_available": "No statistics available",
|
||||||
|
"none": "None",
|
||||||
|
"none_group": "None",
|
||||||
|
"not_available": "Not available",
|
||||||
|
"player_name": "Player name",
|
||||||
|
"players": "Players",
|
||||||
|
"players_count": "{count} Players",
|
||||||
|
"quick_create": "Quick Create",
|
||||||
|
"recent_matches": "Recent Matches",
|
||||||
|
"ruleset": "Ruleset",
|
||||||
|
"ruleset_least_points": "Inverse scoring: the player with the fewest points wins.",
|
||||||
|
"ruleset_most_points": "Traditional ruleset: the player with the most points wins.",
|
||||||
|
"ruleset_single_loser": "Exactly one loser is determined; last place receives the penalty or consequence.",
|
||||||
|
"ruleset_single_winner": "Exactly one winner is chosen; ties are resolved by a predefined tiebreaker.",
|
||||||
|
"search_for_groups": "Search for groups",
|
||||||
|
"search_for_players": "Search for players",
|
||||||
|
"select_winner": "Select Winner:",
|
||||||
|
"selected_players": "Selected players",
|
||||||
|
"settings": "Settings",
|
||||||
|
"single_loser": "Single Loser",
|
||||||
|
"single_winner": "Single Winner",
|
||||||
|
"statistics": "Statistics",
|
||||||
|
"stats": "Stats",
|
||||||
|
"successfully_added_player": "Successfully added player {playerName}",
|
||||||
|
"there_is_no_group_matching_your_search": "There is no group matching your search",
|
||||||
|
"this_cannot_be_undone": "This can't be undone",
|
||||||
|
"today_at": "Today at",
|
||||||
|
"undo": "Undo",
|
||||||
|
"unknown_exception": "Unknown Exception (see console)",
|
||||||
|
"winner": "Winner",
|
||||||
|
"winrate": "Winrate",
|
||||||
|
"wins": "Wins",
|
||||||
|
"yesterday_at": "Yesterday at"
|
||||||
|
}
|
||||||
620
lib/l10n/generated/app_localizations.dart
Normal file
620
lib/l10n/generated/app_localizations.dart
Normal file
@@ -0,0 +1,620 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||||
|
import 'package:intl/intl.dart' as intl;
|
||||||
|
|
||||||
|
import 'app_localizations_de.dart';
|
||||||
|
import 'app_localizations_en.dart';
|
||||||
|
|
||||||
|
// ignore_for_file: type=lint
|
||||||
|
|
||||||
|
/// Callers can lookup localized strings with an instance of AppLocalizations
|
||||||
|
/// returned by `AppLocalizations.of(context)`.
|
||||||
|
///
|
||||||
|
/// Applications need to include `AppLocalizations.delegate()` in their app's
|
||||||
|
/// `localizationDelegates` list, and the locales they support in the app's
|
||||||
|
/// `supportedLocales` list. For example:
|
||||||
|
///
|
||||||
|
/// ```dart
|
||||||
|
/// import 'generated/app_localizations.dart';
|
||||||
|
///
|
||||||
|
/// return MaterialApp(
|
||||||
|
/// localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||||
|
/// supportedLocales: AppLocalizations.supportedLocales,
|
||||||
|
/// home: MyApplicationHome(),
|
||||||
|
/// );
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ## Update pubspec.yaml
|
||||||
|
///
|
||||||
|
/// Please make sure to update your pubspec.yaml to include the following
|
||||||
|
/// packages:
|
||||||
|
///
|
||||||
|
/// ```yaml
|
||||||
|
/// dependencies:
|
||||||
|
/// # Internationalization support.
|
||||||
|
/// flutter_localizations:
|
||||||
|
/// sdk: flutter
|
||||||
|
/// intl: any # Use the pinned version from flutter_localizations
|
||||||
|
///
|
||||||
|
/// # Rest of dependencies
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
|
/// ## iOS Applications
|
||||||
|
///
|
||||||
|
/// iOS applications define key application metadata, including supported
|
||||||
|
/// locales, in an Info.plist file that is built into the application bundle.
|
||||||
|
/// To configure the locales supported by your app, you’ll need to edit this
|
||||||
|
/// file.
|
||||||
|
///
|
||||||
|
/// First, open your project’s ios/Runner.xcworkspace Xcode workspace file.
|
||||||
|
/// Then, in the Project Navigator, open the Info.plist file under the Runner
|
||||||
|
/// project’s Runner folder.
|
||||||
|
///
|
||||||
|
/// Next, select the Information Property List item, select Add Item from the
|
||||||
|
/// Editor menu, then select Localizations from the pop-up menu.
|
||||||
|
///
|
||||||
|
/// Select and expand the newly-created Localizations item then, for each
|
||||||
|
/// locale your application supports, add a new item and select the locale
|
||||||
|
/// you wish to add from the pop-up menu in the Value field. This list should
|
||||||
|
/// be consistent with the languages listed in the AppLocalizations.supportedLocales
|
||||||
|
/// property.
|
||||||
|
abstract class AppLocalizations {
|
||||||
|
AppLocalizations(String locale)
|
||||||
|
: localeName = intl.Intl.canonicalizedLocale(locale.toString());
|
||||||
|
|
||||||
|
final String localeName;
|
||||||
|
|
||||||
|
static AppLocalizations of(BuildContext context) {
|
||||||
|
return Localizations.of<AppLocalizations>(context, AppLocalizations)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const LocalizationsDelegate<AppLocalizations> delegate =
|
||||||
|
_AppLocalizationsDelegate();
|
||||||
|
|
||||||
|
/// A list of this localizations delegate along with the default localizations
|
||||||
|
/// delegates.
|
||||||
|
///
|
||||||
|
/// Returns a list of localizations delegates containing this delegate along with
|
||||||
|
/// GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate,
|
||||||
|
/// and GlobalWidgetsLocalizations.delegate.
|
||||||
|
///
|
||||||
|
/// Additional delegates can be added by appending to this list in
|
||||||
|
/// MaterialApp. This list does not have to be used at all if a custom list
|
||||||
|
/// of delegates is preferred or required.
|
||||||
|
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
|
||||||
|
<LocalizationsDelegate<dynamic>>[
|
||||||
|
delegate,
|
||||||
|
GlobalMaterialLocalizations.delegate,
|
||||||
|
GlobalCupertinoLocalizations.delegate,
|
||||||
|
GlobalWidgetsLocalizations.delegate,
|
||||||
|
];
|
||||||
|
|
||||||
|
/// A list of this localizations delegate's supported locales.
|
||||||
|
static const List<Locale> supportedLocales = <Locale>[
|
||||||
|
Locale('de'),
|
||||||
|
Locale('en'),
|
||||||
|
];
|
||||||
|
|
||||||
|
/// Label for all players list
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'All players'**
|
||||||
|
String get all_players;
|
||||||
|
|
||||||
|
/// Message when all players are added to selection
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'All players selected'**
|
||||||
|
String get all_players_selected;
|
||||||
|
|
||||||
|
/// Label for amount of matches statistic
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Amount of Matches'**
|
||||||
|
String get amount_of_matches;
|
||||||
|
|
||||||
|
/// The name of the App
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Game Tracker'**
|
||||||
|
String get app_name;
|
||||||
|
|
||||||
|
/// Cancel button text
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Cancel'**
|
||||||
|
String get cancel;
|
||||||
|
|
||||||
|
/// Label for choosing a game
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Choose Game'**
|
||||||
|
String get choose_game;
|
||||||
|
|
||||||
|
/// Label for choosing a group
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Choose Group'**
|
||||||
|
String get choose_group;
|
||||||
|
|
||||||
|
/// Label for choosing a ruleset
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Choose Ruleset'**
|
||||||
|
String get choose_ruleset;
|
||||||
|
|
||||||
|
/// Error message when adding a player fails
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Could not add player'**
|
||||||
|
String could_not_add_player(Object playerName);
|
||||||
|
|
||||||
|
/// Button text to create a group
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Create Group'**
|
||||||
|
String get create_group;
|
||||||
|
|
||||||
|
/// Button text to create a match
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Create match'**
|
||||||
|
String get create_match;
|
||||||
|
|
||||||
|
/// Button text to create a new group
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Create new group'**
|
||||||
|
String get create_new_group;
|
||||||
|
|
||||||
|
/// Button text to create a new match
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Create new match'**
|
||||||
|
String get create_new_match;
|
||||||
|
|
||||||
|
/// Success message after deleting data
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Data successfully deleted'**
|
||||||
|
String get data_successfully_deleted;
|
||||||
|
|
||||||
|
/// Success message after exporting data
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Data successfully exported'**
|
||||||
|
String get data_successfully_exported;
|
||||||
|
|
||||||
|
/// Success message after importing data
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Data successfully imported'**
|
||||||
|
String get data_successfully_imported;
|
||||||
|
|
||||||
|
/// Date format for days ago
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'{count} days ago'**
|
||||||
|
String days_ago(int count);
|
||||||
|
|
||||||
|
/// Delete button text
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Delete'**
|
||||||
|
String get delete;
|
||||||
|
|
||||||
|
/// Confirmation dialog for deleting all data
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Delete all data?'**
|
||||||
|
String get delete_all_data;
|
||||||
|
|
||||||
|
/// Error message when group creation fails
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Error while creating group, please try again'**
|
||||||
|
String get error_creating_group;
|
||||||
|
|
||||||
|
/// Error message when file cannot be read
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Error reading file'**
|
||||||
|
String get error_reading_file;
|
||||||
|
|
||||||
|
/// Message when export is canceled
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Export canceled'**
|
||||||
|
String get export_canceled;
|
||||||
|
|
||||||
|
/// Export data menu item
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Export data'**
|
||||||
|
String get export_data;
|
||||||
|
|
||||||
|
/// Error message for format exceptions
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Format Exception (see console)'**
|
||||||
|
String get format_exception;
|
||||||
|
|
||||||
|
/// Game label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Game'**
|
||||||
|
String get game;
|
||||||
|
|
||||||
|
/// Placeholder for game name search
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Game Name'**
|
||||||
|
String get game_name;
|
||||||
|
|
||||||
|
/// Group label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Group'**
|
||||||
|
String get group;
|
||||||
|
|
||||||
|
/// Placeholder for group name input
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Group name'**
|
||||||
|
String get group_name;
|
||||||
|
|
||||||
|
/// Label for groups
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Groups'**
|
||||||
|
String get groups;
|
||||||
|
|
||||||
|
/// Home tab label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Home'**
|
||||||
|
String get home;
|
||||||
|
|
||||||
|
/// Message when import is canceled
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Import canceled'**
|
||||||
|
String get import_canceled;
|
||||||
|
|
||||||
|
/// Import data menu item
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Import data'**
|
||||||
|
String get import_data;
|
||||||
|
|
||||||
|
/// Info label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Info'**
|
||||||
|
String get info;
|
||||||
|
|
||||||
|
/// Error message for invalid schema
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Invalid Schema'**
|
||||||
|
String get invalid_schema;
|
||||||
|
|
||||||
|
/// Title for least points ruleset
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Least Points'**
|
||||||
|
String get least_points;
|
||||||
|
|
||||||
|
/// Message when match is in progress
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Match in progress...'**
|
||||||
|
String get match_in_progress;
|
||||||
|
|
||||||
|
/// Placeholder for match name input
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Match name'**
|
||||||
|
String get match_name;
|
||||||
|
|
||||||
|
/// Label for matches
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Matches'**
|
||||||
|
String get matches;
|
||||||
|
|
||||||
|
/// Menu label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Menu'**
|
||||||
|
String get menu;
|
||||||
|
|
||||||
|
/// Title for most points ruleset
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Most Points'**
|
||||||
|
String get most_points;
|
||||||
|
|
||||||
|
/// Message when no data in the statistic tiles is given
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No data available'**
|
||||||
|
String get no_data_available;
|
||||||
|
|
||||||
|
/// Message when no groups exist
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No groups created yet'**
|
||||||
|
String get no_groups_created_yet;
|
||||||
|
|
||||||
|
/// Message when no matches exist
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No matches created yet'**
|
||||||
|
String get no_matches_created_yet;
|
||||||
|
|
||||||
|
/// Message when no players exist
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No players created yet'**
|
||||||
|
String get no_players_created_yet;
|
||||||
|
|
||||||
|
/// Message when search returns no results
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No players found with that name'**
|
||||||
|
String get no_players_found_with_that_name;
|
||||||
|
|
||||||
|
/// Message when no players are selected
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No players selected'**
|
||||||
|
String get no_players_selected;
|
||||||
|
|
||||||
|
/// Message when no recent matches exist
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No recent matches available'**
|
||||||
|
String get no_recent_matches_available;
|
||||||
|
|
||||||
|
/// Message when no second match exists
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No second match available'**
|
||||||
|
String get no_second_match_available;
|
||||||
|
|
||||||
|
/// Message when no statistics are available, because no matches were played yet
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'No statistics available'**
|
||||||
|
String get no_statistics_available;
|
||||||
|
|
||||||
|
/// None option label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'None'**
|
||||||
|
String get none;
|
||||||
|
|
||||||
|
/// None group option label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'None'**
|
||||||
|
String get none_group;
|
||||||
|
|
||||||
|
/// Abbreviation for not available
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Not available'**
|
||||||
|
String get not_available;
|
||||||
|
|
||||||
|
/// Placeholder for player name input
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Player name'**
|
||||||
|
String get player_name;
|
||||||
|
|
||||||
|
/// Players label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Players'**
|
||||||
|
String get players;
|
||||||
|
|
||||||
|
/// Shows the number of players
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'{count} Players'**
|
||||||
|
String players_count(int count);
|
||||||
|
|
||||||
|
/// Title for quick create section
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Quick Create'**
|
||||||
|
String get quick_create;
|
||||||
|
|
||||||
|
/// Title for recent matches section
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Recent Matches'**
|
||||||
|
String get recent_matches;
|
||||||
|
|
||||||
|
/// Ruleset label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Ruleset'**
|
||||||
|
String get ruleset;
|
||||||
|
|
||||||
|
/// Description for least points ruleset
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Inverse scoring: the player with the fewest points wins.'**
|
||||||
|
String get ruleset_least_points;
|
||||||
|
|
||||||
|
/// Description for most points ruleset
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Traditional ruleset: the player with the most points wins.'**
|
||||||
|
String get ruleset_most_points;
|
||||||
|
|
||||||
|
/// Description for single loser ruleset
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Exactly one loser is determined; last place receives the penalty or consequence.'**
|
||||||
|
String get ruleset_single_loser;
|
||||||
|
|
||||||
|
/// Description for single winner ruleset
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Exactly one winner is chosen; ties are resolved by a predefined tiebreaker.'**
|
||||||
|
String get ruleset_single_winner;
|
||||||
|
|
||||||
|
/// Hint text for group search input field
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Search for groups'**
|
||||||
|
String get search_for_groups;
|
||||||
|
|
||||||
|
/// Hint text for player search input field
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Search for players'**
|
||||||
|
String get search_for_players;
|
||||||
|
|
||||||
|
/// Label to select the winner
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Select Winner:'**
|
||||||
|
String get select_winner;
|
||||||
|
|
||||||
|
/// Shows the number of selected players
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Selected players'**
|
||||||
|
String get selected_players;
|
||||||
|
|
||||||
|
/// Settings label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Settings'**
|
||||||
|
String get settings;
|
||||||
|
|
||||||
|
/// Title for single loser ruleset
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Single Loser'**
|
||||||
|
String get single_loser;
|
||||||
|
|
||||||
|
/// Title for single winner ruleset
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Single Winner'**
|
||||||
|
String get single_winner;
|
||||||
|
|
||||||
|
/// Statistics tab label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Statistics'**
|
||||||
|
String get statistics;
|
||||||
|
|
||||||
|
/// Stats tab label (short)
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Stats'**
|
||||||
|
String get stats;
|
||||||
|
|
||||||
|
/// Success message when adding a player
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Successfully added player {playerName}'**
|
||||||
|
String successfully_added_player(String playerName);
|
||||||
|
|
||||||
|
/// Message when search returns no groups
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'There is no group matching your search'**
|
||||||
|
String get there_is_no_group_matching_your_search;
|
||||||
|
|
||||||
|
/// Warning message for irreversible actions
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'This can\'t be undone'**
|
||||||
|
String get this_cannot_be_undone;
|
||||||
|
|
||||||
|
/// Date format for today
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Today at'**
|
||||||
|
String get today_at;
|
||||||
|
|
||||||
|
/// Undo button text
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Undo'**
|
||||||
|
String get undo;
|
||||||
|
|
||||||
|
/// Error message for unknown exceptions
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Unknown Exception (see console)'**
|
||||||
|
String get unknown_exception;
|
||||||
|
|
||||||
|
/// Winner label
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Winner'**
|
||||||
|
String get winner;
|
||||||
|
|
||||||
|
/// Label for winrate statistic
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Winrate'**
|
||||||
|
String get winrate;
|
||||||
|
|
||||||
|
/// Label for wins statistic
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Wins'**
|
||||||
|
String get wins;
|
||||||
|
|
||||||
|
/// Date format for yesterday
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Yesterday at'**
|
||||||
|
String get yesterday_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AppLocalizationsDelegate
|
||||||
|
extends LocalizationsDelegate<AppLocalizations> {
|
||||||
|
const _AppLocalizationsDelegate();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<AppLocalizations> load(Locale locale) {
|
||||||
|
return SynchronousFuture<AppLocalizations>(lookupAppLocalizations(locale));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool isSupported(Locale locale) =>
|
||||||
|
<String>['de', 'en'].contains(locale.languageCode);
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool shouldReload(_AppLocalizationsDelegate old) => false;
|
||||||
|
}
|
||||||
|
|
||||||
|
AppLocalizations lookupAppLocalizations(Locale locale) {
|
||||||
|
// Lookup logic when only language code is specified.
|
||||||
|
switch (locale.languageCode) {
|
||||||
|
case 'de':
|
||||||
|
return AppLocalizationsDe();
|
||||||
|
case 'en':
|
||||||
|
return AppLocalizationsEn();
|
||||||
|
}
|
||||||
|
|
||||||
|
throw FlutterError(
|
||||||
|
'AppLocalizations.delegate failed to load unsupported locale "$locale". This is likely '
|
||||||
|
'an issue with the localizations generation tool. Please file an issue '
|
||||||
|
'on GitHub with a reproducible sample app and the gen-l10n configuration '
|
||||||
|
'that was used.',
|
||||||
|
);
|
||||||
|
}
|
||||||
269
lib/l10n/generated/app_localizations_de.dart
Normal file
269
lib/l10n/generated/app_localizations_de.dart
Normal file
@@ -0,0 +1,269 @@
|
|||||||
|
// ignore: unused_import
|
||||||
|
import 'package:intl/intl.dart' as intl;
|
||||||
|
import 'app_localizations.dart';
|
||||||
|
|
||||||
|
// ignore_for_file: type=lint
|
||||||
|
|
||||||
|
/// The translations for German (`de`).
|
||||||
|
class AppLocalizationsDe extends AppLocalizations {
|
||||||
|
AppLocalizationsDe([String locale = 'de']) : super(locale);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get all_players => 'Alle Spieler:innen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get all_players_selected => 'Alle Spieler:innen ausgewählt';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get amount_of_matches => 'Anzahl der Spiele';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get app_name => 'Game Tracker';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get cancel => 'Abbrechen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get choose_game => 'Spielvorlage wählen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get choose_group => 'Gruppe wählen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get choose_ruleset => 'Regelwerk wählen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String could_not_add_player(Object playerName) {
|
||||||
|
return 'Spieler:in $playerName konnte nicht hinzugefügt werden';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get create_group => 'Gruppe erstellen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get create_match => 'Spiel erstellen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get create_new_group => 'Neue Gruppe erstellen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get create_new_match => 'Neues Spiel erstellen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get data_successfully_deleted => 'Daten erfolgreich gelöscht';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get data_successfully_exported => 'Daten erfolgreich exportiert';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get data_successfully_imported => 'Daten erfolgreich importiert';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String days_ago(int count) {
|
||||||
|
return 'vor $count Tagen';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get delete => 'Löschen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get delete_all_data => 'Alle Daten löschen?';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get error_creating_group =>
|
||||||
|
'Fehler beim Erstellen der Gruppe, bitte erneut versuchen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get error_reading_file => 'Fehler beim Lesen der Datei';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get export_canceled => 'Export abgebrochen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get export_data => 'Daten exportieren';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get format_exception => 'Formatfehler (siehe Konsole)';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get game => 'Spielvorlage';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get game_name => 'Spielvorlagenname';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get group => 'Gruppe';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get group_name => 'Gruppenname';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get groups => 'Gruppen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get home => 'Startseite';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get import_canceled => 'Import abgebrochen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get import_data => 'Daten importieren';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get info => 'Info';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get invalid_schema => 'Ungültiges Schema';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get least_points => 'Niedrigste Punkte';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get match_in_progress => 'Spiel läuft...';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get match_name => 'Spieltitel';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get matches => 'Spiele';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get menu => 'Menü';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get most_points => 'Höchste Punkte';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_data_available => 'Keine Daten verfügbar';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_groups_created_yet => 'Noch keine Gruppen erstellt';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_matches_created_yet => 'Noch keine Spiele erstellt';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_players_created_yet => 'Noch keine Spieler:in erstellt';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_players_found_with_that_name =>
|
||||||
|
'Keine Spieler:in mit diesem Namen gefunden';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_players_selected => 'Keine Spieler:innen ausgewählt';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_recent_matches_available => 'Keine letzten Spiele verfügbar';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_second_match_available => 'Kein zweites Spiel verfügbar';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_statistics_available => 'Keine Statistiken verfügbar';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get none => 'Kein';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get none_group => 'Keine';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get not_available => 'Nicht verfügbar';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get player_name => 'Spieler:innenname';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get players => 'Spieler:innen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String players_count(int count) {
|
||||||
|
return '$count Spieler';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get quick_create => 'Schnellzugriff';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get recent_matches => 'Letzte Spiele';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get ruleset => 'Regelwerk';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get ruleset_least_points =>
|
||||||
|
'Umgekehrte Wertung: Der/die Spieler:in mit den wenigsten Punkten gewinnt.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get ruleset_most_points =>
|
||||||
|
'Traditionelles Regelwerk: Der/die Spieler:in mit den meisten Punkten gewinnt.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get ruleset_single_loser =>
|
||||||
|
'Genau ein:e Verlierer:in wird bestimmt; der letzte Platz erhält die Strafe oder Konsequenz.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get ruleset_single_winner =>
|
||||||
|
'Genau ein:e Gewinner:in wird gewählt; Unentschieden werden durch einen vordefinierten Tie-Breaker aufgelöst.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get search_for_groups => 'Nach Gruppen suchen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get search_for_players => 'Nach Spieler:innen suchen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get select_winner => 'Gewinner:in wählen:';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get selected_players => 'Ausgewählte Spieler:innen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get settings => 'Einstellungen';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get single_loser => 'Ein:e Verlierer:in';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get single_winner => 'Ein:e Gewinner:in';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get statistics => 'Statistiken';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get stats => 'Statistiken';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String successfully_added_player(String playerName) {
|
||||||
|
return 'Spieler:in $playerName erfolgreich hinzugefügt';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get there_is_no_group_matching_your_search =>
|
||||||
|
'Es gibt keine Gruppe, die deiner Suche entspricht';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get this_cannot_be_undone =>
|
||||||
|
'Dies kann nicht rückgängig gemacht werden';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get today_at => 'Heute um';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get undo => 'Rückgängig';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get unknown_exception => 'Unbekannter Fehler (siehe Konsole)';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get winner => 'Gewinner:in';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get winrate => 'Siegquote';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get wins => 'Siege';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get yesterday_at => 'Gestern um';
|
||||||
|
}
|
||||||
268
lib/l10n/generated/app_localizations_en.dart
Normal file
268
lib/l10n/generated/app_localizations_en.dart
Normal file
@@ -0,0 +1,268 @@
|
|||||||
|
// ignore: unused_import
|
||||||
|
import 'package:intl/intl.dart' as intl;
|
||||||
|
import 'app_localizations.dart';
|
||||||
|
|
||||||
|
// ignore_for_file: type=lint
|
||||||
|
|
||||||
|
/// The translations for English (`en`).
|
||||||
|
class AppLocalizationsEn extends AppLocalizations {
|
||||||
|
AppLocalizationsEn([String locale = 'en']) : super(locale);
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get all_players => 'All players';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get all_players_selected => 'All players selected';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get amount_of_matches => 'Amount of Matches';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get app_name => 'Game Tracker';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get cancel => 'Cancel';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get choose_game => 'Choose Game';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get choose_group => 'Choose Group';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get choose_ruleset => 'Choose Ruleset';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String could_not_add_player(Object playerName) {
|
||||||
|
return 'Could not add player';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get create_group => 'Create Group';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get create_match => 'Create match';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get create_new_group => 'Create new group';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get create_new_match => 'Create new match';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get data_successfully_deleted => 'Data successfully deleted';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get data_successfully_exported => 'Data successfully exported';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get data_successfully_imported => 'Data successfully imported';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String days_ago(int count) {
|
||||||
|
return '$count days ago';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get delete => 'Delete';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get delete_all_data => 'Delete all data?';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get error_creating_group =>
|
||||||
|
'Error while creating group, please try again';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get error_reading_file => 'Error reading file';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get export_canceled => 'Export canceled';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get export_data => 'Export data';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get format_exception => 'Format Exception (see console)';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get game => 'Game';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get game_name => 'Game Name';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get group => 'Group';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get group_name => 'Group name';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get groups => 'Groups';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get home => 'Home';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get import_canceled => 'Import canceled';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get import_data => 'Import data';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get info => 'Info';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get invalid_schema => 'Invalid Schema';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get least_points => 'Least Points';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get match_in_progress => 'Match in progress...';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get match_name => 'Match name';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get matches => 'Matches';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get menu => 'Menu';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get most_points => 'Most Points';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_data_available => 'No data available';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_groups_created_yet => 'No groups created yet';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_matches_created_yet => 'No matches created yet';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_players_created_yet => 'No players created yet';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_players_found_with_that_name =>
|
||||||
|
'No players found with that name';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_players_selected => 'No players selected';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_recent_matches_available => 'No recent matches available';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_second_match_available => 'No second match available';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get no_statistics_available => 'No statistics available';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get none => 'None';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get none_group => 'None';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get not_available => 'Not available';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get player_name => 'Player name';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get players => 'Players';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String players_count(int count) {
|
||||||
|
return '$count Players';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get quick_create => 'Quick Create';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get recent_matches => 'Recent Matches';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get ruleset => 'Ruleset';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get ruleset_least_points =>
|
||||||
|
'Inverse scoring: the player with the fewest points wins.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get ruleset_most_points =>
|
||||||
|
'Traditional ruleset: the player with the most points wins.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get ruleset_single_loser =>
|
||||||
|
'Exactly one loser is determined; last place receives the penalty or consequence.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get ruleset_single_winner =>
|
||||||
|
'Exactly one winner is chosen; ties are resolved by a predefined tiebreaker.';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get search_for_groups => 'Search for groups';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get search_for_players => 'Search for players';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get select_winner => 'Select Winner:';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get selected_players => 'Selected players';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get settings => 'Settings';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get single_loser => 'Single Loser';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get single_winner => 'Single Winner';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get statistics => 'Statistics';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get stats => 'Stats';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String successfully_added_player(String playerName) {
|
||||||
|
return 'Successfully added player $playerName';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get there_is_no_group_matching_your_search =>
|
||||||
|
'There is no group matching your search';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get this_cannot_be_undone => 'This can\'t be undone';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get today_at => 'Today at';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get undo => 'Undo';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get unknown_exception => 'Unknown Exception (see console)';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get winner => 'Winner';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get winrate => 'Winrate';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get wins => 'Wins';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get yesterday_at => 'Yesterday at';
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/custom_navigation_bar.dart';
|
import 'package:game_tracker/presentation/views/main_menu/custom_navigation_bar.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@@ -20,22 +21,30 @@ class GameTracker extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
|
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||||
|
supportedLocales: AppLocalizations.supportedLocales,
|
||||||
|
localeResolutionCallback: (locale, supportedLocales) {
|
||||||
|
for (final supportedLocale in supportedLocales) {
|
||||||
|
if (supportedLocale.languageCode == locale?.languageCode) {
|
||||||
|
return supportedLocale;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return supportedLocales.firstWhere(
|
||||||
|
(locale) => locale.languageCode == 'en',
|
||||||
|
);
|
||||||
|
},
|
||||||
debugShowCheckedModeBanner: false,
|
debugShowCheckedModeBanner: false,
|
||||||
title: 'Game Tracker',
|
onGenerateTitle: (context) => AppLocalizations.of(context).app_name,
|
||||||
darkTheme: ThemeData.dark(),
|
|
||||||
|
|
||||||
themeMode: ThemeMode.dark, // forces dark mode
|
themeMode: ThemeMode.dark, // forces dark mode
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
primaryColor: CustomTheme.primaryColor,
|
primaryColor: CustomTheme.primaryColor,
|
||||||
scaffoldBackgroundColor: CustomTheme.backgroundColor,
|
scaffoldBackgroundColor: CustomTheme.backgroundColor,
|
||||||
appBarTheme: CustomTheme.appBarTheme,
|
appBarTheme: CustomTheme.appBarTheme,
|
||||||
|
|
||||||
colorScheme: ColorScheme.fromSeed(
|
colorScheme: ColorScheme.fromSeed(
|
||||||
seedColor: CustomTheme.primaryColor,
|
seedColor: CustomTheme.primaryColor,
|
||||||
brightness: Brightness.dark,
|
brightness: Brightness.dark,
|
||||||
).copyWith(surface: CustomTheme.backgroundColor),
|
).copyWith(surface: CustomTheme.backgroundColor),
|
||||||
),
|
),
|
||||||
|
|
||||||
home: const CustomNavigationBar(),
|
home: const CustomNavigationBar(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/group_tile.dart';
|
|
||||||
|
|
||||||
class ChooseGroupView extends StatefulWidget {
|
|
||||||
final List<Group> groups;
|
|
||||||
final int initialGroupIndex;
|
|
||||||
|
|
||||||
const ChooseGroupView({
|
|
||||||
super.key,
|
|
||||||
required this.groups,
|
|
||||||
required this.initialGroupIndex,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ChooseGroupView> createState() => _ChooseGroupViewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ChooseGroupViewState extends State<ChooseGroupView> {
|
|
||||||
late int selectedGroupIndex;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
selectedGroupIndex = widget.initialGroupIndex;
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
|
||||||
scrolledUnderElevation: 0,
|
|
||||||
title: const Text(
|
|
||||||
'Choose Group',
|
|
||||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
centerTitle: true,
|
|
||||||
),
|
|
||||||
body: ListView.builder(
|
|
||||||
padding: const EdgeInsets.only(bottom: 85),
|
|
||||||
itemCount: widget.groups.length,
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
selectedGroupIndex = index;
|
|
||||||
});
|
|
||||||
|
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
|
||||||
if (!context.mounted) return;
|
|
||||||
Navigator.of(context).pop(widget.groups[index]);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
child: GroupTile(
|
|
||||||
group: widget.groups[index],
|
|
||||||
isHighlighted: selectedGroupIndex == index,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,120 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
|
||||||
import 'package:game_tracker/core/enums.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/ruleset_list_tile.dart';
|
|
||||||
|
|
||||||
class ChooseRulesetView extends StatefulWidget {
|
|
||||||
final List<(Ruleset, String, String)> rulesets;
|
|
||||||
final int initialRulesetIndex;
|
|
||||||
const ChooseRulesetView({
|
|
||||||
super.key,
|
|
||||||
required this.rulesets,
|
|
||||||
required this.initialRulesetIndex,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<ChooseRulesetView> createState() => _ChooseRulesetViewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ChooseRulesetViewState extends State<ChooseRulesetView> {
|
|
||||||
late int selectedRulesetIndex;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
selectedRulesetIndex = widget.initialRulesetIndex;
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return DefaultTabController(
|
|
||||||
length: 2,
|
|
||||||
initialIndex: 0,
|
|
||||||
child: Scaffold(
|
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
|
||||||
scrolledUnderElevation: 0,
|
|
||||||
title: const Text(
|
|
||||||
'Choose Ruleset',
|
|
||||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
centerTitle: true,
|
|
||||||
),
|
|
||||||
body: Column(
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
color: CustomTheme.backgroundColor,
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
||||||
child: TabBar(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 5),
|
|
||||||
// Label Settings
|
|
||||||
labelStyle: const TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
labelColor: Colors.white,
|
|
||||||
unselectedLabelStyle: const TextStyle(fontSize: 14),
|
|
||||||
unselectedLabelColor: Colors.white70,
|
|
||||||
// Indicator Settings
|
|
||||||
indicator: CustomTheme.standardBoxDecoration,
|
|
||||||
indicatorSize: TabBarIndicatorSize.tab,
|
|
||||||
indicatorWeight: 1,
|
|
||||||
indicatorPadding: const EdgeInsets.symmetric(
|
|
||||||
horizontal: 20,
|
|
||||||
vertical: 0,
|
|
||||||
),
|
|
||||||
// Divider Settings
|
|
||||||
dividerHeight: 0,
|
|
||||||
tabs: const [
|
|
||||||
Tab(text: 'Rulesets'),
|
|
||||||
Tab(text: 'Gametypes'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Divider(
|
|
||||||
indent: 30,
|
|
||||||
endIndent: 30,
|
|
||||||
thickness: 3,
|
|
||||||
radius: BorderRadius.all(Radius.circular(12)),
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: TabBarView(
|
|
||||||
children: [
|
|
||||||
ListView.builder(
|
|
||||||
padding: const EdgeInsets.only(bottom: 85),
|
|
||||||
itemCount: widget.rulesets.length,
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
return RulesetListTile(
|
|
||||||
onPressed: () async {
|
|
||||||
setState(() {
|
|
||||||
selectedRulesetIndex = index;
|
|
||||||
});
|
|
||||||
Future.delayed(const Duration(milliseconds: 500), () {
|
|
||||||
if (!context.mounted) return;
|
|
||||||
Navigator.of(
|
|
||||||
context,
|
|
||||||
).pop(widget.rulesets[index].$1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
title: widget.rulesets[index].$2,
|
|
||||||
description: widget.rulesets[index].$3,
|
|
||||||
isHighlighted: selectedRulesetIndex == index,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
const Center(
|
|
||||||
child: Text(
|
|
||||||
'No gametypes available',
|
|
||||||
style: TextStyle(color: Colors.white70),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,232 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
|
||||||
import 'package:game_tracker/core/enums.dart';
|
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
|
||||||
import 'package:game_tracker/presentation/views/main_menu/create_game/choose_group_view.dart';
|
|
||||||
import 'package:game_tracker/presentation/views/main_menu/create_game/choose_ruleset_view.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/player_selection.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/text_input/text_input_field.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/choose_tile.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
class CreateGameView extends StatefulWidget {
|
|
||||||
const CreateGameView({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<CreateGameView> createState() => _CreateGameViewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _CreateGameViewState extends State<CreateGameView> {
|
|
||||||
/// Reference to the app database
|
|
||||||
late final AppDatabase db;
|
|
||||||
|
|
||||||
/// Futures to load all groups and players from the database
|
|
||||||
late Future<List<Group>> _allGroupsFuture;
|
|
||||||
|
|
||||||
/// Future to load all players from the database
|
|
||||||
late Future<List<Player>> _allPlayersFuture;
|
|
||||||
|
|
||||||
/// Controller for the game name input field
|
|
||||||
final TextEditingController _gameNameController = TextEditingController();
|
|
||||||
|
|
||||||
/// List of all groups from the database
|
|
||||||
List<Group> groupsList = [];
|
|
||||||
|
|
||||||
/// List of all players from the database
|
|
||||||
List<Player> playerList = [];
|
|
||||||
|
|
||||||
/// The currently selected group
|
|
||||||
Group? selectedGroup;
|
|
||||||
|
|
||||||
/// The index of the currently selected group in [groupsList] to mark it in
|
|
||||||
/// the [ChooseGroupView]
|
|
||||||
int selectedGroupIndex = -1;
|
|
||||||
|
|
||||||
/// The currently selected ruleset
|
|
||||||
Ruleset? selectedRuleset;
|
|
||||||
|
|
||||||
/// The index of the currently selected ruleset in [rulesets] to mark it in
|
|
||||||
/// the [ChooseRulesetView]
|
|
||||||
int selectedRulesetIndex = -1;
|
|
||||||
|
|
||||||
/// The currently selected players
|
|
||||||
List<Player>? selectedPlayers;
|
|
||||||
|
|
||||||
/// List of available rulesets with their display names and descriptions
|
|
||||||
/// as tuples of (Ruleset, String, String)
|
|
||||||
List<(Ruleset, String, String)> rulesets = [
|
|
||||||
(
|
|
||||||
Ruleset.singleWinner,
|
|
||||||
'Single Winner',
|
|
||||||
'Exactly one winner is chosen; ties are resolved by a predefined tiebreaker.',
|
|
||||||
),
|
|
||||||
(
|
|
||||||
Ruleset.singleLoser,
|
|
||||||
'Single Loser',
|
|
||||||
'Exactly one loser is determined; last place receives the penalty or consequence.',
|
|
||||||
),
|
|
||||||
(
|
|
||||||
Ruleset.mostPoints,
|
|
||||||
'Most Points',
|
|
||||||
'Traditional ruleset: the player with the most points wins.',
|
|
||||||
),
|
|
||||||
(
|
|
||||||
Ruleset.lastPoints,
|
|
||||||
'Least Points',
|
|
||||||
'Inverse scoring: the player with the fewest points wins.',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
db = Provider.of<AppDatabase>(context, listen: false);
|
|
||||||
|
|
||||||
_allGroupsFuture = db.groupDao.getAllGroups();
|
|
||||||
_allPlayersFuture = db.playerDao.getAllPlayers();
|
|
||||||
|
|
||||||
Future.wait([_allGroupsFuture, _allPlayersFuture]).then((result) async {
|
|
||||||
groupsList = result[0] as List<Group>;
|
|
||||||
playerList = result[1] as List<Player>;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
|
||||||
appBar: AppBar(
|
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
|
||||||
scrolledUnderElevation: 0,
|
|
||||||
title: const Text(
|
|
||||||
'Create new game',
|
|
||||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
centerTitle: true,
|
|
||||||
),
|
|
||||||
body: SafeArea(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Container(
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
|
||||||
child: TextInputField(
|
|
||||||
controller: _gameNameController,
|
|
||||||
hintText: 'Game name',
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
ChooseTile(
|
|
||||||
title: 'Ruleset',
|
|
||||||
trailingText: selectedRuleset == null
|
|
||||||
? 'None'
|
|
||||||
: translateRulesetToString(selectedRuleset!),
|
|
||||||
onPressed: () async {
|
|
||||||
selectedRuleset = await Navigator.of(context).push(
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => ChooseRulesetView(
|
|
||||||
rulesets: rulesets,
|
|
||||||
initialRulesetIndex: selectedRulesetIndex,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
selectedRulesetIndex = rulesets.indexWhere(
|
|
||||||
(r) => r.$1 == selectedRuleset,
|
|
||||||
);
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
ChooseTile(
|
|
||||||
title: 'Group',
|
|
||||||
trailingText: selectedGroup == null
|
|
||||||
? 'None'
|
|
||||||
: selectedGroup!.name,
|
|
||||||
onPressed: () async {
|
|
||||||
selectedGroup = await Navigator.of(context).push(
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) => ChooseGroupView(
|
|
||||||
groups: groupsList,
|
|
||||||
initialGroupIndex: selectedGroupIndex,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
selectedGroupIndex = groupsList.indexWhere(
|
|
||||||
(g) => g.id == selectedGroup?.id,
|
|
||||||
);
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Expanded(
|
|
||||||
child: PlayerSelection(
|
|
||||||
key: ValueKey(selectedGroup?.id ?? 'no_group'),
|
|
||||||
initialPlayers: selectedGroup == null
|
|
||||||
? playerList
|
|
||||||
: playerList
|
|
||||||
.where(
|
|
||||||
(p) => !selectedGroup!.members.any(
|
|
||||||
(m) => m.id == p.id,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {
|
|
||||||
selectedPlayers = value;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
CustomWidthButton(
|
|
||||||
text: 'Create game',
|
|
||||||
sizeRelativeToWidth: 0.95,
|
|
||||||
buttonType: ButtonType.primary,
|
|
||||||
onPressed: _enableCreateGameButton()
|
|
||||||
? () async {
|
|
||||||
Game game = Game(
|
|
||||||
name: _gameNameController.text.trim(),
|
|
||||||
createdAt: DateTime.now(),
|
|
||||||
group: selectedGroup!,
|
|
||||||
players: selectedPlayers,
|
|
||||||
);
|
|
||||||
// TODO: Replace with navigation to GameResultView()
|
|
||||||
print('Created game: $game');
|
|
||||||
Navigator.pop(context);
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Translates a [Ruleset] enum value to its corresponding string representation.
|
|
||||||
String translateRulesetToString(Ruleset ruleset) {
|
|
||||||
switch (ruleset) {
|
|
||||||
case Ruleset.singleWinner:
|
|
||||||
return 'Single Winner';
|
|
||||||
case Ruleset.singleLoser:
|
|
||||||
return 'Single Loser';
|
|
||||||
case Ruleset.mostPoints:
|
|
||||||
return 'Most Points';
|
|
||||||
case Ruleset.lastPoints:
|
|
||||||
return 'Least Points';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Determines whether the "Create Game" button should be enabled based on
|
|
||||||
/// the current state of the input fields.
|
|
||||||
bool _enableCreateGameButton() {
|
|
||||||
return _gameNameController.text.isNotEmpty &&
|
|
||||||
(selectedGroup != null ||
|
|
||||||
(selectedPlayers != null && selectedPlayers!.isNotEmpty)) &&
|
|
||||||
selectedRuleset != null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/game_history_view.dart';
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/groups_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/group_view/groups_view.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/home_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/home_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/views/main_menu/match_view/match_view.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/settings_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/settings_view.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/statistics_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/statistics_view.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/navbar_item.dart';
|
import 'package:game_tracker/presentation/widgets/navbar_item.dart';
|
||||||
@@ -16,22 +17,21 @@ class CustomNavigationBar extends StatefulWidget {
|
|||||||
|
|
||||||
class _CustomNavigationBarState extends State<CustomNavigationBar>
|
class _CustomNavigationBarState extends State<CustomNavigationBar>
|
||||||
with SingleTickerProviderStateMixin {
|
with SingleTickerProviderStateMixin {
|
||||||
|
/// Currently selected tab index
|
||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
|
|
||||||
|
/// Key count to force rebuild of tab views
|
||||||
int tabKeyCount = 0;
|
int tabKeyCount = 0;
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
// Pretty ugly but works
|
// Pretty ugly but works
|
||||||
final List<Widget> tabs = [
|
final List<Widget> tabs = [
|
||||||
KeyedSubtree(key: ValueKey('home_$tabKeyCount'), child: const HomeView()),
|
KeyedSubtree(key: ValueKey('home_$tabKeyCount'), child: const HomeView()),
|
||||||
KeyedSubtree(
|
KeyedSubtree(
|
||||||
key: ValueKey('games_$tabKeyCount'),
|
key: ValueKey('matches_$tabKeyCount'),
|
||||||
child: const GameHistoryView(),
|
child: const MatchView(),
|
||||||
),
|
),
|
||||||
KeyedSubtree(
|
KeyedSubtree(
|
||||||
key: ValueKey('groups_$tabKeyCount'),
|
key: ValueKey('groups_$tabKeyCount'),
|
||||||
@@ -46,7 +46,7 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
|||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
centerTitle: true,
|
centerTitle: true,
|
||||||
title: Text(
|
title: Text(
|
||||||
_currentTabTitle(),
|
_currentTabTitle(context),
|
||||||
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
@@ -89,28 +89,28 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
|||||||
index: 0,
|
index: 0,
|
||||||
isSelected: currentIndex == 0,
|
isSelected: currentIndex == 0,
|
||||||
icon: Icons.home_rounded,
|
icon: Icons.home_rounded,
|
||||||
label: 'Home',
|
label: loc.home,
|
||||||
onTabTapped: onTabTapped,
|
onTabTapped: onTabTapped,
|
||||||
),
|
),
|
||||||
NavbarItem(
|
NavbarItem(
|
||||||
index: 1,
|
index: 1,
|
||||||
isSelected: currentIndex == 1,
|
isSelected: currentIndex == 1,
|
||||||
icon: Icons.gamepad_rounded,
|
icon: Icons.gamepad_rounded,
|
||||||
label: 'Games',
|
label: loc.matches,
|
||||||
onTabTapped: onTabTapped,
|
onTabTapped: onTabTapped,
|
||||||
),
|
),
|
||||||
NavbarItem(
|
NavbarItem(
|
||||||
index: 2,
|
index: 2,
|
||||||
isSelected: currentIndex == 2,
|
isSelected: currentIndex == 2,
|
||||||
icon: Icons.group_rounded,
|
icon: Icons.group_rounded,
|
||||||
label: 'Groups',
|
label: loc.groups,
|
||||||
onTabTapped: onTabTapped,
|
onTabTapped: onTabTapped,
|
||||||
),
|
),
|
||||||
NavbarItem(
|
NavbarItem(
|
||||||
index: 3,
|
index: 3,
|
||||||
isSelected: currentIndex == 3,
|
isSelected: currentIndex == 3,
|
||||||
icon: Icons.bar_chart_rounded,
|
icon: Icons.bar_chart_rounded,
|
||||||
label: 'Stats',
|
label: loc.statistics,
|
||||||
onTabTapped: onTabTapped,
|
onTabTapped: onTabTapped,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -122,22 +122,25 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handles tab tap events. Updates the current [index] state.
|
||||||
void onTabTapped(int index) {
|
void onTabTapped(int index) {
|
||||||
setState(() {
|
setState(() {
|
||||||
currentIndex = index;
|
currentIndex = index;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
String _currentTabTitle() {
|
/// Returns the title of the current tab based on [currentIndex].
|
||||||
|
String _currentTabTitle(context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
switch (currentIndex) {
|
switch (currentIndex) {
|
||||||
case 0:
|
case 0:
|
||||||
return 'Home';
|
return loc.home;
|
||||||
case 1:
|
case 1:
|
||||||
return 'Game History';
|
return loc.matches;
|
||||||
case 2:
|
case 2:
|
||||||
return 'Groups';
|
return loc.groups;
|
||||||
case 3:
|
case 3:
|
||||||
return 'Statistics';
|
return loc.statistics;
|
||||||
default:
|
default:
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,150 +0,0 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
|
||||||
import 'package:game_tracker/presentation/views/main_menu/create_group_view.dart';
|
|
||||||
import 'package:game_tracker/presentation/views/main_menu/game_result_view.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/game_history_tile.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
class GameHistoryView extends StatefulWidget {
|
|
||||||
const GameHistoryView({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<GameHistoryView> createState() => _GameHistoryViewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _GameHistoryViewState extends State<GameHistoryView> {
|
|
||||||
late Future<List<Game>> _gameListFuture;
|
|
||||||
late final AppDatabase db;
|
|
||||||
|
|
||||||
late final List<Game> skeletonData = List.filled(
|
|
||||||
4,
|
|
||||||
Game(
|
|
||||||
name: 'Skeleton Game',
|
|
||||||
group: Group(
|
|
||||||
name: 'Skeleton Group',
|
|
||||||
members: [
|
|
||||||
Player(name: 'Player 1'),
|
|
||||||
Player(name: 'Player 2'),
|
|
||||||
Player(name: 'Player 3'),
|
|
||||||
Player(name: 'Long Name Player 4'),
|
|
||||||
Player(name: 'Player 5'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
winner: Player(name: 'Skeleton Player 1'),
|
|
||||||
players: [Player(name: 'Skeleton Player 6')],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
db = Provider.of<AppDatabase>(context, listen: false);
|
|
||||||
_gameListFuture = Future.delayed(
|
|
||||||
const Duration(milliseconds: 250),
|
|
||||||
() => db.gameDao.getAllGames(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
|
||||||
body: Stack(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
children: [
|
|
||||||
FutureBuilder<List<Game>>(
|
|
||||||
future: _gameListFuture,
|
|
||||||
builder:
|
|
||||||
(BuildContext context, AsyncSnapshot<List<Game>> snapshot) {
|
|
||||||
if (snapshot.hasError) {
|
|
||||||
return const Center(
|
|
||||||
child: TopCenteredMessage(
|
|
||||||
icon: Icons.report,
|
|
||||||
title: 'Error',
|
|
||||||
message: 'Game data could not be loaded',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (snapshot.connectionState == ConnectionState.done &&
|
|
||||||
(!snapshot.hasData || snapshot.data!.isEmpty)) {
|
|
||||||
return const Center(
|
|
||||||
child: TopCenteredMessage(
|
|
||||||
icon: Icons.report,
|
|
||||||
title: 'Info',
|
|
||||||
message: 'No games created yet',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final bool isLoading =
|
|
||||||
snapshot.connectionState == ConnectionState.waiting;
|
|
||||||
final List<Game> games =
|
|
||||||
(isLoading ? skeletonData : (snapshot.data ?? [])
|
|
||||||
..sort(
|
|
||||||
(a, b) => b.createdAt.compareTo(a.createdAt),
|
|
||||||
))
|
|
||||||
.toList();
|
|
||||||
return AppSkeleton(
|
|
||||||
enabled: isLoading,
|
|
||||||
child: ListView.builder(
|
|
||||||
padding: const EdgeInsets.only(bottom: 85),
|
|
||||||
itemCount: games.length + 1,
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
if (index == games.length) {
|
|
||||||
return SizedBox(
|
|
||||||
height: MediaQuery.paddingOf(context).bottom - 80,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return GameHistoryTile(
|
|
||||||
onTap: () async {
|
|
||||||
await Navigator.push(
|
|
||||||
context,
|
|
||||||
CupertinoPageRoute(
|
|
||||||
fullscreenDialog: true,
|
|
||||||
builder: (context) =>
|
|
||||||
GameResultView(game: games[index]),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
setState(() {
|
|
||||||
_gameListFuture = db.gameDao.getAllGames();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
game: games[index],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
bottom: MediaQuery.paddingOf(context).bottom,
|
|
||||||
child: CustomWidthButton(
|
|
||||||
text: 'Create Game',
|
|
||||||
sizeRelativeToWidth: 0.90,
|
|
||||||
onPressed: () async {
|
|
||||||
await Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) {
|
|
||||||
return const CreateGroupView();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
setState(() {
|
|
||||||
_gameListFuture = db.gameDao.getAllGames();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,6 +4,7 @@ import 'package:game_tracker/core/enums.dart';
|
|||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/player_selection.dart';
|
import 'package:game_tracker/presentation/widgets/player_selection.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/text_input/text_input_field.dart';
|
import 'package:game_tracker/presentation/widgets/text_input/text_input_field.dart';
|
||||||
@@ -17,8 +18,12 @@ class CreateGroupView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _CreateGroupViewState extends State<CreateGroupView> {
|
class _CreateGroupViewState extends State<CreateGroupView> {
|
||||||
final _groupNameController = TextEditingController();
|
|
||||||
late final AppDatabase db;
|
late final AppDatabase db;
|
||||||
|
|
||||||
|
/// Controller for the group name input field
|
||||||
|
final _groupNameController = TextEditingController();
|
||||||
|
|
||||||
|
/// List of currently selected players
|
||||||
List<Player> selectedPlayers = [];
|
List<Player> selectedPlayers = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -38,44 +43,37 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
appBar: AppBar(
|
appBar: AppBar(title: Text(loc.create_new_group)),
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
|
||||||
scrolledUnderElevation: 0,
|
|
||||||
title: const Text(
|
|
||||||
'Create new group',
|
|
||||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
centerTitle: true,
|
|
||||||
),
|
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
margin: CustomTheme.standardMargin,
|
||||||
child: TextInputField(
|
child: TextInputField(
|
||||||
controller: _groupNameController,
|
controller: _groupNameController,
|
||||||
hintText: 'Group name',
|
hintText: loc.group_name,
|
||||||
onChanged: (value) {
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: PlayerSelection(
|
child: PlayerSelection(
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
selectedPlayers = [...value];
|
setState(() {
|
||||||
|
selectedPlayers = [...value];
|
||||||
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
CustomWidthButton(
|
CustomWidthButton(
|
||||||
text: 'Create group',
|
text: loc.create_group,
|
||||||
sizeRelativeToWidth: 0.95,
|
sizeRelativeToWidth: 0.95,
|
||||||
buttonType: ButtonType.primary,
|
buttonType: ButtonType.primary,
|
||||||
onPressed:
|
onPressed:
|
||||||
(_groupNameController.text.isEmpty || selectedPlayers.isEmpty)
|
(_groupNameController.text.isEmpty ||
|
||||||
|
(selectedPlayers.length < 2))
|
||||||
? null
|
? null
|
||||||
: () async {
|
: () async {
|
||||||
bool success = await db.groupDao.addGroup(
|
bool success = await db.groupDao.addGroup(
|
||||||
@@ -91,16 +89,17 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
backgroundColor: CustomTheme.boxColor,
|
backgroundColor: CustomTheme.boxColor,
|
||||||
content: const Center(
|
content: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
'Error while creating group, please try again',
|
AppLocalizations.of(
|
||||||
style: TextStyle(color: Colors.white),
|
context,
|
||||||
|
).error_creating_group,
|
||||||
|
style: const TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
setState(() {});
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
122
lib/presentation/views/main_menu/group_view/groups_view.dart
Normal file
122
lib/presentation/views/main_menu/group_view/groups_view.dart
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/core/constants.dart';
|
||||||
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
|
import 'package:game_tracker/presentation/views/main_menu/group_view/create_group_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/tiles/group_tile.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class GroupsView extends StatefulWidget {
|
||||||
|
const GroupsView({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<GroupsView> createState() => _GroupsViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _GroupsViewState extends State<GroupsView> {
|
||||||
|
late final AppDatabase db;
|
||||||
|
|
||||||
|
/// Loaded groups from the database
|
||||||
|
late List<Group> loadedGroups;
|
||||||
|
|
||||||
|
/// Loading state
|
||||||
|
bool isLoading = true;
|
||||||
|
|
||||||
|
List<Group> groups = List.filled(
|
||||||
|
7,
|
||||||
|
Group(
|
||||||
|
name: 'Skeleton Group',
|
||||||
|
members: List.filled(6, Player(name: 'Skeleton Player')),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
|
loadGroups();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
|
body: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
AppSkeleton(
|
||||||
|
enabled: isLoading,
|
||||||
|
child: Visibility(
|
||||||
|
visible: groups.isNotEmpty,
|
||||||
|
replacement: Center(
|
||||||
|
child: TopCenteredMessage(
|
||||||
|
icon: Icons.info,
|
||||||
|
title: loc.info,
|
||||||
|
message: loc.no_groups_created_yet,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
padding: const EdgeInsets.only(bottom: 85),
|
||||||
|
itemCount: groups.length + 1,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
if (index == groups.length) {
|
||||||
|
return SizedBox(
|
||||||
|
height: MediaQuery.paddingOf(context).bottom - 20,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return GroupTile(group: groups[index]);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
bottom: MediaQuery.paddingOf(context).bottom,
|
||||||
|
child: CustomWidthButton(
|
||||||
|
text: loc.create_group,
|
||||||
|
sizeRelativeToWidth: 0.90,
|
||||||
|
onPressed: () async {
|
||||||
|
await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) {
|
||||||
|
return const CreateGroupView();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
loadGroups();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadGroups() {
|
||||||
|
Future.wait([
|
||||||
|
db.groupDao.getAllGroups(),
|
||||||
|
Future.delayed(Constants.minimumSkeletonDuration),
|
||||||
|
]).then((results) {
|
||||||
|
loadedGroups = results[0] as List<Group>;
|
||||||
|
setState(() {
|
||||||
|
groups = loadedGroups
|
||||||
|
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||||
|
});
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,119 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
|
||||||
import 'package:game_tracker/presentation/views/main_menu/create_group_view.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/group_tile.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
class GroupsView extends StatefulWidget {
|
|
||||||
const GroupsView({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<GroupsView> createState() => _GroupsViewState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _GroupsViewState extends State<GroupsView> {
|
|
||||||
late Future<List<Group>> _allGroupsFuture;
|
|
||||||
late final AppDatabase db;
|
|
||||||
|
|
||||||
final player = Player(name: 'Skeleton Player');
|
|
||||||
late final List<Group> skeletonData = List.filled(
|
|
||||||
7,
|
|
||||||
Group(
|
|
||||||
name: 'Skeleton Game',
|
|
||||||
members: [player, player, player, player, player, player],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
super.initState();
|
|
||||||
db = Provider.of<AppDatabase>(context, listen: false);
|
|
||||||
_allGroupsFuture = Future.delayed(
|
|
||||||
const Duration(milliseconds: 250),
|
|
||||||
() => db.groupDao.getAllGroups(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
|
||||||
body: Stack(
|
|
||||||
alignment: Alignment.center,
|
|
||||||
children: [
|
|
||||||
FutureBuilder<List<Group>>(
|
|
||||||
future: _allGroupsFuture,
|
|
||||||
builder:
|
|
||||||
(BuildContext context, AsyncSnapshot<List<Group>> snapshot) {
|
|
||||||
if (snapshot.hasError) {
|
|
||||||
return const Center(
|
|
||||||
child: TopCenteredMessage(
|
|
||||||
icon: Icons.report,
|
|
||||||
title: 'Error',
|
|
||||||
message: 'Group data couldn\'t\nbe loaded',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (snapshot.connectionState == ConnectionState.done &&
|
|
||||||
(!snapshot.hasData || snapshot.data!.isEmpty)) {
|
|
||||||
return const Center(
|
|
||||||
child: TopCenteredMessage(
|
|
||||||
icon: Icons.info,
|
|
||||||
title: 'Info',
|
|
||||||
message: 'No groups created yet',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final bool isLoading =
|
|
||||||
snapshot.connectionState == ConnectionState.waiting;
|
|
||||||
final List<Group> groups =
|
|
||||||
isLoading ? skeletonData : (snapshot.data ?? [])
|
|
||||||
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
|
||||||
return AppSkeleton(
|
|
||||||
enabled: isLoading,
|
|
||||||
child: ListView.builder(
|
|
||||||
padding: const EdgeInsets.only(bottom: 85),
|
|
||||||
itemCount: groups.length + 1,
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
if (index == groups.length) {
|
|
||||||
return SizedBox(
|
|
||||||
height: MediaQuery.paddingOf(context).bottom - 20,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return GroupTile(group: groups[index]);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
bottom: MediaQuery.paddingOf(context).bottom,
|
|
||||||
child: CustomWidthButton(
|
|
||||||
text: 'Create Group',
|
|
||||||
sizeRelativeToWidth: 0.90,
|
|
||||||
onPressed: () async {
|
|
||||||
await Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(
|
|
||||||
builder: (context) {
|
|
||||||
return const CreateGroupView();
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
setState(() {
|
|
||||||
_allGroupsFuture = db.groupDao.getAllGroups();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/core/constants.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/buttons/quick_create_button.dart';
|
import 'package:game_tracker/presentation/widgets/buttons/quick_create_button.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/game_tile.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/info_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/info_tile.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/tiles/match_summary_tile.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/quick_info_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/quick_info_tile.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
@@ -18,15 +20,22 @@ class HomeView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HomeViewState extends State<HomeView> {
|
class _HomeViewState extends State<HomeView> {
|
||||||
late Future<int> _gameCountFuture;
|
|
||||||
late Future<int> _groupCountFuture;
|
|
||||||
late Future<List<Game>> _recentGamesFuture;
|
|
||||||
bool isLoading = true;
|
bool isLoading = true;
|
||||||
|
|
||||||
late final List<Game> skeletonData = List.filled(
|
/// Amount of matches in the database
|
||||||
|
int matchCount = 0;
|
||||||
|
|
||||||
|
/// Amount of groups in the database
|
||||||
|
int groupCount = 0;
|
||||||
|
|
||||||
|
/// Loaded recent matches from the database
|
||||||
|
List<Match> loadedRecentMatches = [];
|
||||||
|
|
||||||
|
/// Recent matches to display, initially filled with skeleton matches
|
||||||
|
List<Match> recentMatches = List.filled(
|
||||||
2,
|
2,
|
||||||
Game(
|
Match(
|
||||||
name: 'Skeleton Game',
|
name: 'Skeleton Match',
|
||||||
group: Group(
|
group: Group(
|
||||||
name: 'Skeleton Group',
|
name: 'Skeleton Group',
|
||||||
members: [
|
members: [
|
||||||
@@ -39,30 +48,18 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final db = Provider.of<AppDatabase>(context, listen: false);
|
loadHomeViewData();
|
||||||
_gameCountFuture = db.gameDao.getGameCount();
|
|
||||||
_groupCountFuture = db.groupDao.getGroupCount();
|
|
||||||
_recentGamesFuture = db.gameDao.getAllGames();
|
|
||||||
|
|
||||||
Future.wait([_gameCountFuture, _groupCountFuture, _recentGamesFuture]).then(
|
|
||||||
(_) async {
|
|
||||||
await Future.delayed(const Duration(milliseconds: 250));
|
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
isLoading = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
return LayoutBuilder(
|
return LayoutBuilder(
|
||||||
builder: (BuildContext context, BoxConstraints constraints) {
|
builder: (BuildContext context, BoxConstraints constraints) {
|
||||||
return AppSkeleton(
|
return AppSkeleton(
|
||||||
|
fixLayoutBuilder: true,
|
||||||
enabled: isLoading,
|
enabled: isLoading,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -71,38 +68,20 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
FutureBuilder<int>(
|
QuickInfoTile(
|
||||||
future: _gameCountFuture,
|
width: constraints.maxWidth * 0.45,
|
||||||
builder: (context, snapshot) {
|
height: constraints.maxHeight * 0.15,
|
||||||
final int count = (snapshot.hasData)
|
title: loc.matches,
|
||||||
? snapshot.data!
|
icon: Icons.groups_rounded,
|
||||||
: 0;
|
value: matchCount,
|
||||||
return QuickInfoTile(
|
|
||||||
width: constraints.maxWidth * 0.45,
|
|
||||||
height: constraints.maxHeight * 0.15,
|
|
||||||
title: 'Games',
|
|
||||||
icon: Icons.groups_rounded,
|
|
||||||
value: count,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
SizedBox(width: constraints.maxWidth * 0.05),
|
SizedBox(width: constraints.maxWidth * 0.05),
|
||||||
FutureBuilder<int>(
|
QuickInfoTile(
|
||||||
future: _groupCountFuture,
|
width: constraints.maxWidth * 0.45,
|
||||||
builder: (context, snapshot) {
|
height: constraints.maxHeight * 0.15,
|
||||||
final int count =
|
title: loc.groups,
|
||||||
(snapshot.connectionState == ConnectionState.done &&
|
icon: Icons.groups_rounded,
|
||||||
snapshot.hasData)
|
value: groupCount,
|
||||||
? snapshot.data!
|
|
||||||
: 0;
|
|
||||||
return QuickInfoTile(
|
|
||||||
width: constraints.maxWidth * 0.45,
|
|
||||||
height: constraints.maxHeight * 0.15,
|
|
||||||
title: 'Groups',
|
|
||||||
icon: Icons.groups_rounded,
|
|
||||||
value: count,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -110,94 +89,79 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||||
child: InfoTile(
|
child: InfoTile(
|
||||||
width: constraints.maxWidth * 0.95,
|
width: constraints.maxWidth * 0.95,
|
||||||
title: 'Recent Games',
|
title: loc.recent_matches,
|
||||||
icon: Icons.timer,
|
icon: Icons.timer,
|
||||||
content: Padding(
|
content: Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 40.0),
|
padding: const EdgeInsets.symmetric(horizontal: 40.0),
|
||||||
child: FutureBuilder(
|
child: Visibility(
|
||||||
future: _recentGamesFuture,
|
visible: !isLoading && loadedRecentMatches.isNotEmpty,
|
||||||
builder:
|
replacement: Center(
|
||||||
(
|
heightFactor: 12,
|
||||||
BuildContext context,
|
child: Text(
|
||||||
AsyncSnapshot<List<Game>> snapshot,
|
AppLocalizations.of(
|
||||||
) {
|
context,
|
||||||
if (snapshot.hasError) {
|
).no_recent_matches_available,
|
||||||
return const Center(
|
),
|
||||||
heightFactor: 4,
|
),
|
||||||
child: Text(
|
child: Column(
|
||||||
'Error while loading recent games.',
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
),
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
);
|
children: [
|
||||||
}
|
MatchSummaryTile(
|
||||||
final List<Game> games =
|
matchTitle: recentMatches[0].name,
|
||||||
(isLoading
|
game: 'Winner',
|
||||||
? skeletonData
|
ruleset: 'Ruleset',
|
||||||
: (snapshot.data ?? [])
|
players: _getPlayerText(
|
||||||
..sort(
|
recentMatches[0],
|
||||||
(a, b) => b.createdAt.compareTo(
|
context,
|
||||||
a.createdAt,
|
),
|
||||||
),
|
winner: recentMatches[0].winner == null
|
||||||
))
|
? AppLocalizations.of(
|
||||||
.take(2)
|
context,
|
||||||
.toList();
|
).match_in_progress
|
||||||
if (games.isNotEmpty) {
|
: recentMatches[0].winner!.name,
|
||||||
return Column(
|
),
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
const Padding(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
padding: EdgeInsets.symmetric(vertical: 8.0),
|
||||||
children: [
|
child: Divider(),
|
||||||
GameTile(
|
),
|
||||||
gameTitle: games[0].name,
|
if (loadedRecentMatches.length > 1) ...[
|
||||||
gameType: 'Winner',
|
MatchSummaryTile(
|
||||||
ruleset: 'Ruleset',
|
matchTitle: recentMatches[1].name,
|
||||||
players: _getPlayerText(games[0]),
|
game: 'Winner',
|
||||||
winner: games[0].winner == null
|
ruleset: 'Ruleset',
|
||||||
? 'Game in progress...'
|
players: _getPlayerText(
|
||||||
: games[0].winner!.name,
|
recentMatches[1],
|
||||||
),
|
context,
|
||||||
const Padding(
|
),
|
||||||
padding: EdgeInsets.symmetric(
|
winner: recentMatches[1].winner == null
|
||||||
vertical: 8.0,
|
? AppLocalizations.of(
|
||||||
),
|
context,
|
||||||
child: Divider(),
|
).match_in_progress
|
||||||
),
|
: recentMatches[1].winner!.name,
|
||||||
if (games.length > 1) ...[
|
),
|
||||||
GameTile(
|
const SizedBox(height: 8),
|
||||||
gameTitle: games[1].name,
|
] else ...[
|
||||||
gameType: 'Winner',
|
Center(
|
||||||
ruleset: 'Ruleset',
|
heightFactor: 5.35,
|
||||||
players: _getPlayerText(games[1]),
|
child: Text(
|
||||||
winner: games[1].winner == null
|
AppLocalizations.of(
|
||||||
? 'Game in progress...'
|
context,
|
||||||
: games[1].winner!.name,
|
).no_second_match_available,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
),
|
||||||
] else ...[
|
],
|
||||||
const Center(
|
],
|
||||||
heightFactor: 4,
|
),
|
||||||
child: Text(
|
|
||||||
'No second game available.',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return const Center(
|
|
||||||
heightFactor: 12,
|
|
||||||
child: Text('No recent games available.'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
InfoTile(
|
InfoTile(
|
||||||
width: constraints.maxWidth * 0.95,
|
width: constraints.maxWidth * 0.95,
|
||||||
title: 'Quick Create',
|
title: loc.quick_create,
|
||||||
icon: Icons.add_box_rounded,
|
icon: Icons.add_box_rounded,
|
||||||
content: Column(
|
content: Column(
|
||||||
spacing: 8,
|
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||||
@@ -249,10 +213,45 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getPlayerText(Game game) {
|
/// Loads the data for the HomeView from the database.
|
||||||
|
/// This includes the match count, group count, and recent matches.
|
||||||
|
void loadHomeViewData() {
|
||||||
|
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
|
Future.wait([
|
||||||
|
db.matchDao.getMatchCount(),
|
||||||
|
db.groupDao.getGroupCount(),
|
||||||
|
db.matchDao.getAllMatches(),
|
||||||
|
Future.delayed(Constants.minimumSkeletonDuration),
|
||||||
|
]).then((results) {
|
||||||
|
matchCount = results[0] as int;
|
||||||
|
groupCount = results[1] as int;
|
||||||
|
loadedRecentMatches = results[2] as List<Match>;
|
||||||
|
recentMatches =
|
||||||
|
(loadedRecentMatches
|
||||||
|
..sort((a, b) => b.createdAt.compareTo(a.createdAt)))
|
||||||
|
.take(2)
|
||||||
|
.toList();
|
||||||
|
if (loadedRecentMatches.length < 2) {
|
||||||
|
recentMatches.add(
|
||||||
|
Match(name: 'Dummy Match', winner: null, group: null, players: null),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generates a text representation of the players in the match.
|
||||||
|
/// If the match has a group, it returns the group name and the number of additional players.
|
||||||
|
/// If there is no group, it returns the count of players.
|
||||||
|
String _getPlayerText(Match game, context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
if (game.group == null) {
|
if (game.group == null) {
|
||||||
final playerCount = game.players?.length ?? 0;
|
final playerCount = game.players?.length ?? 0;
|
||||||
return '$playerCount Players';
|
return loc.players_count(playerCount);
|
||||||
}
|
}
|
||||||
if (game.players == null || game.players!.isEmpty) {
|
if (game.players == null || game.players!.isEmpty) {
|
||||||
return game.group!.name;
|
return game.group!.name;
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
import 'package:game_tracker/core/enums.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/text_input/custom_search_bar.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/tiles/title_description_list_tile.dart';
|
||||||
|
|
||||||
|
class ChooseGameView extends StatefulWidget {
|
||||||
|
final List<(String, String, Ruleset)> games;
|
||||||
|
final int initialGameIndex;
|
||||||
|
|
||||||
|
const ChooseGameView({
|
||||||
|
super.key,
|
||||||
|
required this.games,
|
||||||
|
required this.initialGameIndex,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ChooseGameView> createState() => _ChooseGameViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ChooseGameViewState extends State<ChooseGameView> {
|
||||||
|
/// Controller for the search bar
|
||||||
|
final TextEditingController searchBarController = TextEditingController();
|
||||||
|
|
||||||
|
/// Currently selected game index
|
||||||
|
late int selectedGameIndex;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
selectedGameIndex = widget.initialGameIndex;
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
|
appBar: AppBar(
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back_ios),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop(selectedGameIndex);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
title: Text(loc.choose_game),
|
||||||
|
),
|
||||||
|
body: PopScope(
|
||||||
|
// This fixes that the Android Back Gesture didn't return the
|
||||||
|
// selectedGameIndex and therefore the selected Game wasn't saved
|
||||||
|
canPop: false,
|
||||||
|
onPopInvokedWithResult: (bool didPop, Object? result) {
|
||||||
|
if (didPop) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Navigator.of(context).pop(selectedGameIndex);
|
||||||
|
},
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
child: CustomSearchBar(
|
||||||
|
controller: searchBarController,
|
||||||
|
hintText: loc.game_name,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 5),
|
||||||
|
Expanded(
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: widget.games.length,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return TitleDescriptionListTile(
|
||||||
|
title: widget.games[index].$1,
|
||||||
|
description: widget.games[index].$2,
|
||||||
|
badgeText: translateRulesetToString(
|
||||||
|
widget.games[index].$3,
|
||||||
|
context,
|
||||||
|
),
|
||||||
|
isHighlighted: selectedGameIndex == index,
|
||||||
|
onPressed: () async {
|
||||||
|
setState(() {
|
||||||
|
if (selectedGameIndex == index) {
|
||||||
|
selectedGameIndex = -1;
|
||||||
|
} else {
|
||||||
|
selectedGameIndex = index;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/text_input/custom_search_bar.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/tiles/group_tile.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
||||||
|
|
||||||
|
class ChooseGroupView extends StatefulWidget {
|
||||||
|
final List<Group> groups;
|
||||||
|
final String initialGroupId;
|
||||||
|
|
||||||
|
const ChooseGroupView({
|
||||||
|
super.key,
|
||||||
|
required this.groups,
|
||||||
|
required this.initialGroupId,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ChooseGroupView> createState() => _ChooseGroupViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ChooseGroupViewState extends State<ChooseGroupView> {
|
||||||
|
late String selectedGroupId;
|
||||||
|
final TextEditingController controller = TextEditingController();
|
||||||
|
late final List<Group> filteredGroups;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
selectedGroupId = widget.initialGroupId;
|
||||||
|
filteredGroups = [...widget.groups];
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
|
appBar: AppBar(
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back_ios),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop(
|
||||||
|
selectedGroupId == ''
|
||||||
|
? null
|
||||||
|
: widget.groups.firstWhere(
|
||||||
|
(group) => group.id == selectedGroupId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
title: Text(loc.choose_group),
|
||||||
|
),
|
||||||
|
body: PopScope(
|
||||||
|
// This fixes that the Android Back Gesture didn't return the
|
||||||
|
// selectedGroupId and therefore the selected Group wasn't saved
|
||||||
|
canPop: false,
|
||||||
|
onPopInvokedWithResult: (bool didPop, Object? result) {
|
||||||
|
if (didPop) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Navigator.of(context).pop(
|
||||||
|
selectedGroupId == ''
|
||||||
|
? null
|
||||||
|
: widget.groups.firstWhere(
|
||||||
|
(group) => group.id == selectedGroupId,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||||
|
child: CustomSearchBar(
|
||||||
|
controller: controller,
|
||||||
|
hintText: loc.search_for_groups,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
filterGroups(value);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Visibility(
|
||||||
|
visible: filteredGroups.isNotEmpty,
|
||||||
|
replacement: Visibility(
|
||||||
|
visible: widget.groups.isNotEmpty,
|
||||||
|
replacement: TopCenteredMessage(
|
||||||
|
icon: Icons.info,
|
||||||
|
title: loc.info,
|
||||||
|
message: loc.no_groups_created_yet,
|
||||||
|
),
|
||||||
|
child: TopCenteredMessage(
|
||||||
|
icon: Icons.info,
|
||||||
|
title: loc.info,
|
||||||
|
message: AppLocalizations.of(
|
||||||
|
context,
|
||||||
|
).there_is_no_group_matching_your_search,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
padding: const EdgeInsets.only(bottom: 85),
|
||||||
|
itemCount: filteredGroups.length,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
if (selectedGroupId != filteredGroups[index].id) {
|
||||||
|
selectedGroupId = filteredGroups[index].id;
|
||||||
|
} else {
|
||||||
|
selectedGroupId = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: GroupTile(
|
||||||
|
group: filteredGroups[index],
|
||||||
|
isHighlighted:
|
||||||
|
selectedGroupId == filteredGroups[index].id,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Filters the groups based on the search [query].
|
||||||
|
void filterGroups(String query) {
|
||||||
|
setState(() {
|
||||||
|
if (query.isEmpty) {
|
||||||
|
filteredGroups.clear();
|
||||||
|
filteredGroups.addAll(widget.groups);
|
||||||
|
} else {
|
||||||
|
filteredGroups.clear();
|
||||||
|
filteredGroups.addAll(
|
||||||
|
widget.groups.where(
|
||||||
|
(group) => group.name.toLowerCase().contains(query.toLowerCase()),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
import 'package:game_tracker/core/enums.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/tiles/title_description_list_tile.dart';
|
||||||
|
|
||||||
|
class ChooseRulesetView extends StatefulWidget {
|
||||||
|
final List<(Ruleset, String)> rulesets;
|
||||||
|
final int initialRulesetIndex;
|
||||||
|
|
||||||
|
const ChooseRulesetView({
|
||||||
|
super.key,
|
||||||
|
required this.rulesets,
|
||||||
|
required this.initialRulesetIndex,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<ChooseRulesetView> createState() => _ChooseRulesetViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ChooseRulesetViewState extends State<ChooseRulesetView> {
|
||||||
|
/// Currently selected ruleset index
|
||||||
|
late int selectedRulesetIndex;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
selectedRulesetIndex = widget.initialRulesetIndex;
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
return DefaultTabController(
|
||||||
|
length: 2,
|
||||||
|
initialIndex: 0,
|
||||||
|
child: Scaffold(
|
||||||
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
|
appBar: AppBar(
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back_ios),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop(
|
||||||
|
selectedRulesetIndex == -1
|
||||||
|
? null
|
||||||
|
: widget.rulesets[selectedRulesetIndex].$1,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
title: Text(loc.choose_ruleset),
|
||||||
|
),
|
||||||
|
body: PopScope(
|
||||||
|
// This fixes that the Android Back Gesture didn't return the
|
||||||
|
// selectedRulesetIndex and therefore the selected Ruleset wasn't saved
|
||||||
|
canPop: false,
|
||||||
|
onPopInvokedWithResult: (bool didPop, Object? result) {
|
||||||
|
if (didPop) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Navigator.of(context).pop(
|
||||||
|
selectedRulesetIndex == -1
|
||||||
|
? null
|
||||||
|
: widget.rulesets[selectedRulesetIndex].$1,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: ListView.builder(
|
||||||
|
padding: const EdgeInsets.only(bottom: 85),
|
||||||
|
itemCount: widget.rulesets.length,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return TitleDescriptionListTile(
|
||||||
|
onPressed: () async {
|
||||||
|
setState(() {
|
||||||
|
if (selectedRulesetIndex == index) {
|
||||||
|
selectedRulesetIndex = -1;
|
||||||
|
} else {
|
||||||
|
selectedRulesetIndex = index;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
title: translateRulesetToString(
|
||||||
|
widget.rulesets[index].$1,
|
||||||
|
context,
|
||||||
|
),
|
||||||
|
description: widget.rulesets[index].$2,
|
||||||
|
isHighlighted: selectedRulesetIndex == index,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,271 @@
|
|||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
import 'package:game_tracker/core/enums.dart';
|
||||||
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
|
import 'package:game_tracker/presentation/views/main_menu/match_view/create_match/choose_game_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/views/main_menu/match_view/create_match/choose_group_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/views/main_menu/match_view/create_match/choose_ruleset_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/views/main_menu/match_view/match_result_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/player_selection.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/text_input/text_input_field.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/tiles/choose_tile.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class CreateMatchView extends StatefulWidget {
|
||||||
|
final VoidCallback? onWinnerChanged;
|
||||||
|
const CreateMatchView({super.key, this.onWinnerChanged});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CreateMatchView> createState() => _CreateMatchViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CreateMatchViewState extends State<CreateMatchView> {
|
||||||
|
late final AppDatabase db;
|
||||||
|
|
||||||
|
/// Controller for the match name input field
|
||||||
|
final TextEditingController _matchNameController = TextEditingController();
|
||||||
|
|
||||||
|
/// Hint text for the match name input field
|
||||||
|
String? hintText;
|
||||||
|
|
||||||
|
/// List of all groups from the database
|
||||||
|
List<Group> groupsList = [];
|
||||||
|
|
||||||
|
/// List of all players from the database
|
||||||
|
List<Player> playerList = [];
|
||||||
|
|
||||||
|
/// List of players filtered based on the selected group
|
||||||
|
/// If a group is selected, this list contains all players from [playerList]
|
||||||
|
/// who are not members of the selected group. If no group is selected,
|
||||||
|
/// this list is identical to [playerList].
|
||||||
|
List<Player> filteredPlayerList = [];
|
||||||
|
|
||||||
|
/// The currently selected group
|
||||||
|
Group? selectedGroup;
|
||||||
|
|
||||||
|
/// The index of the currently selected group in [groupsList] to mark it in
|
||||||
|
/// the [ChooseGroupView]
|
||||||
|
String selectedGroupId = '';
|
||||||
|
|
||||||
|
/// The currently selected ruleset
|
||||||
|
Ruleset? selectedRuleset;
|
||||||
|
|
||||||
|
/// The index of the currently selected ruleset in [rulesets] to mark it in
|
||||||
|
/// the [ChooseRulesetView]
|
||||||
|
int selectedRulesetIndex = -1;
|
||||||
|
|
||||||
|
/// The index of the currently selected game in [games] to mark it in
|
||||||
|
/// the [ChooseGameView]
|
||||||
|
int selectedGameIndex = -1;
|
||||||
|
|
||||||
|
/// The currently selected players
|
||||||
|
List<Player>? selectedPlayers;
|
||||||
|
|
||||||
|
/// List of available rulesets with their localized string representations
|
||||||
|
late final List<(Ruleset, String)> _rulesets;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_matchNameController.addListener(() {
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
|
||||||
|
db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
|
|
||||||
|
Future.wait([
|
||||||
|
db.groupDao.getAllGroups(),
|
||||||
|
db.playerDao.getAllPlayers(),
|
||||||
|
]).then((result) async {
|
||||||
|
groupsList = result[0] as List<Group>;
|
||||||
|
playerList = result[1] as List<Player>;
|
||||||
|
setState(() {
|
||||||
|
filteredPlayerList = List.from(playerList);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_matchNameController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
hintText ??= loc.match_name;
|
||||||
|
_rulesets = [
|
||||||
|
(Ruleset.singleWinner, loc.ruleset_single_winner),
|
||||||
|
(Ruleset.singleLoser, loc.ruleset_single_loser),
|
||||||
|
(Ruleset.mostPoints, loc.ruleset_most_points),
|
||||||
|
(Ruleset.leastPoints, loc.ruleset_least_points),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Replace when games are implemented
|
||||||
|
List<(String, String, Ruleset)> games = [
|
||||||
|
('Example Game 1', 'This is a description', Ruleset.leastPoints),
|
||||||
|
('Example Game 2', '', Ruleset.singleWinner),
|
||||||
|
];
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
|
appBar: AppBar(title: Text(loc.create_new_match)),
|
||||||
|
body: SafeArea(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
margin: CustomTheme.tileMargin,
|
||||||
|
child: TextInputField(
|
||||||
|
controller: _matchNameController,
|
||||||
|
hintText: hintText ?? '',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ChooseTile(
|
||||||
|
title: loc.game,
|
||||||
|
trailingText: selectedGameIndex == -1
|
||||||
|
? loc.none
|
||||||
|
: games[selectedGameIndex].$1,
|
||||||
|
onPressed: () async {
|
||||||
|
selectedGameIndex = await Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => ChooseGameView(
|
||||||
|
games: games,
|
||||||
|
initialGameIndex: selectedGameIndex,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
if (selectedGameIndex != -1) {
|
||||||
|
hintText = games[selectedGameIndex].$1;
|
||||||
|
selectedRuleset = games[selectedGameIndex].$3;
|
||||||
|
selectedRulesetIndex = _rulesets.indexWhere(
|
||||||
|
(r) => r.$1 == selectedRuleset,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
hintText = loc.match_name;
|
||||||
|
selectedRuleset = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ChooseTile(
|
||||||
|
title: loc.ruleset,
|
||||||
|
trailingText: selectedRuleset == null
|
||||||
|
? loc.none
|
||||||
|
: translateRulesetToString(selectedRuleset!, context),
|
||||||
|
onPressed: () async {
|
||||||
|
selectedRuleset = await Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => ChooseRulesetView(
|
||||||
|
rulesets: _rulesets,
|
||||||
|
initialRulesetIndex: selectedRulesetIndex,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (!mounted) return;
|
||||||
|
selectedRulesetIndex = _rulesets.indexWhere(
|
||||||
|
(r) => r.$1 == selectedRuleset,
|
||||||
|
);
|
||||||
|
selectedGameIndex = -1;
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
ChooseTile(
|
||||||
|
title: loc.group,
|
||||||
|
trailingText: selectedGroup == null
|
||||||
|
? loc.none_group
|
||||||
|
: selectedGroup!.name,
|
||||||
|
onPressed: () async {
|
||||||
|
selectedGroup = await Navigator.of(context).push(
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) => ChooseGroupView(
|
||||||
|
groups: groupsList,
|
||||||
|
initialGroupId: selectedGroupId,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
selectedGroupId = selectedGroup?.id ?? '';
|
||||||
|
if (selectedGroup != null) {
|
||||||
|
filteredPlayerList = playerList
|
||||||
|
.where(
|
||||||
|
(p) => !selectedGroup!.members.any((m) => m.id == p.id),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
} else {
|
||||||
|
filteredPlayerList = List.from(playerList);
|
||||||
|
}
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: PlayerSelection(
|
||||||
|
key: ValueKey(selectedGroup?.id ?? 'no_group'),
|
||||||
|
initialSelectedPlayers: selectedPlayers ?? [],
|
||||||
|
availablePlayers: filteredPlayerList,
|
||||||
|
onChanged: (value) {
|
||||||
|
setState(() {
|
||||||
|
selectedPlayers = value;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
CustomWidthButton(
|
||||||
|
text: loc.create_match,
|
||||||
|
sizeRelativeToWidth: 0.95,
|
||||||
|
buttonType: ButtonType.primary,
|
||||||
|
onPressed: _enableCreateGameButton()
|
||||||
|
? () async {
|
||||||
|
Match match = Match(
|
||||||
|
name: _matchNameController.text.isEmpty
|
||||||
|
? (hintText ?? '')
|
||||||
|
: _matchNameController.text.trim(),
|
||||||
|
createdAt: DateTime.now(),
|
||||||
|
group: selectedGroup,
|
||||||
|
players: selectedPlayers,
|
||||||
|
);
|
||||||
|
await db.matchDao.addMatch(match: match);
|
||||||
|
if (context.mounted) {
|
||||||
|
Navigator.pushReplacement(
|
||||||
|
context,
|
||||||
|
CupertinoPageRoute(
|
||||||
|
fullscreenDialog: true,
|
||||||
|
builder: (context) => MatchResultView(
|
||||||
|
match: match,
|
||||||
|
onWinnerChanged: widget.onWinnerChanged,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Determines whether the "Create Match" button should be enabled.
|
||||||
|
///
|
||||||
|
/// Returns `true` if:
|
||||||
|
/// - A ruleset is selected AND
|
||||||
|
/// - Either a group is selected OR at least 2 players are selected
|
||||||
|
bool _enableCreateGameButton() {
|
||||||
|
return (selectedGroup != null ||
|
||||||
|
(selectedPlayers != null && selectedPlayers!.length > 1)) &&
|
||||||
|
selectedRuleset != null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,32 +1,38 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/custom_radio_list_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/custom_radio_list_tile.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class GameResultView extends StatefulWidget {
|
class MatchResultView extends StatefulWidget {
|
||||||
final Game game;
|
final Match match;
|
||||||
|
|
||||||
const GameResultView({super.key, required this.game});
|
final VoidCallback? onWinnerChanged;
|
||||||
|
|
||||||
|
const MatchResultView({super.key, required this.match, this.onWinnerChanged});
|
||||||
@override
|
@override
|
||||||
State<GameResultView> createState() => _GameResultViewState();
|
State<MatchResultView> createState() => _MatchResultViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _GameResultViewState extends State<GameResultView> {
|
class _MatchResultViewState extends State<MatchResultView> {
|
||||||
late final List<Player> allPlayers;
|
|
||||||
late final AppDatabase db;
|
late final AppDatabase db;
|
||||||
|
|
||||||
|
/// List of all players who participated in the match
|
||||||
|
late final List<Player> allPlayers;
|
||||||
|
|
||||||
|
/// Currently selected winner player
|
||||||
Player? _selectedPlayer;
|
Player? _selectedPlayer;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
db = Provider.of<AppDatabase>(context, listen: false);
|
db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
allPlayers = getAllPlayers(widget.game);
|
allPlayers = getAllPlayers(widget.match);
|
||||||
if (widget.game.winner != null) {
|
if (widget.match.winner != null) {
|
||||||
_selectedPlayer = allPlayers.firstWhere(
|
_selectedPlayer = allPlayers.firstWhere(
|
||||||
(p) => p.id == widget.game.winner!.id,
|
(p) => p.id == widget.match.winner!.id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -34,20 +40,18 @@ class _GameResultViewState extends State<GameResultView> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
leading: IconButton(
|
||||||
scrolledUnderElevation: 0,
|
icon: const Icon(Icons.close),
|
||||||
title: Text(
|
onPressed: () {
|
||||||
widget.game.name,
|
widget.onWinnerChanged?.call();
|
||||||
style: const TextStyle(
|
Navigator.of(context).pop();
|
||||||
fontSize: 20,
|
},
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
centerTitle: true,
|
title: Text(widget.match.name),
|
||||||
),
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -71,9 +75,9 @@ class _GameResultViewState extends State<GameResultView> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Text(
|
Text(
|
||||||
'Select Winner:',
|
loc.select_winner,
|
||||||
style: TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
@@ -122,23 +126,36 @@ class _GameResultViewState extends State<GameResultView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Handles saving or removing the winner in the database
|
||||||
|
/// based on the current selection.
|
||||||
Future<void> _handleWinnerSaving() async {
|
Future<void> _handleWinnerSaving() async {
|
||||||
if (_selectedPlayer == null) {
|
if (_selectedPlayer == null) {
|
||||||
await db.gameDao.removeWinner(gameId: widget.game.id);
|
await db.matchDao.removeWinner(matchId: widget.match.id);
|
||||||
} else {
|
} else {
|
||||||
await db.gameDao.setWinner(
|
await db.matchDao.setWinner(
|
||||||
gameId: widget.game.id,
|
matchId: widget.match.id,
|
||||||
winnerId: _selectedPlayer!.id,
|
winnerId: _selectedPlayer!.id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
widget.onWinnerChanged?.call();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Player> getAllPlayers(Game game) {
|
/// Retrieves all players associated with the given [match].
|
||||||
if (game.group == null && game.players != null) {
|
/// This includes players directly assigned to the match
|
||||||
return [...game.players!];
|
/// as well as members of the group (if any).
|
||||||
} else if (game.group != null && game.players != null) {
|
/// The returned list is sorted alphabetically by player name.
|
||||||
return [...game.players!, ...game.group!.members];
|
List<Player> getAllPlayers(Match match) {
|
||||||
|
List<Player> players = [];
|
||||||
|
|
||||||
|
if (match.group == null && match.players != null) {
|
||||||
|
players = [...match.players!];
|
||||||
|
} else if (match.group != null && match.players != null) {
|
||||||
|
players = [...match.players!, ...match.group!.members];
|
||||||
|
} else {
|
||||||
|
players = [...match.group!.members];
|
||||||
}
|
}
|
||||||
return [...game.group!.members];
|
|
||||||
|
players.sort((a, b) => a.name.compareTo(b.name));
|
||||||
|
return players;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
137
lib/presentation/views/main_menu/match_view/match_view.dart
Normal file
137
lib/presentation/views/main_menu/match_view/match_view.dart
Normal file
@@ -0,0 +1,137 @@
|
|||||||
|
import 'dart:core' hide Match;
|
||||||
|
|
||||||
|
import 'package:flutter/cupertino.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/core/constants.dart';
|
||||||
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
|
import 'package:game_tracker/presentation/views/main_menu/match_view/create_match/create_match_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/views/main_menu/match_view/match_result_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/tiles/match_tile.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
class MatchView extends StatefulWidget {
|
||||||
|
const MatchView({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MatchView> createState() => _MatchViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MatchViewState extends State<MatchView> {
|
||||||
|
late final AppDatabase db;
|
||||||
|
bool isLoading = true;
|
||||||
|
|
||||||
|
/// Loaded matches from the database,
|
||||||
|
/// initially filled with skeleton matches
|
||||||
|
List<Match> matches = List.filled(
|
||||||
|
4,
|
||||||
|
Match(
|
||||||
|
name: 'Skeleton match name',
|
||||||
|
group: Group(
|
||||||
|
name: 'Group name',
|
||||||
|
members: List.filled(5, Player(name: 'Player')),
|
||||||
|
),
|
||||||
|
winner: Player(name: 'Player'),
|
||||||
|
players: [Player(name: 'Player')],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
|
loadGames();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
|
body: Stack(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
children: [
|
||||||
|
AppSkeleton(
|
||||||
|
enabled: isLoading,
|
||||||
|
child: Visibility(
|
||||||
|
visible: matches.isNotEmpty,
|
||||||
|
replacement: Center(
|
||||||
|
child: TopCenteredMessage(
|
||||||
|
icon: Icons.report,
|
||||||
|
title: loc.info,
|
||||||
|
message: loc.no_matches_created_yet,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
padding: const EdgeInsets.only(bottom: 85),
|
||||||
|
itemCount: matches.length + 1,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
if (index == matches.length) {
|
||||||
|
return SizedBox(
|
||||||
|
height: MediaQuery.paddingOf(context).bottom - 20,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return MatchTile(
|
||||||
|
onTap: () async {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
CupertinoPageRoute(
|
||||||
|
fullscreenDialog: true,
|
||||||
|
builder: (context) => MatchResultView(
|
||||||
|
match: matches[index],
|
||||||
|
onWinnerChanged: loadGames,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
match: matches[index],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
bottom: MediaQuery.paddingOf(context).bottom,
|
||||||
|
child: CustomWidthButton(
|
||||||
|
text: loc.create_match,
|
||||||
|
sizeRelativeToWidth: 0.90,
|
||||||
|
onPressed: () async {
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
CreateMatchView(onWinnerChanged: loadGames),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Loads the games from the database and sorts them by creation date.
|
||||||
|
void loadGames() {
|
||||||
|
Future.wait([
|
||||||
|
db.matchDao.getAllMatches(),
|
||||||
|
Future.delayed(Constants.minimumSkeletonDuration),
|
||||||
|
]).then((results) {
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
final loadedMatches = results[0] as List<Match>;
|
||||||
|
matches = loadedMatches
|
||||||
|
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
import 'package:game_tracker/core/enums.dart';
|
import 'package:game_tracker/core/enums.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/settings_list_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/settings_list_tile.dart';
|
||||||
import 'package:game_tracker/services/data_transfer_service.dart';
|
import 'package:game_tracker/services/data_transfer_service.dart';
|
||||||
|
|
||||||
@@ -12,8 +13,14 @@ class SettingsView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _SettingsViewState extends State<SettingsView> {
|
class _SettingsViewState extends State<SettingsView> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(backgroundColor: CustomTheme.backgroundColor),
|
appBar: AppBar(backgroundColor: CustomTheme.backgroundColor),
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
@@ -24,31 +31,34 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
const Padding(
|
Padding(
|
||||||
padding: EdgeInsets.fromLTRB(24, 0, 24, 10),
|
padding: const EdgeInsets.fromLTRB(24, 0, 24, 10),
|
||||||
child: Text(
|
child: Text(
|
||||||
textAlign: TextAlign.start,
|
textAlign: TextAlign.start,
|
||||||
'Menu',
|
loc.menu,
|
||||||
style: TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 28,
|
fontSize: 28,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Padding(
|
Padding(
|
||||||
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 10),
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 24,
|
||||||
|
vertical: 10,
|
||||||
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
textAlign: TextAlign.start,
|
textAlign: TextAlign.start,
|
||||||
'Settings',
|
loc.settings,
|
||||||
style: TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 22,
|
fontSize: 22,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
SettingsListTile(
|
SettingsListTile(
|
||||||
title: 'Export data',
|
title: loc.export_data,
|
||||||
icon: Icons.upload_outlined,
|
icon: Icons.upload_rounded,
|
||||||
suffixWidget: const Icon(Icons.arrow_forward_ios, size: 16),
|
suffixWidget: const Icon(Icons.arrow_forward_ios, size: 16),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final String json =
|
final String json =
|
||||||
@@ -62,8 +72,8 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
SettingsListTile(
|
SettingsListTile(
|
||||||
title: 'Import data',
|
title: loc.import_data,
|
||||||
icon: Icons.download_outlined,
|
icon: Icons.download_rounded,
|
||||||
suffixWidget: const Icon(Icons.arrow_forward_ios, size: 16),
|
suffixWidget: const Icon(Icons.arrow_forward_ios, size: 16),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
final result = await DataTransferService.importData(
|
final result = await DataTransferService.importData(
|
||||||
@@ -74,23 +84,23 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
SettingsListTile(
|
SettingsListTile(
|
||||||
title: 'Delete all data',
|
title: loc.delete_all_data,
|
||||||
icon: Icons.download_outlined,
|
icon: Icons.delete_rounded,
|
||||||
suffixWidget: const Icon(Icons.arrow_forward_ios, size: 16),
|
suffixWidget: const Icon(Icons.arrow_forward_ios, size: 16),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
showDialog<bool>(
|
showDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: const Text('Delete all data?'),
|
title: Text(loc.delete_all_data),
|
||||||
content: const Text('This can\'t be undone'),
|
content: Text(loc.this_cannot_be_undone),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(false),
|
onPressed: () => Navigator.of(context).pop(false),
|
||||||
child: const Text('Abbrechen'),
|
child: Text(loc.cancel),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(true),
|
onPressed: () => Navigator.of(context).pop(true),
|
||||||
child: const Text('Löschen'),
|
child: Text(loc.delete),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -99,7 +109,9 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
DataTransferService.deleteAllData(context);
|
DataTransferService.deleteAllData(context);
|
||||||
showSnackbar(
|
showSnackbar(
|
||||||
context: context,
|
context: context,
|
||||||
message: 'Daten erfolgreich gelöscht',
|
message: AppLocalizations.of(
|
||||||
|
context,
|
||||||
|
).data_successfully_deleted,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -120,25 +132,20 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required ImportResult result,
|
required ImportResult result,
|
||||||
}) {
|
}) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case ImportResult.success:
|
case ImportResult.success:
|
||||||
showSnackbar(context: context, message: 'Data successfully imported');
|
showSnackbar(context: context, message: loc.data_successfully_imported);
|
||||||
case ImportResult.invalidSchema:
|
case ImportResult.invalidSchema:
|
||||||
showSnackbar(context: context, message: 'Invalid Schema');
|
showSnackbar(context: context, message: loc.invalid_schema);
|
||||||
case ImportResult.fileReadError:
|
case ImportResult.fileReadError:
|
||||||
showSnackbar(context: context, message: 'Error reading file');
|
showSnackbar(context: context, message: loc.error_reading_file);
|
||||||
case ImportResult.canceled:
|
case ImportResult.canceled:
|
||||||
showSnackbar(context: context, message: 'Import canceled');
|
showSnackbar(context: context, message: loc.import_canceled);
|
||||||
case ImportResult.formatException:
|
case ImportResult.formatException:
|
||||||
showSnackbar(
|
showSnackbar(context: context, message: loc.format_exception);
|
||||||
context: context,
|
|
||||||
message: 'Format Exception (see console)',
|
|
||||||
);
|
|
||||||
case ImportResult.unknownException:
|
case ImportResult.unknownException:
|
||||||
showSnackbar(
|
showSnackbar(context: context, message: loc.unknown_exception);
|
||||||
context: context,
|
|
||||||
message: 'Unknown Exception (see console)',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,16 +157,14 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
required BuildContext context,
|
required BuildContext context,
|
||||||
required ExportResult result,
|
required ExportResult result,
|
||||||
}) {
|
}) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case ExportResult.success:
|
case ExportResult.success:
|
||||||
showSnackbar(context: context, message: 'Data successfully exported');
|
showSnackbar(context: context, message: loc.data_successfully_exported);
|
||||||
case ExportResult.canceled:
|
case ExportResult.canceled:
|
||||||
showSnackbar(context: context, message: 'Export canceled');
|
showSnackbar(context: context, message: loc.export_canceled);
|
||||||
case ExportResult.unknownException:
|
case ExportResult.unknownException:
|
||||||
showSnackbar(
|
showSnackbar(context: context, message: loc.unknown_exception);
|
||||||
context: context,
|
|
||||||
message: 'Unknown Exception (see console)',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +180,7 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
Duration duration = const Duration(seconds: 3),
|
Duration duration = const Duration(seconds: 3),
|
||||||
VoidCallback? action,
|
VoidCallback? action,
|
||||||
}) {
|
}) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
final messenger = ScaffoldMessenger.of(context);
|
final messenger = ScaffoldMessenger.of(context);
|
||||||
messenger.hideCurrentSnackBar();
|
messenger.hideCurrentSnackBar();
|
||||||
messenger.showSnackBar(
|
messenger.showSnackBar(
|
||||||
@@ -183,7 +189,7 @@ class _SettingsViewState extends State<SettingsView> {
|
|||||||
backgroundColor: CustomTheme.onBoxColor,
|
backgroundColor: CustomTheme.onBoxColor,
|
||||||
duration: duration,
|
duration: duration,
|
||||||
action: action != null
|
action: action != null
|
||||||
? SnackBarAction(label: 'Rückgängig', onPressed: action)
|
? SnackBarAction(label: loc.undo, onPressed: action)
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/core/constants.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/statistics_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/statistics_tile.dart';
|
||||||
|
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class StatisticsView extends StatefulWidget {
|
class StatisticsView extends StatefulWidget {
|
||||||
@@ -14,37 +17,20 @@ class StatisticsView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _StatisticsViewState extends State<StatisticsView> {
|
class _StatisticsViewState extends State<StatisticsView> {
|
||||||
late Future<List<Game>> _gamesFuture;
|
|
||||||
late Future<List<Player>> _playersFuture;
|
|
||||||
List<(String, int)> winCounts = List.filled(6, ('Skeleton Player', 1));
|
List<(String, int)> winCounts = List.filled(6, ('Skeleton Player', 1));
|
||||||
List<(String, int)> gameCounts = List.filled(6, ('Skeleton Player', 1));
|
List<(String, int)> matchCounts = List.filled(6, ('Skeleton Player', 1));
|
||||||
List<(String, double)> winRates = List.filled(6, ('Skeleton Player', 1));
|
List<(String, double)> winRates = List.filled(6, ('Skeleton Player', 1));
|
||||||
bool isLoading = true;
|
bool isLoading = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
final db = Provider.of<AppDatabase>(context, listen: false);
|
loadStatisticData();
|
||||||
_gamesFuture = db.gameDao.getAllGames();
|
|
||||||
_playersFuture = db.playerDao.getAllPlayers();
|
|
||||||
|
|
||||||
Future.wait([_gamesFuture, _playersFuture]).then((results) async {
|
|
||||||
await Future.delayed(const Duration(milliseconds: 250));
|
|
||||||
final games = results[0] as List<Game>;
|
|
||||||
final players = results[1] as List<Player>;
|
|
||||||
winCounts = _calculateWinsForAllPlayers(games, players);
|
|
||||||
gameCounts = _calculateGameAmountsForAllPlayers(games, players);
|
|
||||||
winRates = computeWinRatePercent(wins: winCounts, games: gameCounts);
|
|
||||||
if (mounted) {
|
|
||||||
setState(() {
|
|
||||||
isLoading = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
return LayoutBuilder(
|
return LayoutBuilder(
|
||||||
builder: (BuildContext context, BoxConstraints constraints) {
|
builder: (BuildContext context, BoxConstraints constraints) {
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
@@ -58,31 +44,48 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(height: constraints.maxHeight * 0.01),
|
SizedBox(height: constraints.maxHeight * 0.01),
|
||||||
StatisticsTile(
|
Visibility(
|
||||||
icon: Icons.sports_score,
|
visible:
|
||||||
title: 'Wins per Player',
|
winCounts.isEmpty &&
|
||||||
width: constraints.maxWidth * 0.95,
|
matchCounts.isEmpty &&
|
||||||
values: winCounts,
|
winRates.isEmpty,
|
||||||
itemCount: 3,
|
replacement: Column(
|
||||||
barColor: Colors.blue,
|
children: [
|
||||||
),
|
StatisticsTile(
|
||||||
SizedBox(height: constraints.maxHeight * 0.02),
|
icon: Icons.sports_score,
|
||||||
StatisticsTile(
|
title: loc.wins,
|
||||||
icon: Icons.percent,
|
width: constraints.maxWidth * 0.95,
|
||||||
title: 'Winrate per Player',
|
values: winCounts,
|
||||||
width: constraints.maxWidth * 0.95,
|
itemCount: 3,
|
||||||
values: winRates,
|
barColor: Colors.green,
|
||||||
itemCount: 5,
|
),
|
||||||
barColor: Colors.orange[700]!,
|
SizedBox(height: constraints.maxHeight * 0.02),
|
||||||
),
|
StatisticsTile(
|
||||||
SizedBox(height: constraints.maxHeight * 0.02),
|
icon: Icons.percent,
|
||||||
StatisticsTile(
|
title: loc.winrate,
|
||||||
icon: Icons.casino,
|
width: constraints.maxWidth * 0.95,
|
||||||
title: 'Games per Player',
|
values: winRates,
|
||||||
width: constraints.maxWidth * 0.95,
|
itemCount: 5,
|
||||||
values: gameCounts,
|
barColor: Colors.orange[700]!,
|
||||||
itemCount: 10,
|
),
|
||||||
barColor: Colors.green,
|
SizedBox(height: constraints.maxHeight * 0.02),
|
||||||
|
StatisticsTile(
|
||||||
|
icon: Icons.casino,
|
||||||
|
title: loc.amount_of_matches,
|
||||||
|
width: constraints.maxWidth * 0.95,
|
||||||
|
values: matchCounts,
|
||||||
|
itemCount: 10,
|
||||||
|
barColor: Colors.blue,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: TopCenteredMessage(
|
||||||
|
icon: Icons.info,
|
||||||
|
title: loc.info,
|
||||||
|
message: AppLocalizations.of(
|
||||||
|
context,
|
||||||
|
).no_statistics_available,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: MediaQuery.paddingOf(context).bottom),
|
SizedBox(height: MediaQuery.paddingOf(context).bottom),
|
||||||
],
|
],
|
||||||
@@ -94,17 +97,49 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Loads matches and players from the database
|
||||||
|
/// and calculates statistics for each player
|
||||||
|
void loadStatisticData() {
|
||||||
|
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
|
|
||||||
|
Future.wait([
|
||||||
|
db.matchDao.getAllMatches(),
|
||||||
|
db.playerDao.getAllPlayers(),
|
||||||
|
Future.delayed(Constants.minimumSkeletonDuration),
|
||||||
|
]).then((results) async {
|
||||||
|
if (!mounted) return;
|
||||||
|
final matches = results[0] as List<Match>;
|
||||||
|
final players = results[1] as List<Player>;
|
||||||
|
winCounts = _calculateWinsForAllPlayers(
|
||||||
|
matches: matches,
|
||||||
|
players: players,
|
||||||
|
context: context,
|
||||||
|
);
|
||||||
|
matchCounts = _calculateMatchAmountsForAllPlayers(
|
||||||
|
matches: matches,
|
||||||
|
players: players,
|
||||||
|
context: context,
|
||||||
|
);
|
||||||
|
winRates = computeWinRatePercent(wins: winCounts, matches: matchCounts);
|
||||||
|
setState(() {
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// Calculates the number of wins for each player
|
/// Calculates the number of wins for each player
|
||||||
/// and returns a sorted list of tuples (playerName, winCount)
|
/// and returns a sorted list of tuples (playerName, winCount)
|
||||||
List<(String, int)> _calculateWinsForAllPlayers(
|
List<(String, int)> _calculateWinsForAllPlayers({
|
||||||
List<Game> games,
|
required List<Match> matches,
|
||||||
List<Player> players,
|
required List<Player> players,
|
||||||
) {
|
required BuildContext context,
|
||||||
|
}) {
|
||||||
List<(String, int)> winCounts = [];
|
List<(String, int)> winCounts = [];
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
|
||||||
// Getting the winners
|
// Getting the winners
|
||||||
for (var game in games) {
|
for (var match in matches) {
|
||||||
final winner = game.winner;
|
final winner = match.winner;
|
||||||
if (winner != null) {
|
if (winner != null) {
|
||||||
final index = winCounts.indexWhere((entry) => entry.$1 == winner.id);
|
final index = winCounts.indexWhere((entry) => entry.$1 == winner.id);
|
||||||
// -1 means winner not found in winCounts
|
// -1 means winner not found in winCounts
|
||||||
@@ -131,7 +166,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
final playerId = winCounts[i].$1;
|
final playerId = winCounts[i].$1;
|
||||||
final player = players.firstWhere(
|
final player = players.firstWhere(
|
||||||
(p) => p.id == playerId,
|
(p) => p.id == playerId,
|
||||||
orElse: () => Player(id: playerId, name: 'N.a.'),
|
orElse: () => Player(id: playerId, name: loc.not_available),
|
||||||
);
|
);
|
||||||
winCounts[i] = (player.name, winCounts[i].$2);
|
winCounts[i] = (player.name, winCounts[i].$2);
|
||||||
}
|
}
|
||||||
@@ -141,83 +176,85 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
return winCounts;
|
return winCounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculates the number of games played for each player
|
/// Calculates the number of matches played for each player
|
||||||
/// and returns a sorted list of tuples (playerName, gameCount)
|
/// and returns a sorted list of tuples (playerName, matchCount)
|
||||||
List<(String, int)> _calculateGameAmountsForAllPlayers(
|
List<(String, int)> _calculateMatchAmountsForAllPlayers({
|
||||||
List<Game> games,
|
required List<Match> matches,
|
||||||
List<Player> players,
|
required List<Player> players,
|
||||||
) {
|
required BuildContext context,
|
||||||
List<(String, int)> gameCounts = [];
|
}) {
|
||||||
|
List<(String, int)> matchCounts = [];
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
|
||||||
// Counting games for each player
|
// Counting matches for each player
|
||||||
for (var game in games) {
|
for (var match in matches) {
|
||||||
if (game.group != null) {
|
if (match.group != null) {
|
||||||
final members = game.group!.members.map((p) => p.id).toList();
|
final members = match.group!.members.map((p) => p.id).toList();
|
||||||
for (var playerId in members) {
|
for (var playerId in members) {
|
||||||
final index = gameCounts.indexWhere((entry) => entry.$1 == playerId);
|
final index = matchCounts.indexWhere((entry) => entry.$1 == playerId);
|
||||||
// -1 means player not found in gameCounts
|
// -1 means player not found in matchCounts
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
final current = gameCounts[index].$2;
|
final current = matchCounts[index].$2;
|
||||||
gameCounts[index] = (playerId, current + 1);
|
matchCounts[index] = (playerId, current + 1);
|
||||||
} else {
|
} else {
|
||||||
gameCounts.add((playerId, 1));
|
matchCounts.add((playerId, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (game.players != null) {
|
if (match.players != null) {
|
||||||
final members = game.players!.map((p) => p.id).toList();
|
final members = match.players!.map((p) => p.id).toList();
|
||||||
for (var playerId in members) {
|
for (var playerId in members) {
|
||||||
final index = gameCounts.indexWhere((entry) => entry.$1 == playerId);
|
final index = matchCounts.indexWhere((entry) => entry.$1 == playerId);
|
||||||
// -1 means player not found in gameCounts
|
// -1 means player not found in matchCounts
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
final current = gameCounts[index].$2;
|
final current = matchCounts[index].$2;
|
||||||
gameCounts[index] = (playerId, current + 1);
|
matchCounts[index] = (playerId, current + 1);
|
||||||
} else {
|
} else {
|
||||||
gameCounts.add((playerId, 1));
|
matchCounts.add((playerId, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adding all players with zero games
|
// Adding all players with zero matches
|
||||||
for (var player in players) {
|
for (var player in players) {
|
||||||
final index = gameCounts.indexWhere((entry) => entry.$1 == player.id);
|
final index = matchCounts.indexWhere((entry) => entry.$1 == player.id);
|
||||||
// -1 means player not found in gameCounts
|
// -1 means player not found in matchCounts
|
||||||
if (index == -1) {
|
if (index == -1) {
|
||||||
gameCounts.add((player.id, 0));
|
matchCounts.add((player.id, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace player IDs with names
|
// Replace player IDs with names
|
||||||
for (int i = 0; i < gameCounts.length; i++) {
|
for (int i = 0; i < matchCounts.length; i++) {
|
||||||
final playerId = gameCounts[i].$1;
|
final playerId = matchCounts[i].$1;
|
||||||
final player = players.firstWhere(
|
final player = players.firstWhere(
|
||||||
(p) => p.id == playerId,
|
(p) => p.id == playerId,
|
||||||
orElse: () => Player(id: playerId, name: 'N.a.'),
|
orElse: () => Player(id: playerId, name: loc.not_available),
|
||||||
);
|
);
|
||||||
gameCounts[i] = (player.name, gameCounts[i].$2);
|
matchCounts[i] = (player.name, matchCounts[i].$2);
|
||||||
}
|
}
|
||||||
|
|
||||||
gameCounts.sort((a, b) => b.$2.compareTo(a.$2));
|
matchCounts.sort((a, b) => b.$2.compareTo(a.$2));
|
||||||
|
|
||||||
return gameCounts;
|
return matchCounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// dart
|
// dart
|
||||||
List<(String, double)> computeWinRatePercent({
|
List<(String, double)> computeWinRatePercent({
|
||||||
required List<(String, int)> wins,
|
required List<(String, int)> wins,
|
||||||
required List<(String, int)> games,
|
required List<(String, int)> matches,
|
||||||
}) {
|
}) {
|
||||||
final Map<String, int> winsMap = {for (var e in wins) e.$1: e.$2};
|
final Map<String, int> winsMap = {for (var e in wins) e.$1: e.$2};
|
||||||
final Map<String, int> gamesMap = {for (var e in games) e.$1: e.$2};
|
final Map<String, int> matchesMap = {for (var e in matches) e.$1: e.$2};
|
||||||
|
|
||||||
// Get all unique player names
|
// Get all unique player names
|
||||||
final names = {...winsMap.keys, ...gamesMap.keys};
|
final names = {...winsMap.keys, ...matchesMap.keys};
|
||||||
|
|
||||||
// Calculate win rates
|
// Calculate win rates
|
||||||
final result = names.map((name) {
|
final result = names.map((name) {
|
||||||
final int w = winsMap[name] ?? 0;
|
final int w = winsMap[name] ?? 0;
|
||||||
final int g = gamesMap[name] ?? 0;
|
final int g = matchesMap[name] ?? 0;
|
||||||
// Calculate percentage and round to 2 decimal places
|
// Calculate percentage and round to 2 decimal places
|
||||||
// Avoid division by zero
|
// Avoid division by zero
|
||||||
final double percent = (g > 0)
|
final double percent = (g > 0)
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:skeletonizer/skeletonizer.dart';
|
import 'package:skeletonizer/skeletonizer.dart';
|
||||||
|
|
||||||
|
/// A widget that provides a skeleton loading effect to its child widget tree.
|
||||||
|
/// - [child]: The widget tree to apply the skeleton effect to.
|
||||||
|
/// - [enabled]: A boolean to enable or disable the skeleton effect.
|
||||||
|
/// - [fixLayoutBuilder]: A boolean to fix the layout builder for AnimatedSwitcher.
|
||||||
class AppSkeleton extends StatefulWidget {
|
class AppSkeleton extends StatefulWidget {
|
||||||
final Widget child;
|
|
||||||
final bool enabled;
|
|
||||||
final bool fixLayoutBuilder;
|
|
||||||
|
|
||||||
const AppSkeleton({
|
const AppSkeleton({
|
||||||
super.key,
|
super.key,
|
||||||
required this.child,
|
required this.child,
|
||||||
@@ -13,6 +13,15 @@ class AppSkeleton extends StatefulWidget {
|
|||||||
this.fixLayoutBuilder = false,
|
this.fixLayoutBuilder = false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The widget tree to apply the skeleton effect to.
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
/// A boolean to enable or disable the skeleton effect.
|
||||||
|
final bool enabled;
|
||||||
|
|
||||||
|
/// A boolean to fix the layout builder for AnimatedSwitcher.
|
||||||
|
final bool fixLayoutBuilder;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<AppSkeleton> createState() => _AppSkeletonState();
|
State<AppSkeleton> createState() => _AppSkeletonState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,12 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
import 'package:game_tracker/core/enums.dart';
|
import 'package:game_tracker/core/enums.dart';
|
||||||
|
|
||||||
|
/// A custom button widget that is designed to have a width relative to the screen size.
|
||||||
|
/// It supports three types of buttons: primary, secondary, and text buttons.
|
||||||
|
/// - [text]: The text to display on the button.
|
||||||
|
/// - [buttonType]: The type of button to display. Defaults to [ButtonType.primary].
|
||||||
|
/// - [sizeRelativeToWidth]: The size of the button relative to the width of the screen.
|
||||||
|
/// - [onPressed]: The callback to be invoked when the button is pressed.
|
||||||
class CustomWidthButton extends StatelessWidget {
|
class CustomWidthButton extends StatelessWidget {
|
||||||
const CustomWidthButton({
|
const CustomWidthButton({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -11,9 +17,16 @@ class CustomWidthButton extends StatelessWidget {
|
|||||||
this.onPressed,
|
this.onPressed,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The text to display on the button.
|
||||||
final String text;
|
final String text;
|
||||||
|
|
||||||
|
/// The size of the button relative to the width of the screen.
|
||||||
final double sizeRelativeToWidth;
|
final double sizeRelativeToWidth;
|
||||||
|
|
||||||
|
/// The callback to be invoked when the button is pressed.
|
||||||
final VoidCallback? onPressed;
|
final VoidCallback? onPressed;
|
||||||
|
|
||||||
|
/// The type of button to display. Depends on the enum [ButtonType].
|
||||||
final ButtonType buttonType;
|
final ButtonType buttonType;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -47,7 +60,7 @@ class CustomWidthButton extends StatelessWidget {
|
|||||||
60,
|
60,
|
||||||
),
|
),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: CustomTheme.standardBorderRadiusAll,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
@@ -78,7 +91,7 @@ class CustomWidthButton extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
side: BorderSide(color: borderSideColor, width: 2),
|
side: BorderSide(color: borderSideColor, width: 2),
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: CustomTheme.standardBorderRadiusAll,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A button widget designed for quick creating matches in the [HomeView]
|
||||||
|
/// - [text]: The text to display on the button.
|
||||||
|
/// - [onPressed]: The callback to be invoked when the button is pressed.
|
||||||
class QuickCreateButton extends StatefulWidget {
|
class QuickCreateButton extends StatefulWidget {
|
||||||
final String text;
|
|
||||||
final VoidCallback? onPressed;
|
|
||||||
const QuickCreateButton({
|
const QuickCreateButton({
|
||||||
super.key,
|
super.key,
|
||||||
required this.text,
|
required this.text,
|
||||||
required this.onPressed,
|
required this.onPressed,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The text to display on the button.
|
||||||
|
final String text;
|
||||||
|
|
||||||
|
/// The callback to be invoked when the button is pressed.
|
||||||
|
final VoidCallback? onPressed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<QuickCreateButton> createState() => _QuickCreateButtonState();
|
State<QuickCreateButton> createState() => _QuickCreateButtonState();
|
||||||
}
|
}
|
||||||
@@ -22,7 +29,9 @@ class _QuickCreateButtonState extends State<QuickCreateButton> {
|
|||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
minimumSize: const Size(140, 45),
|
minimumSize: const Size(140, 45),
|
||||||
backgroundColor: CustomTheme.primaryColor,
|
backgroundColor: CustomTheme.primaryColor,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: CustomTheme.standardBorderRadiusAll,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
widget.text,
|
widget.text,
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// A navigation bar item widget that represents a single tab in a navigation bar.
|
||||||
|
/// - [index]: The index of the tab.
|
||||||
|
/// - [isSelected]: A boolean indicating whether the tab is currently selected.
|
||||||
|
/// - [icon]: The icon to display for the tab.
|
||||||
|
/// - [label]: The label to display for the tab.
|
||||||
|
/// - [onTabTapped]: The callback to be invoked when the tab is tapped.
|
||||||
class NavbarItem extends StatefulWidget {
|
class NavbarItem extends StatefulWidget {
|
||||||
final int index;
|
|
||||||
final bool isSelected;
|
|
||||||
final IconData icon;
|
|
||||||
final String label;
|
|
||||||
final Function(int) onTabTapped;
|
|
||||||
|
|
||||||
const NavbarItem({
|
const NavbarItem({
|
||||||
super.key,
|
super.key,
|
||||||
required this.index,
|
required this.index,
|
||||||
@@ -16,6 +16,21 @@ class NavbarItem extends StatefulWidget {
|
|||||||
required this.onTabTapped,
|
required this.onTabTapped,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The index of the tab.
|
||||||
|
final int index;
|
||||||
|
|
||||||
|
/// A boolean indicating whether the tab is currently selected.
|
||||||
|
final bool isSelected;
|
||||||
|
|
||||||
|
/// The icon to display for the tab.
|
||||||
|
final IconData icon;
|
||||||
|
|
||||||
|
/// The label to display for the tab.
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
/// The callback to be invoked when the tab is tapped.
|
||||||
|
final Function(int) onTabTapped;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<NavbarItem> createState() => _NavbarItemState();
|
State<NavbarItem> createState() => _NavbarItemState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/core/constants.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/text_input/custom_search_bar.dart';
|
import 'package:game_tracker/presentation/widgets/text_input/custom_search_bar.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/text_icon_list_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/text_icon_list_tile.dart';
|
||||||
@@ -9,28 +11,55 @@ import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
|
|||||||
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
/// A widget that allows users to select players from a list,
|
||||||
|
/// with search functionality and the ability to add new players.
|
||||||
|
/// - [availablePlayers]: An optional list of players to choose from. If null, all
|
||||||
|
/// players from the database are used.
|
||||||
|
/// - [initialSelectedPlayers]: An optional list of players that should be pre-selected.
|
||||||
|
/// - [onChanged]: A callback function that is invoked whenever the selection changes,
|
||||||
|
/// providing the updated list of selected players.
|
||||||
class PlayerSelection extends StatefulWidget {
|
class PlayerSelection extends StatefulWidget {
|
||||||
final Function(List<Player> value) onChanged;
|
|
||||||
final List<Player> initialPlayers;
|
|
||||||
|
|
||||||
const PlayerSelection({
|
const PlayerSelection({
|
||||||
super.key,
|
super.key,
|
||||||
|
this.availablePlayers,
|
||||||
|
this.initialSelectedPlayers,
|
||||||
required this.onChanged,
|
required this.onChanged,
|
||||||
this.initialPlayers = const [],
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// An optional list of players to choose from. If null, all players from the database are used.
|
||||||
|
final List<Player>? availablePlayers;
|
||||||
|
|
||||||
|
/// An optional list of players that should be pre-selected.
|
||||||
|
final List<Player>? initialSelectedPlayers;
|
||||||
|
|
||||||
|
/// A callback function that is invoked whenever the selection changes,
|
||||||
|
final Function(List<Player> value) onChanged;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<PlayerSelection> createState() => _PlayerSelectionState();
|
State<PlayerSelection> createState() => _PlayerSelectionState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _PlayerSelectionState extends State<PlayerSelection> {
|
class _PlayerSelectionState extends State<PlayerSelection> {
|
||||||
List<Player> selectedPlayers = [];
|
late final AppDatabase db;
|
||||||
List<Player> suggestedPlayers = [];
|
bool isLoading = true;
|
||||||
|
|
||||||
|
/// Future that loads all players from the database.
|
||||||
|
late Future<List<Player>> _allPlayersFuture;
|
||||||
|
|
||||||
|
/// The complete list of all available players.
|
||||||
List<Player> allPlayers = [];
|
List<Player> allPlayers = [];
|
||||||
|
|
||||||
|
/// The list of players suggested based on the search input.
|
||||||
|
List<Player> suggestedPlayers = [];
|
||||||
|
|
||||||
|
/// The list of currently selected players.
|
||||||
|
List<Player> selectedPlayers = [];
|
||||||
|
|
||||||
|
/// Controller for the search bar input.
|
||||||
late final TextEditingController _searchBarController =
|
late final TextEditingController _searchBarController =
|
||||||
TextEditingController();
|
TextEditingController();
|
||||||
late final AppDatabase db;
|
|
||||||
late Future<List<Player>> _allPlayersFuture;
|
/// Skeleton data used while loading players.
|
||||||
late final List<Player> skeletonData = List.filled(
|
late final List<Player> skeletonData = List.filled(
|
||||||
7,
|
7,
|
||||||
Player(name: 'Player 0'),
|
Player(name: 'Player 0'),
|
||||||
@@ -40,33 +69,15 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
db = Provider.of<AppDatabase>(context, listen: false);
|
db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
loadPlayerList();
|
|
||||||
}
|
|
||||||
|
|
||||||
void loadPlayerList() {
|
|
||||||
_allPlayersFuture = Future.delayed(
|
|
||||||
const Duration(milliseconds: 250),
|
|
||||||
() => db.playerDao.getAllPlayers(),
|
|
||||||
);
|
|
||||||
suggestedPlayers = skeletonData;
|
suggestedPlayers = skeletonData;
|
||||||
_allPlayersFuture.then((loadedPlayers) {
|
loadPlayerList();
|
||||||
setState(() {
|
|
||||||
if (widget.initialPlayers.isNotEmpty) {
|
|
||||||
allPlayers = [...widget.initialPlayers];
|
|
||||||
suggestedPlayers = [...widget.initialPlayers];
|
|
||||||
} else {
|
|
||||||
loadedPlayers.sort((a, b) => a.name.compareTo(b.name));
|
|
||||||
allPlayers = [...loadedPlayers];
|
|
||||||
suggestedPlayers = [...loadedPlayers];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
return Container(
|
return Container(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
margin: CustomTheme.standardMargin,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
||||||
decoration: CustomTheme.standardBoxDecoration,
|
decoration: CustomTheme.standardBoxDecoration,
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -75,7 +86,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
|||||||
CustomSearchBar(
|
CustomSearchBar(
|
||||||
controller: _searchBarController,
|
controller: _searchBarController,
|
||||||
constraints: const BoxConstraints(maxHeight: 45, minHeight: 45),
|
constraints: const BoxConstraints(maxHeight: 45, minHeight: 45),
|
||||||
hintText: 'Search for players',
|
hintText: loc.search_for_players,
|
||||||
trailingButtonShown: true,
|
trailingButtonShown: true,
|
||||||
trailingButtonicon: Icons.add_circle,
|
trailingButtonicon: Icons.add_circle,
|
||||||
trailingButtonEnabled: _searchBarController.text.trim().isNotEmpty,
|
trailingButtonEnabled: _searchBarController.text.trim().isNotEmpty,
|
||||||
@@ -108,160 +119,206 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Text(
|
Text(
|
||||||
'Selected players: (${selectedPlayers.length})',
|
loc.selected_players,
|
||||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
Wrap(
|
SizedBox(
|
||||||
alignment: WrapAlignment.start,
|
height: 50,
|
||||||
crossAxisAlignment: WrapCrossAlignment.start,
|
child: selectedPlayers.isEmpty
|
||||||
spacing: 8.0,
|
? Center(child: Text(loc.no_players_selected))
|
||||||
runSpacing: 8.0,
|
: SingleChildScrollView(
|
||||||
children: <Widget>[
|
scrollDirection: Axis.horizontal,
|
||||||
// Generates a TextIconTile for each selected player.
|
child: Row(
|
||||||
for (var player in selectedPlayers)
|
children: [
|
||||||
TextIconTile(
|
for (var player in selectedPlayers)
|
||||||
text: player.name,
|
Padding(
|
||||||
onIconTap: () {
|
padding: const EdgeInsets.only(right: 8.0),
|
||||||
setState(() {
|
child: TextIconTile(
|
||||||
// Removes the player from the selection and notifies the parent.
|
text: player.name,
|
||||||
final currentSearch = _searchBarController.text
|
onIconTap: () {
|
||||||
.toLowerCase();
|
|
||||||
selectedPlayers.remove(player);
|
|
||||||
widget.onChanged([...selectedPlayers]);
|
|
||||||
// If the player matches the current search query (or search is empty),
|
|
||||||
// they are added back to the suggestions and the list is re-sorted.
|
|
||||||
if (currentSearch.isEmpty ||
|
|
||||||
player.name.toLowerCase().contains(currentSearch)) {
|
|
||||||
suggestedPlayers.add(player);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
const Text(
|
|
||||||
'All players:',
|
|
||||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
FutureBuilder(
|
|
||||||
future: _allPlayersFuture,
|
|
||||||
builder:
|
|
||||||
(BuildContext context, AsyncSnapshot<List<Player>> snapshot) {
|
|
||||||
if (snapshot.hasError) {
|
|
||||||
return const Center(
|
|
||||||
child: TopCenteredMessage(
|
|
||||||
icon: Icons.report,
|
|
||||||
title: 'Error',
|
|
||||||
message: 'Player data couldn\'t\nbe loaded.',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
bool doneLoading =
|
|
||||||
snapshot.connectionState == ConnectionState.done;
|
|
||||||
bool snapshotDataEmpty =
|
|
||||||
!snapshot.hasData || snapshot.data!.isEmpty;
|
|
||||||
if (doneLoading &&
|
|
||||||
(snapshotDataEmpty && allPlayers.isEmpty)) {
|
|
||||||
return const Center(
|
|
||||||
child: TopCenteredMessage(
|
|
||||||
icon: Icons.info,
|
|
||||||
title: 'Info',
|
|
||||||
message: 'No players created yet.',
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final bool isLoading =
|
|
||||||
snapshot.connectionState == ConnectionState.waiting;
|
|
||||||
return Expanded(
|
|
||||||
child: AppSkeleton(
|
|
||||||
enabled: isLoading,
|
|
||||||
child: Visibility(
|
|
||||||
visible:
|
|
||||||
(suggestedPlayers.isEmpty && allPlayers.isNotEmpty),
|
|
||||||
replacement: ListView.builder(
|
|
||||||
itemCount: suggestedPlayers.length,
|
|
||||||
itemBuilder: (BuildContext context, int index) {
|
|
||||||
return TextIconListTile(
|
|
||||||
text: suggestedPlayers[index].name,
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
setState(() {
|
||||||
if (!selectedPlayers.contains(
|
// Removes the player from the selection and notifies the parent.
|
||||||
suggestedPlayers[index],
|
selectedPlayers.remove(player);
|
||||||
)) {
|
widget.onChanged([...selectedPlayers]);
|
||||||
selectedPlayers.add(
|
|
||||||
suggestedPlayers[index],
|
// Get the current search query
|
||||||
);
|
final currentSearch = _searchBarController
|
||||||
widget.onChanged([...selectedPlayers]);
|
.text
|
||||||
suggestedPlayers.remove(
|
.toLowerCase();
|
||||||
suggestedPlayers[index],
|
|
||||||
|
// If the player matches the current search query (or search is empty),
|
||||||
|
// they are added back to the `suggestedPlayers` and the list is re-sorted.
|
||||||
|
if (currentSearch.isEmpty ||
|
||||||
|
player.name.toLowerCase().contains(
|
||||||
|
currentSearch,
|
||||||
|
)) {
|
||||||
|
suggestedPlayers.add(player);
|
||||||
|
suggestedPlayers.sort(
|
||||||
|
(a, b) => a.name.compareTo(b.name),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
),
|
],
|
||||||
child: TopCenteredMessage(
|
|
||||||
icon: Icons.info,
|
|
||||||
title: 'Info',
|
|
||||||
message: (selectedPlayers.length == allPlayers.length)
|
|
||||||
? 'No more players to add.'
|
|
||||||
: 'No players found with that name.',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Text(
|
||||||
|
loc.all_players,
|
||||||
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Expanded(
|
||||||
|
child: AppSkeleton(
|
||||||
|
enabled: isLoading,
|
||||||
|
child: Visibility(
|
||||||
|
visible: suggestedPlayers.isNotEmpty,
|
||||||
|
replacement: TopCenteredMessage(
|
||||||
|
icon: Icons.info,
|
||||||
|
title: loc.info,
|
||||||
|
message: _getInfoText(context),
|
||||||
|
),
|
||||||
|
child: ListView.builder(
|
||||||
|
itemCount: suggestedPlayers.length,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return TextIconListTile(
|
||||||
|
text: suggestedPlayers[index].name,
|
||||||
|
onPressed: () {
|
||||||
|
setState(() {
|
||||||
|
// If the player is not already selected
|
||||||
|
if (!selectedPlayers.contains(
|
||||||
|
suggestedPlayers[index],
|
||||||
|
)) {
|
||||||
|
// Add to player to the front of the selectedPlayers
|
||||||
|
selectedPlayers.insert(0, suggestedPlayers[index]);
|
||||||
|
// Notify the parent widget of the change
|
||||||
|
widget.onChanged([...selectedPlayers]);
|
||||||
|
// Remove the player from the suggestedPlayers
|
||||||
|
suggestedPlayers.remove(suggestedPlayers[index]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Loads the list of players from the database or uses the provided available players.
|
||||||
|
/// Sets the loading state and updates the player lists accordingly.
|
||||||
|
void loadPlayerList() {
|
||||||
|
_allPlayersFuture = Future.wait([
|
||||||
|
db.playerDao.getAllPlayers(),
|
||||||
|
Future.delayed(Constants.minimumSkeletonDuration),
|
||||||
|
]).then((results) => results[0] as List<Player>);
|
||||||
|
if (mounted) {
|
||||||
|
_allPlayersFuture.then((loadedPlayers) {
|
||||||
|
setState(() {
|
||||||
|
// If a list of available players is provided (even if empty), use that list.
|
||||||
|
if (widget.availablePlayers != null) {
|
||||||
|
widget.availablePlayers!.sort((a, b) => a.name.compareTo(b.name));
|
||||||
|
allPlayers = [...widget.availablePlayers!];
|
||||||
|
suggestedPlayers = [...allPlayers];
|
||||||
|
|
||||||
|
if (widget.initialSelectedPlayers != null) {
|
||||||
|
// Ensures that only players available for selection are pre-selected.
|
||||||
|
selectedPlayers = widget.initialSelectedPlayers!
|
||||||
|
.where(
|
||||||
|
(p) => widget.availablePlayers!.any(
|
||||||
|
(available) => available.id == p.id,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Otherwise, use the loaded players from the database.
|
||||||
|
loadedPlayers.sort((a, b) => a.name.compareTo(b.name));
|
||||||
|
allPlayers = [...loadedPlayers];
|
||||||
|
suggestedPlayers = [...loadedPlayers];
|
||||||
|
}
|
||||||
|
isLoading = false;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Adds a new player to the database from the search bar input.
|
/// Adds a new player to the database from the search bar input.
|
||||||
/// Shows a snackbar indicating success or failure.
|
/// Shows a snackbar indicating success or failure.
|
||||||
/// [context] - BuildContext to show the snackbar.
|
/// [context] - BuildContext to show the snackbar.
|
||||||
void addNewPlayerFromSearch({required BuildContext context}) async {
|
Future<void> addNewPlayerFromSearch({required BuildContext context}) async {
|
||||||
String playerName = _searchBarController.text.trim();
|
final loc = AppLocalizations.of(context);
|
||||||
Player createdPlayer = Player(name: playerName);
|
final playerName = _searchBarController.text.trim();
|
||||||
bool success = await db.playerDao.addPlayer(player: createdPlayer);
|
|
||||||
|
final createdPlayer = Player(name: playerName);
|
||||||
|
final success = await db.playerDao.addPlayer(player: createdPlayer);
|
||||||
|
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
selectedPlayers.add(createdPlayer);
|
_handleSuccessfulPlayerCreation(createdPlayer);
|
||||||
widget.onChanged([...selectedPlayers]);
|
showSnackBarMessage(loc.successfully_added_player(playerName));
|
||||||
allPlayers.add(createdPlayer);
|
|
||||||
setState(() {
|
|
||||||
_searchBarController.clear();
|
|
||||||
suggestedPlayers = allPlayers.where((player) {
|
|
||||||
return !selectedPlayers.contains(player);
|
|
||||||
}).toList();
|
|
||||||
});
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
backgroundColor: CustomTheme.boxColor,
|
|
||||||
content: Center(
|
|
||||||
child: Text(
|
|
||||||
'Successfully added player $playerName.',
|
|
||||||
style: const TextStyle(color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
showSnackBarMessage(loc.could_not_add_player(playerName));
|
||||||
SnackBar(
|
}
|
||||||
backgroundColor: CustomTheme.boxColor,
|
}
|
||||||
content: Center(
|
|
||||||
child: Text(
|
/// Updates the state after successfully adding a new player.
|
||||||
'Could not add player $playerName.',
|
void _handleSuccessfulPlayerCreation(Player player) {
|
||||||
style: const TextStyle(color: Colors.white),
|
selectedPlayers.insert(0, player);
|
||||||
),
|
widget.onChanged([...selectedPlayers]);
|
||||||
),
|
allPlayers.add(player);
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_searchBarController.clear();
|
||||||
|
_updateSuggestedPlayers();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Updates the suggested players list based on current selection.
|
||||||
|
void _updateSuggestedPlayers() {
|
||||||
|
suggestedPlayers = allPlayers
|
||||||
|
.where((player) => !selectedPlayers.contains(player))
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Displays a snackbar message at the bottom of the screen.
|
||||||
|
/// [message] - The message to display in the snackbar.
|
||||||
|
void showSnackBarMessage(String message) {
|
||||||
|
if (!context.mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
backgroundColor: CustomTheme.boxColor,
|
||||||
|
content: Center(
|
||||||
|
child: Text(message, style: const TextStyle(color: Colors.white)),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Determines the appropriate info text to display when no players
|
||||||
|
/// are available in the suggested players list.
|
||||||
|
String _getInfoText(BuildContext context) {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
if (allPlayers.isEmpty) {
|
||||||
|
// No players exist in the database
|
||||||
|
return loc.no_players_created_yet;
|
||||||
|
} else if (selectedPlayers.length == allPlayers.length ||
|
||||||
|
widget.availablePlayers?.isEmpty == true) {
|
||||||
|
// All players have been selected or
|
||||||
|
// available players list is provided but empty
|
||||||
|
return loc.all_players_selected;
|
||||||
|
} else {
|
||||||
|
// No players match the search query
|
||||||
|
return loc.no_players_found_with_that_name;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A custom search bar widget that encapsulates a [SearchBar] with additional customization options.
|
||||||
|
/// - [controller]: The controller for the search bar's text input.
|
||||||
|
/// - [hintText]: The hint text displayed in the search bar when it is empty.
|
||||||
|
/// - [trailingButtonShown]: Whether to show the trailing button.
|
||||||
|
/// - [trailingButtonicon]: The icon for the trailing button.
|
||||||
|
/// - [trailingButtonEnabled]: Whether the trailing button is in enabled state.
|
||||||
|
/// - [onTrailingButtonPressed]: The callback invoked when the trailing button is pressed.
|
||||||
|
/// - [onChanged]: The callback invoked when the text in the search bar changes.
|
||||||
|
/// - [constraints]: The constraints for the search bar.
|
||||||
class CustomSearchBar extends StatelessWidget {
|
class CustomSearchBar extends StatelessWidget {
|
||||||
final TextEditingController controller;
|
|
||||||
final String hintText;
|
|
||||||
final ValueChanged<String>? onChanged;
|
|
||||||
final BoxConstraints? constraints;
|
|
||||||
final bool trailingButtonShown;
|
|
||||||
final bool trailingButtonEnabled;
|
|
||||||
final VoidCallback? onTrailingButtonPressed;
|
|
||||||
final IconData trailingButtonicon;
|
|
||||||
|
|
||||||
const CustomSearchBar({
|
const CustomSearchBar({
|
||||||
super.key,
|
super.key,
|
||||||
required this.controller,
|
required this.controller,
|
||||||
@@ -23,6 +23,30 @@ class CustomSearchBar extends StatelessWidget {
|
|||||||
this.constraints,
|
this.constraints,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The controller for the search bar's text input.
|
||||||
|
final TextEditingController controller;
|
||||||
|
|
||||||
|
/// The hint text displayed in the search bar when it is empty.
|
||||||
|
final String hintText;
|
||||||
|
|
||||||
|
/// Whether to show the trailing button.
|
||||||
|
final bool trailingButtonShown;
|
||||||
|
|
||||||
|
/// The icon for the trailing button.
|
||||||
|
final IconData trailingButtonicon;
|
||||||
|
|
||||||
|
/// Whether the trailing button is in enabled state.
|
||||||
|
final bool trailingButtonEnabled;
|
||||||
|
|
||||||
|
/// The callback invoked when the trailing button is pressed.
|
||||||
|
final VoidCallback? onTrailingButtonPressed;
|
||||||
|
|
||||||
|
/// The callback invoked when the text in the search bar changes.
|
||||||
|
final ValueChanged<String>? onChanged;
|
||||||
|
|
||||||
|
/// The constraints for the search bar.
|
||||||
|
final BoxConstraints? constraints;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SearchBar(
|
return SearchBar(
|
||||||
@@ -30,7 +54,7 @@ class CustomSearchBar extends StatelessWidget {
|
|||||||
constraints:
|
constraints:
|
||||||
constraints ?? const BoxConstraints(maxHeight: 45, minHeight: 45),
|
constraints ?? const BoxConstraints(maxHeight: 45, minHeight: 45),
|
||||||
hintText: hintText,
|
hintText: hintText,
|
||||||
onChanged: trailingButtonEnabled ? onChanged : null,
|
onChanged: onChanged,
|
||||||
hintStyle: WidgetStateProperty.all(const TextStyle(fontSize: 16)),
|
hintStyle: WidgetStateProperty.all(const TextStyle(fontSize: 16)),
|
||||||
leading: const Icon(Icons.search),
|
leading: const Icon(Icons.search),
|
||||||
trailing: [
|
trailing: [
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A custom text input field widget that encapsulates a [TextField] with specific styling.
|
||||||
|
/// - [controller]: The controller for the text input field.
|
||||||
|
/// - [onChanged]: The callback invoked when the text in the field changes.
|
||||||
|
/// - [hintText]: The hint text displayed in the text input field when it is empty
|
||||||
class TextInputField extends StatelessWidget {
|
class TextInputField extends StatelessWidget {
|
||||||
final TextEditingController controller;
|
|
||||||
final ValueChanged<String>? onChanged;
|
|
||||||
final String hintText;
|
|
||||||
|
|
||||||
const TextInputField({
|
const TextInputField({
|
||||||
super.key,
|
super.key,
|
||||||
required this.controller,
|
required this.controller,
|
||||||
@@ -13,6 +13,15 @@ class TextInputField extends StatelessWidget {
|
|||||||
this.onChanged,
|
this.onChanged,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The controller for the text input field.
|
||||||
|
final TextEditingController controller;
|
||||||
|
|
||||||
|
/// The callback invoked when the text in the field changes.
|
||||||
|
final ValueChanged<String>? onChanged;
|
||||||
|
|
||||||
|
/// The hint text displayed in the text input field when it is empty.
|
||||||
|
final String hintText;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return TextField(
|
return TextField(
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A tile widget that allows users to choose an option by tapping on it.
|
||||||
|
/// - [title]: The title text displayed on the tile.
|
||||||
|
/// - [trailingText]: Optional trailing text displayed on the tile.
|
||||||
|
/// - [onPressed]: The callback invoked when the tile is tapped.
|
||||||
class ChooseTile extends StatefulWidget {
|
class ChooseTile extends StatefulWidget {
|
||||||
final String title;
|
|
||||||
final VoidCallback? onPressed;
|
|
||||||
final String? trailingText;
|
|
||||||
const ChooseTile({
|
const ChooseTile({
|
||||||
super.key,
|
super.key,
|
||||||
required this.title,
|
required this.title,
|
||||||
@@ -12,6 +13,15 @@ class ChooseTile extends StatefulWidget {
|
|||||||
this.onPressed,
|
this.onPressed,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The title text displayed on the tile.
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
/// The callback invoked when the tile is tapped.
|
||||||
|
final VoidCallback? onPressed;
|
||||||
|
|
||||||
|
/// Optional trailing text displayed on the tile.
|
||||||
|
final String? trailingText;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ChooseTile> createState() => _ChooseTileState();
|
State<ChooseTile> createState() => _ChooseTileState();
|
||||||
}
|
}
|
||||||
@@ -22,8 +32,8 @@ class _ChooseTileState extends State<ChooseTile> {
|
|||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: widget.onPressed,
|
onTap: widget.onPressed,
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 5),
|
margin: CustomTheme.tileMargin,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||||
decoration: CustomTheme.standardBoxDecoration,
|
decoration: CustomTheme.standardBoxDecoration,
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A custom radio list tile widget that encapsulates a [Radio] button with additional styling and functionality.
|
||||||
|
/// - [text]: The text to display next to the radio button.
|
||||||
|
/// - [value]: The value associated with the radio button.
|
||||||
|
/// - [onContainerTap]: The callback invoked when the container is tapped.
|
||||||
class CustomRadioListTile<T> extends StatelessWidget {
|
class CustomRadioListTile<T> extends StatelessWidget {
|
||||||
final String text;
|
|
||||||
final T value;
|
|
||||||
final ValueChanged<T> onContainerTap;
|
|
||||||
|
|
||||||
const CustomRadioListTile({
|
const CustomRadioListTile({
|
||||||
super.key,
|
super.key,
|
||||||
required this.text,
|
required this.text,
|
||||||
@@ -13,6 +13,15 @@ class CustomRadioListTile<T> extends StatelessWidget {
|
|||||||
required this.onContainerTap,
|
required this.onContainerTap,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The text to display next to the radio button.
|
||||||
|
final String text;
|
||||||
|
|
||||||
|
/// The value associated with the radio button.
|
||||||
|
final T value;
|
||||||
|
|
||||||
|
/// The callback invoked when the container is tapped.
|
||||||
|
final ValueChanged<T> onContainerTap;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
@@ -23,7 +32,7 @@ class CustomRadioListTile<T> extends StatelessWidget {
|
|||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: CustomTheme.boxColor,
|
color: CustomTheme.boxColor,
|
||||||
border: Border.all(color: CustomTheme.boxBorder),
|
border: Border.all(color: CustomTheme.boxBorder),
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: CustomTheme.standardBorderRadiusAll,
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -3,16 +3,22 @@ import 'package:game_tracker/core/custom_theme.dart';
|
|||||||
import 'package:game_tracker/data/dto/group.dart';
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
|
||||||
|
|
||||||
|
/// A tile widget that displays information about a group, including its name and members.
|
||||||
|
/// - [group]: The group data to be displayed.
|
||||||
|
/// - [isHighlighted]: Whether the tile should be highlighted.
|
||||||
class GroupTile extends StatelessWidget {
|
class GroupTile extends StatelessWidget {
|
||||||
const GroupTile({super.key, required this.group, this.isHighlighted = false});
|
const GroupTile({super.key, required this.group, this.isHighlighted = false});
|
||||||
|
|
||||||
|
/// The group data to be displayed.
|
||||||
final Group group;
|
final Group group;
|
||||||
|
|
||||||
|
/// Whether the tile should be highlighted.
|
||||||
final bool isHighlighted;
|
final bool isHighlighted;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return AnimatedContainer(
|
return AnimatedContainer(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
margin: CustomTheme.standardMargin,
|
||||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
|
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
|
||||||
decoration: isHighlighted
|
decoration: isHighlighted
|
||||||
? CustomTheme.highlightedBoxDecoration
|
? CustomTheme.highlightedBoxDecoration
|
||||||
@@ -56,7 +62,9 @@ class GroupTile extends StatelessWidget {
|
|||||||
spacing: 12.0,
|
spacing: 12.0,
|
||||||
runSpacing: 8.0,
|
runSpacing: 8.0,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
for (var member in group.members)
|
for (var member in [
|
||||||
|
...group.members,
|
||||||
|
]..sort((a, b) => a.name.compareTo(b.name)))
|
||||||
TextIconTile(text: member.name, iconEnabled: false),
|
TextIconTile(text: member.name, iconEnabled: false),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A tile widget that displays a title with an icon and some content below it.
|
||||||
|
/// - [title]: The title text displayed on the tile.
|
||||||
|
/// - [icon]: The icon displayed next to the title.
|
||||||
|
/// - [content]: The content widget displayed below the title.
|
||||||
|
/// - [padding]: Optional padding for the tile content.
|
||||||
|
/// - [height]: Optional height for the tile.
|
||||||
|
/// - [width]: Optional width for the tile.
|
||||||
class InfoTile extends StatefulWidget {
|
class InfoTile extends StatefulWidget {
|
||||||
final String title;
|
|
||||||
final IconData icon;
|
|
||||||
final Widget content;
|
|
||||||
final EdgeInsets? padding;
|
|
||||||
final double? height;
|
|
||||||
final double? width;
|
|
||||||
const InfoTile({
|
const InfoTile({
|
||||||
super.key,
|
super.key,
|
||||||
required this.title,
|
required this.title,
|
||||||
@@ -18,6 +19,24 @@ class InfoTile extends StatefulWidget {
|
|||||||
this.width,
|
this.width,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The title text displayed on the tile.
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
/// The icon displayed next to the title.
|
||||||
|
final IconData icon;
|
||||||
|
|
||||||
|
/// The content widget displayed below the title.
|
||||||
|
final Widget content;
|
||||||
|
|
||||||
|
/// Optional padding for the tile content.
|
||||||
|
final EdgeInsets? padding;
|
||||||
|
|
||||||
|
/// Optional height for the tile.
|
||||||
|
final double? height;
|
||||||
|
|
||||||
|
/// Optional width for the tile.
|
||||||
|
final double? width;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<InfoTile> createState() => _InfoTileState();
|
State<InfoTile> createState() => _InfoTileState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,27 +2,27 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
import 'package:skeletonizer/skeletonizer.dart';
|
import 'package:skeletonizer/skeletonizer.dart';
|
||||||
|
|
||||||
class GameTile extends StatefulWidget {
|
class MatchSummaryTile extends StatefulWidget {
|
||||||
final String gameTitle;
|
final String matchTitle;
|
||||||
final String gameType;
|
final String game;
|
||||||
final String ruleset;
|
final String ruleset;
|
||||||
final String players;
|
final String players;
|
||||||
final String winner;
|
final String winner;
|
||||||
|
|
||||||
const GameTile({
|
const MatchSummaryTile({
|
||||||
super.key,
|
super.key,
|
||||||
required this.gameTitle,
|
required this.matchTitle,
|
||||||
required this.gameType,
|
required this.game,
|
||||||
required this.ruleset,
|
required this.ruleset,
|
||||||
required this.players,
|
required this.players,
|
||||||
required this.winner,
|
required this.winner,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<GameTile> createState() => _GameTileState();
|
State<MatchSummaryTile> createState() => _MatchSummaryTileState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _GameTileState extends State<GameTile> {
|
class _MatchSummaryTileState extends State<MatchSummaryTile> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
@@ -31,12 +31,12 @@ class _GameTileState extends State<GameTile> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
widget.gameTitle,
|
widget.matchTitle,
|
||||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 5),
|
const SizedBox(width: 5),
|
||||||
Text(
|
Text(
|
||||||
widget.gameType,
|
widget.game,
|
||||||
style: const TextStyle(fontSize: 14, color: Colors.grey),
|
style: const TextStyle(fontSize: 14, color: Colors.grey),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -1,31 +1,48 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
class GameHistoryTile extends StatefulWidget {
|
/// A tile widget that displays information about a match, including its name,
|
||||||
final Game game;
|
/// creation date, associated group, winner, and players.
|
||||||
|
/// - [match]: The match data to be displayed.
|
||||||
|
/// - [onTap]: The callback invoked when the tile is tapped.
|
||||||
|
class MatchTile extends StatefulWidget {
|
||||||
|
const MatchTile({super.key, required this.match, required this.onTap});
|
||||||
|
|
||||||
|
/// The match data to be displayed.
|
||||||
|
final Match match;
|
||||||
|
|
||||||
|
/// The callback invoked when the tile is tapped.
|
||||||
final VoidCallback onTap;
|
final VoidCallback onTap;
|
||||||
|
|
||||||
const GameHistoryTile({super.key, required this.game, required this.onTap});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<GameHistoryTile> createState() => _GameHistoryTileState();
|
State<MatchTile> createState() => _MatchTileState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _GameHistoryTileState extends State<GameHistoryTile> {
|
class _MatchTileState extends State<MatchTile> {
|
||||||
|
late final List<Player> _allPlayers;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_allPlayers = _getCombinedPlayers();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final group = widget.game.group;
|
final group = widget.match.group;
|
||||||
final winner = widget.game.winner;
|
final winner = widget.match.winner;
|
||||||
final allPlayers = _getAllPlayers();
|
final loc = AppLocalizations.of(context);
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: widget.onTap,
|
onTap: widget.onTap,
|
||||||
child: Container(
|
child: Container(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
margin: CustomTheme.tileMargin,
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(12),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: CustomTheme.boxColor,
|
color: CustomTheme.boxColor,
|
||||||
border: Border.all(color: CustomTheme.boxBorder),
|
border: Border.all(color: CustomTheme.boxBorder),
|
||||||
@@ -39,7 +56,7 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
widget.game.name,
|
widget.match.name,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@@ -48,7 +65,7 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
_formatDate(widget.game.createdAt),
|
_formatDate(widget.match.createdAt, context),
|
||||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -97,11 +114,11 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
'Winner: ${winner.name}',
|
'${loc.winner}: ${winner.name}',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: Colors.white,
|
color: CustomTheme.textColor,
|
||||||
),
|
),
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
@@ -112,10 +129,10 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
],
|
],
|
||||||
|
|
||||||
if (allPlayers.isNotEmpty) ...[
|
if (_allPlayers.isNotEmpty) ...[
|
||||||
const Text(
|
Text(
|
||||||
'Players',
|
loc.players,
|
||||||
style: TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
color: Colors.grey,
|
color: Colors.grey,
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
@@ -125,7 +142,7 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
Wrap(
|
Wrap(
|
||||||
spacing: 6,
|
spacing: 6,
|
||||||
runSpacing: 6,
|
runSpacing: 6,
|
||||||
children: allPlayers.map((player) {
|
children: _allPlayers.map((player) {
|
||||||
return TextIconTile(text: player.name, iconEnabled: false);
|
return TextIconTile(text: player.name, iconEnabled: false);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
@@ -136,28 +153,33 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String _formatDate(DateTime dateTime) {
|
/// Formats the given [dateTime] into a human-readable string based on its
|
||||||
|
/// difference from the current date.
|
||||||
|
String _formatDate(DateTime dateTime, BuildContext context) {
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
final difference = now.difference(dateTime);
|
final difference = now.difference(dateTime);
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
|
||||||
if (difference.inDays == 0) {
|
if (difference.inDays == 0) {
|
||||||
return 'Today at ${DateFormat('HH:mm').format(dateTime)}';
|
return "${loc.today_at} ${DateFormat('HH:mm').format(dateTime)}";
|
||||||
} else if (difference.inDays == 1) {
|
} else if (difference.inDays == 1) {
|
||||||
return 'Yesterday at ${DateFormat('HH:mm').format(dateTime)}';
|
return "${loc.yesterday_at} ${DateFormat('HH:mm').format(dateTime)}";
|
||||||
} else if (difference.inDays < 7) {
|
} else if (difference.inDays < 7) {
|
||||||
return '${difference.inDays} days ago';
|
return loc.days_ago(difference.inDays);
|
||||||
} else {
|
} else {
|
||||||
return DateFormat('MMM d, yyyy').format(dateTime);
|
return DateFormat('MMM d, yyyy').format(dateTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<dynamic> _getAllPlayers() {
|
/// Retrieves all unique players associated with the match,
|
||||||
final allPlayers = <dynamic>[];
|
/// combining players from both the match and its group.
|
||||||
|
List<Player> _getCombinedPlayers() {
|
||||||
|
final allPlayers = <Player>[];
|
||||||
final playerIds = <String>{};
|
final playerIds = <String>{};
|
||||||
|
|
||||||
// Add players from game.players
|
// Add players from game.players
|
||||||
if (widget.game.players != null) {
|
if (widget.match.players != null) {
|
||||||
for (var player in widget.game.players!) {
|
for (var player in widget.match.players!) {
|
||||||
if (!playerIds.contains(player.id)) {
|
if (!playerIds.contains(player.id)) {
|
||||||
allPlayers.add(player);
|
allPlayers.add(player);
|
||||||
playerIds.add(player.id);
|
playerIds.add(player.id);
|
||||||
@@ -166,8 +188,8 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add players from game.group.players
|
// Add players from game.group.players
|
||||||
if (widget.game.group?.members != null) {
|
if (widget.match.group?.members != null) {
|
||||||
for (var player in widget.game.group!.members) {
|
for (var player in widget.match.group!.members) {
|
||||||
if (!playerIds.contains(player.id)) {
|
if (!playerIds.contains(player.id)) {
|
||||||
allPlayers.add(player);
|
allPlayers.add(player);
|
||||||
playerIds.add(player.id);
|
playerIds.add(player.id);
|
||||||
@@ -175,6 +197,7 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
allPlayers.sort((a, b) => a.name.compareTo(b.name));
|
||||||
return allPlayers;
|
return allPlayers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A tile widget that displays a title with an icon and a numeric value below it.
|
||||||
|
/// - [title]: The title text displayed on the tile.
|
||||||
|
/// - [icon]: The icon displayed next to the title.
|
||||||
|
/// - [value]: The numeric value displayed below the title.
|
||||||
|
/// - [height]: Optional height for the tile.
|
||||||
|
/// - [width]: Optional width for the tile.
|
||||||
|
/// - [padding]: Optional padding for the tile content.
|
||||||
class QuickInfoTile extends StatefulWidget {
|
class QuickInfoTile extends StatefulWidget {
|
||||||
final String title;
|
|
||||||
final IconData icon;
|
|
||||||
final int value;
|
|
||||||
final double? height;
|
|
||||||
final double? width;
|
|
||||||
final EdgeInsets? padding;
|
|
||||||
const QuickInfoTile({
|
const QuickInfoTile({
|
||||||
super.key,
|
super.key,
|
||||||
required this.title,
|
required this.title,
|
||||||
@@ -18,6 +19,24 @@ class QuickInfoTile extends StatefulWidget {
|
|||||||
this.padding,
|
this.padding,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The title text displayed on the tile.
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
/// The icon displayed next to the title.
|
||||||
|
final IconData icon;
|
||||||
|
|
||||||
|
/// The numeric value displayed below the title.
|
||||||
|
final int value;
|
||||||
|
|
||||||
|
/// Optional height for the tile.
|
||||||
|
final double? height;
|
||||||
|
|
||||||
|
/// Optional width for the tile.
|
||||||
|
final double? width;
|
||||||
|
|
||||||
|
/// Optional padding for the tile content.
|
||||||
|
final EdgeInsets? padding;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<QuickInfoTile> createState() => _QuickInfoTileState();
|
State<QuickInfoTile> createState() => _QuickInfoTileState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
|
||||||
|
|
||||||
class RulesetListTile extends StatelessWidget {
|
|
||||||
final String title;
|
|
||||||
final String description;
|
|
||||||
final VoidCallback? onPressed;
|
|
||||||
final bool isHighlighted;
|
|
||||||
|
|
||||||
const RulesetListTile({
|
|
||||||
super.key,
|
|
||||||
required this.title,
|
|
||||||
required this.description,
|
|
||||||
this.onPressed,
|
|
||||||
this.isHighlighted = false,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: onPressed,
|
|
||||||
child: AnimatedContainer(
|
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
|
|
||||||
decoration: isHighlighted
|
|
||||||
? CustomTheme.highlightedBoxDecoration
|
|
||||||
: CustomTheme.standardBoxDecoration,
|
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Flexible(
|
|
||||||
child: Text(
|
|
||||||
title,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontSize: 18,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 5),
|
|
||||||
Text(description, style: const TextStyle(fontSize: 14)),
|
|
||||||
const SizedBox(height: 2.5),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +1,32 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A customizable settings list tile widget that displays an icon, title, and an optional suffix widget.
|
||||||
|
/// - [icon]: The icon displayed on the left side of the tile.
|
||||||
|
/// - [title]: The title text displayed next to the icon.
|
||||||
|
/// - [suffixWidget]: An optional widget displayed on the right side of the tile.
|
||||||
|
/// - [onPressed]: The callback invoked when the tile is tapped.
|
||||||
class SettingsListTile extends StatelessWidget {
|
class SettingsListTile extends StatelessWidget {
|
||||||
final VoidCallback? onPressed;
|
|
||||||
final IconData icon;
|
|
||||||
final String title;
|
|
||||||
final Widget? suffixWidget;
|
|
||||||
const SettingsListTile({
|
const SettingsListTile({
|
||||||
super.key,
|
super.key,
|
||||||
required this.title,
|
|
||||||
required this.icon,
|
required this.icon,
|
||||||
|
required this.title,
|
||||||
this.suffixWidget,
|
this.suffixWidget,
|
||||||
this.onPressed,
|
this.onPressed,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The icon displayed on the left side of the tile.
|
||||||
|
final IconData icon;
|
||||||
|
|
||||||
|
/// The title text displayed next to the icon.
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
/// An optional widget displayed on the right side of the tile.
|
||||||
|
final Widget? suffixWidget;
|
||||||
|
|
||||||
|
/// The callback invoked when the tile is tapped.
|
||||||
|
final VoidCallback? onPressed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Padding(
|
return Padding(
|
||||||
|
|||||||
@@ -1,8 +1,16 @@
|
|||||||
import 'dart:math';
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/info_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/info_tile.dart';
|
||||||
|
|
||||||
|
/// A tile widget that displays statistical data using horizontal bars.
|
||||||
|
/// - [icon]: The icon displayed next to the title.
|
||||||
|
/// - [title]: The title text displayed on the tile.
|
||||||
|
/// - [width]: The width of the tile.
|
||||||
|
/// - [values]: A list of tuples containing labels and their corresponding numeric values.
|
||||||
|
/// - [itemCount]: The maximum number of items to display.
|
||||||
|
/// - [barColor]: The color of the bars representing the values.
|
||||||
class StatisticsTile extends StatelessWidget {
|
class StatisticsTile extends StatelessWidget {
|
||||||
const StatisticsTile({
|
const StatisticsTile({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -14,16 +22,27 @@ class StatisticsTile extends StatelessWidget {
|
|||||||
required this.barColor,
|
required this.barColor,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The icon displayed next to the title.
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
|
|
||||||
|
/// The title text displayed on the tile.
|
||||||
final String title;
|
final String title;
|
||||||
|
|
||||||
|
/// The width of the tile.
|
||||||
final double width;
|
final double width;
|
||||||
|
|
||||||
|
/// A list of tuples containing labels and their corresponding numeric values.
|
||||||
final List<(String, num)> values;
|
final List<(String, num)> values;
|
||||||
|
|
||||||
|
/// The maximum number of items to display.
|
||||||
final int itemCount;
|
final int itemCount;
|
||||||
|
|
||||||
|
/// The color of the bars representing the values.
|
||||||
final Color barColor;
|
final Color barColor;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final maxBarWidth = MediaQuery.of(context).size.width * 0.65;
|
final loc = AppLocalizations.of(context);
|
||||||
|
|
||||||
return InfoTile(
|
return InfoTile(
|
||||||
width: width,
|
width: width,
|
||||||
@@ -33,42 +52,60 @@ class StatisticsTile extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
padding: const EdgeInsets.symmetric(horizontal: 20.0),
|
||||||
child: Visibility(
|
child: Visibility(
|
||||||
visible: values.isNotEmpty,
|
visible: values.isNotEmpty,
|
||||||
replacement: const Center(
|
replacement: Center(
|
||||||
heightFactor: 4,
|
heightFactor: 4,
|
||||||
child: Text('No data available.'),
|
child: Text(loc.no_data_available),
|
||||||
),
|
),
|
||||||
child: Column(
|
child: LayoutBuilder(
|
||||||
children: List.generate(min(values.length, itemCount), (index) {
|
builder: (context, constraints) {
|
||||||
/// The maximum wins among all players
|
final maxBarWidth = constraints.maxWidth * 0.65;
|
||||||
final maxGames = values.isNotEmpty ? values[0].$2 : 0;
|
return Column(
|
||||||
|
children: List.generate(min(values.length, itemCount), (index) {
|
||||||
|
/// The maximum wins among all players
|
||||||
|
final maxMatches = values.isNotEmpty ? values[0].$2 : 0;
|
||||||
|
|
||||||
/// Fraction of wins
|
/// Fraction of wins
|
||||||
final double fraction = (maxGames > 0)
|
final double fraction = (maxMatches > 0)
|
||||||
? (values[index].$2 / maxGames)
|
? (values[index].$2 / maxMatches)
|
||||||
: 0.0;
|
: 0.0;
|
||||||
|
|
||||||
/// Calculated width for current the bar
|
/// Calculated width for current the bar
|
||||||
final double barWidth = maxBarWidth * fraction;
|
final double barWidth = maxBarWidth * fraction;
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.symmetric(vertical: 2.0),
|
padding: const EdgeInsets.symmetric(vertical: 2.0),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
|
||||||
Stack(
|
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Stack(
|
||||||
height: 24,
|
children: [
|
||||||
width: barWidth,
|
Container(
|
||||||
decoration: BoxDecoration(
|
height: 24,
|
||||||
borderRadius: BorderRadius.circular(4),
|
width: barWidth,
|
||||||
color: barColor,
|
decoration: BoxDecoration(
|
||||||
),
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
color: barColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 4.0),
|
||||||
|
child: Text(
|
||||||
|
values[index].$1,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
Padding(
|
const Spacer(),
|
||||||
padding: const EdgeInsets.only(left: 4.0),
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
values[index].$1,
|
values[index].$2 <= 1 && values[index].$2 is double
|
||||||
|
? values[index].$2.toStringAsFixed(2)
|
||||||
|
: values[index].$2.toString(),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
@@ -77,23 +114,10 @@ class StatisticsTile extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const Spacer(),
|
);
|
||||||
Center(
|
}),
|
||||||
child: Text(
|
|
||||||
values[index].$2 <= 1 && values[index].$2 is double
|
|
||||||
? values[index].$2.toStringAsFixed(2)
|
|
||||||
: values[index].$2.toString(),
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}),
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,18 +1,27 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A list tile widget that displays text with an optional icon button.
|
||||||
|
/// - [text]: The text to display in the tile.
|
||||||
|
/// - [onPressed]: The callback to be invoked when the icon is pressed.
|
||||||
|
/// - [iconEnabled]: A boolean to determine if the icon should be displayed.
|
||||||
class TextIconListTile extends StatelessWidget {
|
class TextIconListTile extends StatelessWidget {
|
||||||
final String text;
|
|
||||||
final VoidCallback? onPressed;
|
|
||||||
final bool iconEnabled;
|
|
||||||
|
|
||||||
const TextIconListTile({
|
const TextIconListTile({
|
||||||
super.key,
|
super.key,
|
||||||
required this.text,
|
required this.text,
|
||||||
this.onPressed,
|
|
||||||
this.iconEnabled = true,
|
this.iconEnabled = true,
|
||||||
|
this.onPressed,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The text to display in the tile.
|
||||||
|
final String text;
|
||||||
|
|
||||||
|
/// A boolean to determine if the icon should be displayed.
|
||||||
|
final bool iconEnabled;
|
||||||
|
|
||||||
|
/// The callback to be invoked when the icon is pressed.
|
||||||
|
final VoidCallback? onPressed;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
|
|||||||
@@ -1,18 +1,27 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A tile widget that displays text with an optional icon that can be tapped.
|
||||||
|
/// - [text]: The text to display in the tile.
|
||||||
|
/// - [iconEnabled]: A boolean to determine if the icon should be displayed.
|
||||||
|
/// - [onIconTap]: The callback to be invoked when the icon is tapped.
|
||||||
class TextIconTile extends StatelessWidget {
|
class TextIconTile extends StatelessWidget {
|
||||||
final String text;
|
|
||||||
final bool iconEnabled;
|
|
||||||
final VoidCallback? onIconTap;
|
|
||||||
|
|
||||||
const TextIconTile({
|
const TextIconTile({
|
||||||
super.key,
|
super.key,
|
||||||
required this.text,
|
required this.text,
|
||||||
this.onIconTap,
|
|
||||||
this.iconEnabled = true,
|
this.iconEnabled = true,
|
||||||
|
this.onIconTap,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// The text to display in the tile.
|
||||||
|
final String text;
|
||||||
|
|
||||||
|
/// A boolean to determine if the icon should be displayed.
|
||||||
|
final bool iconEnabled;
|
||||||
|
|
||||||
|
/// The callback to be invoked when the icon is tapped.
|
||||||
|
final VoidCallback? onIconTap;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
|
|||||||
110
lib/presentation/widgets/tiles/title_description_list_tile.dart
Normal file
110
lib/presentation/widgets/tiles/title_description_list_tile.dart
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
|
||||||
|
/// A list tile widget that displays a title and description, with optional highlighting and badge.
|
||||||
|
/// - [title]: The title text displayed on the tile.
|
||||||
|
/// - [description]: The description text displayed below the title.
|
||||||
|
/// - [onPressed]: The callback invoked when the tile is tapped.
|
||||||
|
/// - [isHighlighted]: A boolean to determine if the tile should be highlighted.
|
||||||
|
/// - [badgeText]: Optional text to display in a badge on the right side of the title.
|
||||||
|
/// - [badgeColor]: Optional color for the badge background.
|
||||||
|
class TitleDescriptionListTile extends StatelessWidget {
|
||||||
|
const TitleDescriptionListTile({
|
||||||
|
super.key,
|
||||||
|
required this.title,
|
||||||
|
required this.description,
|
||||||
|
this.onPressed,
|
||||||
|
this.isHighlighted = false,
|
||||||
|
this.badgeText,
|
||||||
|
this.badgeColor,
|
||||||
|
});
|
||||||
|
|
||||||
|
/// The title text displayed on the tile.
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
/// The description text displayed below the title.
|
||||||
|
final String description;
|
||||||
|
|
||||||
|
/// The callback invoked when the tile is tapped.
|
||||||
|
final VoidCallback? onPressed;
|
||||||
|
|
||||||
|
/// A boolean to determine if the tile should be highlighted.
|
||||||
|
final bool isHighlighted;
|
||||||
|
|
||||||
|
/// Optional text to display in a badge on the right side of the title.
|
||||||
|
final String? badgeText;
|
||||||
|
|
||||||
|
/// Optional color for the badge background.
|
||||||
|
final Color? badgeColor;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return GestureDetector(
|
||||||
|
onTap: onPressed,
|
||||||
|
child: AnimatedContainer(
|
||||||
|
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
|
||||||
|
decoration: isHighlighted
|
||||||
|
? CustomTheme.highlightedBoxDecoration
|
||||||
|
: CustomTheme.standardBoxDecoration,
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
SizedBox(
|
||||||
|
width: 230,
|
||||||
|
child: Text(
|
||||||
|
title,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 1,
|
||||||
|
softWrap: false,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 18,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (badgeText != null) ...[
|
||||||
|
const Spacer(),
|
||||||
|
Container(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 115),
|
||||||
|
margin: const EdgeInsets.only(top: 4),
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 2,
|
||||||
|
horizontal: 6,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: badgeColor ?? CustomTheme.primaryColor,
|
||||||
|
borderRadius: BorderRadius.circular(4),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
badgeText!,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
maxLines: 1,
|
||||||
|
softWrap: false,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 12,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
if (description.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 5),
|
||||||
|
Text(description, style: const TextStyle(fontSize: 14)),
|
||||||
|
const SizedBox(height: 2.5),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
/// A widget that displays a message centered at the top of the screen with an icon, title, and message.
|
||||||
|
/// - [icon]: The icon to display above the title.
|
||||||
|
/// - [title]: The title text to display.
|
||||||
|
/// - [message]: The message text to display below the title.
|
||||||
class TopCenteredMessage extends StatelessWidget {
|
class TopCenteredMessage extends StatelessWidget {
|
||||||
const TopCenteredMessage({
|
const TopCenteredMessage({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -8,10 +12,15 @@ class TopCenteredMessage extends StatelessWidget {
|
|||||||
required this.message,
|
required this.message,
|
||||||
});
|
});
|
||||||
|
|
||||||
final String title;
|
/// The icon to display above the title.
|
||||||
final String message;
|
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
|
|
||||||
|
/// The title text to display.
|
||||||
|
final String title;
|
||||||
|
|
||||||
|
/// The message text to display below the title.
|
||||||
|
final String message;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:game_tracker/core/enums.dart';
|
import 'package:game_tracker/core/enums.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
import 'package:json_schema/json_schema.dart';
|
import 'package:json_schema/json_schema.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@@ -16,7 +16,7 @@ class DataTransferService {
|
|||||||
/// Deletes all data from the database.
|
/// Deletes all data from the database.
|
||||||
static Future<void> deleteAllData(BuildContext context) async {
|
static Future<void> deleteAllData(BuildContext context) async {
|
||||||
final db = Provider.of<AppDatabase>(context, listen: false);
|
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
await db.gameDao.deleteAllGames();
|
await db.matchDao.deleteAllMatches();
|
||||||
await db.groupDao.deleteAllGroups();
|
await db.groupDao.deleteAllGroups();
|
||||||
await db.playerDao.deleteAllPlayers();
|
await db.playerDao.deleteAllPlayers();
|
||||||
}
|
}
|
||||||
@@ -25,15 +25,31 @@ class DataTransferService {
|
|||||||
/// Returns the JSON string representation of the data.
|
/// Returns the JSON string representation of the data.
|
||||||
static Future<String> getAppDataAsJson(BuildContext context) async {
|
static Future<String> getAppDataAsJson(BuildContext context) async {
|
||||||
final db = Provider.of<AppDatabase>(context, listen: false);
|
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
final games = await db.gameDao.getAllGames();
|
final matches = await db.matchDao.getAllMatches();
|
||||||
final groups = await db.groupDao.getAllGroups();
|
final groups = await db.groupDao.getAllGroups();
|
||||||
final players = await db.playerDao.getAllPlayers();
|
final players = await db.playerDao.getAllPlayers();
|
||||||
|
|
||||||
// Construct a JSON representation of the data
|
// Construct a JSON representation of the data
|
||||||
final Map<String, dynamic> jsonMap = {
|
final Map<String, dynamic> jsonMap = {
|
||||||
'games': games.map((game) => game.toJson()).toList(),
|
'players': players.map((p) => p.toJson()).toList(),
|
||||||
'groups': groups.map((group) => group.toJson()).toList(),
|
|
||||||
'players': players.map((player) => player.toJson()).toList(),
|
'groups': groups
|
||||||
|
.map((g) => {
|
||||||
|
'id': g.id,
|
||||||
|
'name': g.name,
|
||||||
|
'createdAt': g.createdAt.toIso8601String(),
|
||||||
|
'memberIds': (g.members).map((m) => m.id).toList(),
|
||||||
|
}).toList(),
|
||||||
|
|
||||||
|
'matches': matches
|
||||||
|
.map((m) => {
|
||||||
|
'id': m.id,
|
||||||
|
'name': m.name,
|
||||||
|
'createdAt': m.createdAt.toIso8601String(),
|
||||||
|
'groupId': m.group?.id,
|
||||||
|
'playerIds': (m.players ?? []).map((p) => p.id).toList(),
|
||||||
|
'winnerId': m.winner?.id,
|
||||||
|
}).toList(),
|
||||||
};
|
};
|
||||||
|
|
||||||
return json.encode(jsonMap);
|
return json.encode(jsonMap);
|
||||||
@@ -46,7 +62,7 @@ class DataTransferService {
|
|||||||
/// [fileName] The desired name for the exported file (without extension).
|
/// [fileName] The desired name for the exported file (without extension).
|
||||||
static Future<ExportResult> exportData(
|
static Future<ExportResult> exportData(
|
||||||
String jsonString,
|
String jsonString,
|
||||||
String fileName,
|
String fileName
|
||||||
) async {
|
) async {
|
||||||
try {
|
try {
|
||||||
final bytes = Uint8List.fromList(utf8.encode(jsonString));
|
final bytes = Uint8List.fromList(utf8.encode(jsonString));
|
||||||
@@ -54,11 +70,13 @@ class DataTransferService {
|
|||||||
fileName: '$fileName.json',
|
fileName: '$fileName.json',
|
||||||
bytes: bytes,
|
bytes: bytes,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (path == null) {
|
if (path == null) {
|
||||||
return ExportResult.canceled;
|
return ExportResult.canceled;
|
||||||
} else {
|
} else {
|
||||||
return ExportResult.success;
|
return ExportResult.success;
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (e, stack) {
|
} catch (e, stack) {
|
||||||
print('[exportData] $e');
|
print('[exportData] $e');
|
||||||
print(stack);
|
print(stack);
|
||||||
@@ -81,41 +99,77 @@ class DataTransferService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final jsonString = await _readFileContent(path.files.single);
|
final jsonString = await _readFileContent(path.files.single);
|
||||||
if (jsonString == null) {
|
if (jsonString == null) return ImportResult.fileReadError;
|
||||||
return ImportResult.fileReadError;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (await _validateJsonSchema(jsonString)) {
|
final isValid = await _validateJsonSchema(jsonString);
|
||||||
final Map<String, dynamic> jsonData =
|
if (!isValid) return ImportResult.invalidSchema;
|
||||||
json.decode(jsonString) as Map<String, dynamic>;
|
|
||||||
|
|
||||||
final List<dynamic>? gamesJson = jsonData['games'] as List<dynamic>?;
|
final Map<String, dynamic> decoded = json.decode(jsonString) as Map<String, dynamic>;
|
||||||
final List<dynamic>? groupsJson = jsonData['groups'] as List<dynamic>?;
|
|
||||||
final List<dynamic>? playersJson =
|
|
||||||
jsonData['players'] as List<dynamic>?;
|
|
||||||
|
|
||||||
final List<Game> importedGames =
|
final List<dynamic> playersJson = (decoded['players'] as List<dynamic>?) ?? [];
|
||||||
gamesJson
|
final List<dynamic> groupsJson = (decoded['groups'] as List<dynamic>?) ?? [];
|
||||||
?.map((g) => Game.fromJson(g as Map<String, dynamic>))
|
final List<dynamic> matchesJson = (decoded['matches'] as List<dynamic>?) ?? [];
|
||||||
.toList() ??
|
|
||||||
[];
|
// Players
|
||||||
final List<Group> importedGroups =
|
final List<Player> importedPlayers = playersJson
|
||||||
groupsJson
|
.map((p) => Player.fromJson(p as Map<String, dynamic>))
|
||||||
?.map((g) => Group.fromJson(g as Map<String, dynamic>))
|
.toList();
|
||||||
.toList() ??
|
|
||||||
[];
|
final Map<String, Player> playerById = {
|
||||||
final List<Player> importedPlayers =
|
for (final p in importedPlayers) p.id: p,
|
||||||
playersJson
|
};
|
||||||
?.map((p) => Player.fromJson(p as Map<String, dynamic>))
|
|
||||||
.toList() ??
|
// Groups
|
||||||
[];
|
final List<Group> importedGroups = groupsJson.map((g) {
|
||||||
|
final map = g as Map<String, dynamic>;
|
||||||
|
final memberIds = (map['memberIds'] as List<dynamic>? ?? []).cast<String>();
|
||||||
|
|
||||||
|
final members = memberIds
|
||||||
|
.map((id) => playerById[id])
|
||||||
|
.whereType<Player>()
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return Group(
|
||||||
|
id: map['id'] as String,
|
||||||
|
name: map['name'] as String,
|
||||||
|
members: members,
|
||||||
|
createdAt: DateTime.parse(map['createdAt'] as String),
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
final Map<String, Group> groupById = {
|
||||||
|
for (final g in importedGroups) g.id: g,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Matches
|
||||||
|
final List<Match> importedMatches = matchesJson.map((m) {
|
||||||
|
final map = m as Map<String, dynamic>;
|
||||||
|
|
||||||
|
final String? groupId = map['groupId'] as String?;
|
||||||
|
final List<String> playerIds = (map['playerIds'] as List<dynamic>? ?? []).cast<String>();
|
||||||
|
final String? winnerId = map['winnerId'] as String?;
|
||||||
|
|
||||||
|
final group = (groupId == null) ? null : groupById[groupId];
|
||||||
|
final players = playerIds
|
||||||
|
.map((id) => playerById[id])
|
||||||
|
.whereType<Player>()
|
||||||
|
.toList();
|
||||||
|
final winner = (winnerId == null) ? null : playerById[winnerId];
|
||||||
|
|
||||||
|
return Match(
|
||||||
|
id: map['id'] as String,
|
||||||
|
name: map['name'] as String,
|
||||||
|
group: group,
|
||||||
|
players: players,
|
||||||
|
createdAt: DateTime.parse(map['createdAt'] as String),
|
||||||
|
winner: winner,
|
||||||
|
);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
await db.playerDao.addPlayersAsList(players: importedPlayers);
|
||||||
|
await db.groupDao.addGroupsAsList(groups: importedGroups);
|
||||||
|
await db.matchDao.addMatchAsList(matches: importedMatches);
|
||||||
|
|
||||||
await db.playerDao.addPlayersAsList(players: importedPlayers);
|
|
||||||
await db.groupDao.addGroupsAsList(groups: importedGroups);
|
|
||||||
await db.gameDao.addGamesAsList(games: importedGames);
|
|
||||||
} else {
|
|
||||||
return ImportResult.invalidSchema;
|
|
||||||
}
|
|
||||||
return ImportResult.success;
|
return ImportResult.success;
|
||||||
} on FormatException catch (e, stack) {
|
} on FormatException catch (e, stack) {
|
||||||
print('[importData] FormatException');
|
print('[importData] FormatException');
|
||||||
@@ -158,4 +212,4 @@ class DataTransferService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,9 @@ dependencies:
|
|||||||
json_schema: ^5.2.2
|
json_schema: ^5.2.2
|
||||||
file_saver: ^0.3.1
|
file_saver: ^0.3.1
|
||||||
clock: ^1.1.2
|
clock: ^1.1.2
|
||||||
intl: ^0.18.0
|
intl: any
|
||||||
|
flutter_localizations:
|
||||||
|
sdk: flutter
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
@@ -35,5 +37,6 @@ dev_dependencies:
|
|||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
generate: true
|
||||||
assets:
|
assets:
|
||||||
- assets/schema.json
|
- assets/schema.json
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import 'package:drift/drift.dart';
|
|||||||
import 'package:drift/native.dart';
|
import 'package:drift/native.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@@ -16,14 +16,14 @@ void main() {
|
|||||||
late Player testPlayer5;
|
late Player testPlayer5;
|
||||||
late Group testGroup1;
|
late Group testGroup1;
|
||||||
late Group testGroup2;
|
late Group testGroup2;
|
||||||
late Game testGame1;
|
late Match testMatch1;
|
||||||
late Game testGame2;
|
late Match testMatch2;
|
||||||
late Game testGameOnlyPlayers;
|
late Match testMatchOnlyPlayers;
|
||||||
late Game testGameOnlyGroup;
|
late Match testMatchOnlyGroup;
|
||||||
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
|
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
|
||||||
final fakeClock = Clock(() => fixedDate);
|
final fakeClock = Clock(() => fixedDate);
|
||||||
|
|
||||||
setUp(() {
|
setUp(() async {
|
||||||
database = AppDatabase(
|
database = AppDatabase(
|
||||||
DatabaseConnection(
|
DatabaseConnection(
|
||||||
NativeDatabase.memory(),
|
NativeDatabase.memory(),
|
||||||
@@ -46,46 +46,61 @@ void main() {
|
|||||||
name: 'Test Group 2',
|
name: 'Test Group 2',
|
||||||
members: [testPlayer4, testPlayer5],
|
members: [testPlayer4, testPlayer5],
|
||||||
);
|
);
|
||||||
testGame1 = Game(
|
testMatch1 = Match(
|
||||||
name: 'First Test Game',
|
name: 'First Test Match',
|
||||||
group: testGroup1,
|
group: testGroup1,
|
||||||
players: [testPlayer4, testPlayer5],
|
players: [testPlayer4, testPlayer5],
|
||||||
winner: testPlayer4,
|
winner: testPlayer4,
|
||||||
);
|
);
|
||||||
testGame2 = Game(
|
testMatch2 = Match(
|
||||||
name: 'Second Test Game',
|
name: 'Second Test Match',
|
||||||
group: testGroup2,
|
group: testGroup2,
|
||||||
players: [testPlayer1, testPlayer2, testPlayer3],
|
players: [testPlayer1, testPlayer2, testPlayer3],
|
||||||
winner: testPlayer2,
|
winner: testPlayer2,
|
||||||
);
|
);
|
||||||
testGameOnlyPlayers = Game(
|
testMatchOnlyPlayers = Match(
|
||||||
name: 'Test Game with Players',
|
name: 'Test Match with Players',
|
||||||
players: [testPlayer1, testPlayer2, testPlayer3],
|
players: [testPlayer1, testPlayer2, testPlayer3],
|
||||||
winner: testPlayer3,
|
winner: testPlayer3,
|
||||||
);
|
);
|
||||||
testGameOnlyGroup = Game(name: 'Test Game with Group', group: testGroup2);
|
testMatchOnlyGroup = Match(
|
||||||
|
name: 'Test Match with Group',
|
||||||
|
group: testGroup2,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
await database.playerDao.addPlayersAsList(
|
||||||
|
players: [
|
||||||
|
testPlayer1,
|
||||||
|
testPlayer2,
|
||||||
|
testPlayer3,
|
||||||
|
testPlayer4,
|
||||||
|
testPlayer5,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
await database.groupDao.addGroupsAsList(groups: [testGroup1, testGroup2]);
|
||||||
});
|
});
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
await database.close();
|
await database.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
group('Game Tests', () {
|
group('Match Tests', () {
|
||||||
test('Adding and fetching single game works correctly', () async {
|
test('Adding and fetching single match works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testGame1);
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
|
|
||||||
final result = await database.gameDao.getGameById(gameId: testGame1.id);
|
final result = await database.matchDao.getMatchById(
|
||||||
|
matchId: testMatch1.id,
|
||||||
|
);
|
||||||
|
|
||||||
expect(result.id, testGame1.id);
|
expect(result.id, testMatch1.id);
|
||||||
expect(result.name, testGame1.name);
|
expect(result.name, testMatch1.name);
|
||||||
expect(result.createdAt, testGame1.createdAt);
|
expect(result.createdAt, testMatch1.createdAt);
|
||||||
|
|
||||||
if (result.winner != null && testGame1.winner != null) {
|
if (result.winner != null && testMatch1.winner != null) {
|
||||||
expect(result.winner!.id, testGame1.winner!.id);
|
expect(result.winner!.id, testMatch1.winner!.id);
|
||||||
expect(result.winner!.name, testGame1.winner!.name);
|
expect(result.winner!.name, testMatch1.winner!.name);
|
||||||
expect(result.winner!.createdAt, testGame1.winner!.createdAt);
|
expect(result.winner!.createdAt, testMatch1.winner!.createdAt);
|
||||||
} else {
|
} else {
|
||||||
expect(result.winner, testGame1.winner);
|
expect(result.winner, testMatch1.winner);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result.group != null) {
|
if (result.group != null) {
|
||||||
@@ -99,188 +114,203 @@ void main() {
|
|||||||
fail('Group is null');
|
fail('Group is null');
|
||||||
}
|
}
|
||||||
if (result.players != null) {
|
if (result.players != null) {
|
||||||
expect(result.players!.length, testGame1.players!.length);
|
expect(result.players!.length, testMatch1.players!.length);
|
||||||
|
|
||||||
for (int i = 0; i < testGame1.players!.length; i++) {
|
for (int i = 0; i < testMatch1.players!.length; i++) {
|
||||||
expect(result.players![i].id, testGame1.players![i].id);
|
expect(result.players![i].id, testMatch1.players![i].id);
|
||||||
expect(result.players![i].name, testGame1.players![i].name);
|
expect(result.players![i].name, testMatch1.players![i].name);
|
||||||
expect(result.players![i].createdAt, testGame1.players![i].createdAt);
|
expect(
|
||||||
|
result.players![i].createdAt,
|
||||||
|
testMatch1.players![i].createdAt,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fail('Players is null');
|
fail('Players is null');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Adding and fetching multiple games works correctly', () async {
|
test('Adding and fetching multiple matches works correctly', () async {
|
||||||
await database.gameDao.addGamesAsList(
|
await database.matchDao.addMatchAsList(
|
||||||
games: [testGame1, testGame2, testGameOnlyGroup, testGameOnlyPlayers],
|
matches: [
|
||||||
|
testMatch1,
|
||||||
|
testMatch2,
|
||||||
|
testMatchOnlyGroup,
|
||||||
|
testMatchOnlyPlayers,
|
||||||
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
final allGames = await database.gameDao.getAllGames();
|
final allMatches = await database.matchDao.getAllMatches();
|
||||||
expect(allGames.length, 4);
|
expect(allMatches.length, 4);
|
||||||
|
|
||||||
final testGames = {
|
final testMatches = {
|
||||||
testGame1.id: testGame1,
|
testMatch1.id: testMatch1,
|
||||||
testGame2.id: testGame2,
|
testMatch2.id: testMatch2,
|
||||||
testGameOnlyGroup.id: testGameOnlyGroup,
|
testMatchOnlyGroup.id: testMatchOnlyGroup,
|
||||||
testGameOnlyPlayers.id: testGameOnlyPlayers,
|
testMatchOnlyPlayers.id: testMatchOnlyPlayers,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (final game in allGames) {
|
for (final match in allMatches) {
|
||||||
final testGame = testGames[game.id]!;
|
final testMatch = testMatches[match.id]!;
|
||||||
|
|
||||||
// Game-Checks
|
// Match-Checks
|
||||||
expect(game.id, testGame.id);
|
expect(match.id, testMatch.id);
|
||||||
expect(game.name, testGame.name);
|
expect(match.name, testMatch.name);
|
||||||
expect(game.createdAt, testGame.createdAt);
|
expect(match.createdAt, testMatch.createdAt);
|
||||||
if (game.winner != null && testGame.winner != null) {
|
if (match.winner != null && testMatch.winner != null) {
|
||||||
expect(game.winner!.id, testGame.winner!.id);
|
expect(match.winner!.id, testMatch.winner!.id);
|
||||||
expect(game.winner!.name, testGame.winner!.name);
|
expect(match.winner!.name, testMatch.winner!.name);
|
||||||
expect(game.winner!.createdAt, testGame.winner!.createdAt);
|
expect(match.winner!.createdAt, testMatch.winner!.createdAt);
|
||||||
} else {
|
} else {
|
||||||
expect(game.winner, testGame.winner);
|
expect(match.winner, testMatch.winner);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Group-Checks
|
// Group-Checks
|
||||||
if (testGame.group != null) {
|
if (testMatch.group != null) {
|
||||||
expect(game.group!.id, testGame.group!.id);
|
expect(match.group!.id, testMatch.group!.id);
|
||||||
expect(game.group!.name, testGame.group!.name);
|
expect(match.group!.name, testMatch.group!.name);
|
||||||
expect(game.group!.createdAt, testGame.group!.createdAt);
|
expect(match.group!.createdAt, testMatch.group!.createdAt);
|
||||||
|
|
||||||
// Group Members-Checks
|
// Group Members-Checks
|
||||||
expect(game.group!.members.length, testGame.group!.members.length);
|
expect(match.group!.members.length, testMatch.group!.members.length);
|
||||||
for (int i = 0; i < testGame.group!.members.length; i++) {
|
for (int i = 0; i < testMatch.group!.members.length; i++) {
|
||||||
expect(game.group!.members[i].id, testGame.group!.members[i].id);
|
expect(match.group!.members[i].id, testMatch.group!.members[i].id);
|
||||||
expect(
|
expect(
|
||||||
game.group!.members[i].name,
|
match.group!.members[i].name,
|
||||||
testGame.group!.members[i].name,
|
testMatch.group!.members[i].name,
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
game.group!.members[i].createdAt,
|
match.group!.members[i].createdAt,
|
||||||
testGame.group!.members[i].createdAt,
|
testMatch.group!.members[i].createdAt,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
expect(game.group, null);
|
expect(match.group, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Players-Checks
|
// Players-Checks
|
||||||
if (testGame.players != null) {
|
if (testMatch.players != null) {
|
||||||
expect(game.players!.length, testGame.players!.length);
|
expect(match.players!.length, testMatch.players!.length);
|
||||||
for (int i = 0; i < testGame.players!.length; i++) {
|
for (int i = 0; i < testMatch.players!.length; i++) {
|
||||||
expect(game.players![i].id, testGame.players![i].id);
|
expect(match.players![i].id, testMatch.players![i].id);
|
||||||
expect(game.players![i].name, testGame.players![i].name);
|
expect(match.players![i].name, testMatch.players![i].name);
|
||||||
expect(game.players![i].createdAt, testGame.players![i].createdAt);
|
expect(
|
||||||
|
match.players![i].createdAt,
|
||||||
|
testMatch.players![i].createdAt,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
expect(game.players, null);
|
expect(match.players, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Adding the same game twice does not create duplicates', () async {
|
test('Adding the same match twice does not create duplicates', () async {
|
||||||
await database.gameDao.addGame(game: testGame1);
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
await database.gameDao.addGame(game: testGame1);
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
|
|
||||||
final gameCount = await database.gameDao.getGameCount();
|
final matchCount = await database.matchDao.getMatchCount();
|
||||||
expect(gameCount, 1);
|
expect(matchCount, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Game existence check works correctly', () async {
|
test('Match existence check works correctly', () async {
|
||||||
var gameExists = await database.gameDao.gameExists(gameId: testGame1.id);
|
var matchExists = await database.matchDao.matchExists(
|
||||||
expect(gameExists, false);
|
matchId: testMatch1.id,
|
||||||
|
|
||||||
await database.gameDao.addGame(game: testGame1);
|
|
||||||
|
|
||||||
gameExists = await database.gameDao.gameExists(gameId: testGame1.id);
|
|
||||||
expect(gameExists, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Deleting a game works correctly', () async {
|
|
||||||
await database.gameDao.addGame(game: testGame1);
|
|
||||||
|
|
||||||
final gameDeleted = await database.gameDao.deleteGame(
|
|
||||||
gameId: testGame1.id,
|
|
||||||
);
|
);
|
||||||
expect(gameDeleted, true);
|
expect(matchExists, false);
|
||||||
|
|
||||||
final gameExists = await database.gameDao.gameExists(
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
gameId: testGame1.id,
|
|
||||||
|
matchExists = await database.matchDao.matchExists(matchId: testMatch1.id);
|
||||||
|
expect(matchExists, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Deleting a match works correctly', () async {
|
||||||
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
|
|
||||||
|
final matchDeleted = await database.matchDao.deleteMatch(
|
||||||
|
matchId: testMatch1.id,
|
||||||
);
|
);
|
||||||
expect(gameExists, false);
|
expect(matchDeleted, true);
|
||||||
|
|
||||||
|
final matchExists = await database.matchDao.matchExists(
|
||||||
|
matchId: testMatch1.id,
|
||||||
|
);
|
||||||
|
expect(matchExists, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Getting the game count works correctly', () async {
|
test('Getting the match count works correctly', () async {
|
||||||
var gameCount = await database.gameDao.getGameCount();
|
var matchCount = await database.matchDao.getMatchCount();
|
||||||
expect(gameCount, 0);
|
expect(matchCount, 0);
|
||||||
|
|
||||||
await database.gameDao.addGame(game: testGame1);
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
|
|
||||||
gameCount = await database.gameDao.getGameCount();
|
matchCount = await database.matchDao.getMatchCount();
|
||||||
expect(gameCount, 1);
|
expect(matchCount, 1);
|
||||||
|
|
||||||
await database.gameDao.addGame(game: testGame2);
|
await database.matchDao.addMatch(match: testMatch2);
|
||||||
|
|
||||||
gameCount = await database.gameDao.getGameCount();
|
matchCount = await database.matchDao.getMatchCount();
|
||||||
expect(gameCount, 2);
|
expect(matchCount, 2);
|
||||||
|
|
||||||
await database.gameDao.deleteGame(gameId: testGame1.id);
|
await database.matchDao.deleteMatch(matchId: testMatch1.id);
|
||||||
|
|
||||||
gameCount = await database.gameDao.getGameCount();
|
matchCount = await database.matchDao.getMatchCount();
|
||||||
expect(gameCount, 1);
|
expect(matchCount, 1);
|
||||||
|
|
||||||
await database.gameDao.deleteGame(gameId: testGame2.id);
|
await database.matchDao.deleteMatch(matchId: testMatch2.id);
|
||||||
|
|
||||||
gameCount = await database.gameDao.getGameCount();
|
matchCount = await database.matchDao.getMatchCount();
|
||||||
expect(gameCount, 0);
|
expect(matchCount, 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Checking if game has winner works correclty', () async {
|
test('Checking if match has winner works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testGame1);
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
await database.gameDao.addGame(game: testGameOnlyGroup);
|
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||||
|
|
||||||
var hasWinner = await database.gameDao.hasWinner(gameId: testGame1.id);
|
var hasWinner = await database.matchDao.hasWinner(matchId: testMatch1.id);
|
||||||
expect(hasWinner, true);
|
expect(hasWinner, true);
|
||||||
|
|
||||||
hasWinner = await database.gameDao.hasWinner(
|
hasWinner = await database.matchDao.hasWinner(
|
||||||
gameId: testGameOnlyGroup.id,
|
matchId: testMatchOnlyGroup.id,
|
||||||
);
|
);
|
||||||
expect(hasWinner, false);
|
expect(hasWinner, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Fetching the winner of a game works correctly', () async {
|
test('Fetching the winner of a match works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testGame1);
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
|
|
||||||
final winner = await database.gameDao.getWinner(gameId: testGame1.id);
|
final winner = await database.matchDao.getWinner(matchId: testMatch1.id);
|
||||||
if (winner == null) {
|
if (winner == null) {
|
||||||
fail('Winner is null');
|
fail('Winner is null');
|
||||||
} else {
|
} else {
|
||||||
expect(winner.id, testGame1.winner!.id);
|
expect(winner.id, testMatch1.winner!.id);
|
||||||
expect(winner.name, testGame1.winner!.name);
|
expect(winner.name, testMatch1.winner!.name);
|
||||||
expect(winner.createdAt, testGame1.winner!.createdAt);
|
expect(winner.createdAt, testMatch1.winner!.createdAt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Updating the winner of a game works correctly', () async {
|
test('Updating the winner of a match works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testGame1);
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
|
|
||||||
final winner = await database.gameDao.getWinner(gameId: testGame1.id);
|
final winner = await database.matchDao.getWinner(matchId: testMatch1.id);
|
||||||
if (winner == null) {
|
if (winner == null) {
|
||||||
fail('Winner is null');
|
fail('Winner is null');
|
||||||
} else {
|
} else {
|
||||||
expect(winner.id, testGame1.winner!.id);
|
expect(winner.id, testMatch1.winner!.id);
|
||||||
expect(winner.name, testGame1.winner!.name);
|
expect(winner.name, testMatch1.winner!.name);
|
||||||
expect(winner.createdAt, testGame1.winner!.createdAt);
|
expect(winner.createdAt, testMatch1.winner!.createdAt);
|
||||||
expect(winner.id, testPlayer4.id);
|
expect(winner.id, testPlayer4.id);
|
||||||
expect(winner.id != testPlayer5.id, true);
|
expect(winner.id != testPlayer5.id, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
await database.gameDao.setWinner(
|
await database.matchDao.setWinner(
|
||||||
gameId: testGame1.id,
|
matchId: testMatch1.id,
|
||||||
winnerId: testPlayer5.id,
|
winnerId: testPlayer5.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
final newWinner = await database.gameDao.getWinner(gameId: testGame1.id);
|
final newWinner = await database.matchDao.getWinner(
|
||||||
|
matchId: testMatch1.id,
|
||||||
|
);
|
||||||
|
|
||||||
if (newWinner == null) {
|
if (newWinner == null) {
|
||||||
fail('New winner is null');
|
fail('New winner is null');
|
||||||
@@ -292,39 +322,41 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Removing a winner works correctly', () async {
|
test('Removing a winner works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testGame2);
|
await database.matchDao.addMatch(match: testMatch2);
|
||||||
|
|
||||||
var hasWinner = await database.gameDao.hasWinner(gameId: testGame2.id);
|
var hasWinner = await database.matchDao.hasWinner(matchId: testMatch2.id);
|
||||||
expect(hasWinner, true);
|
expect(hasWinner, true);
|
||||||
|
|
||||||
await database.gameDao.removeWinner(gameId: testGame2.id);
|
await database.matchDao.removeWinner(matchId: testMatch2.id);
|
||||||
|
|
||||||
hasWinner = await database.gameDao.hasWinner(gameId: testGame2.id);
|
hasWinner = await database.matchDao.hasWinner(matchId: testMatch2.id);
|
||||||
expect(hasWinner, false);
|
expect(hasWinner, false);
|
||||||
|
|
||||||
final removedWinner = await database.gameDao.getWinner(
|
final removedWinner = await database.matchDao.getWinner(
|
||||||
gameId: testGame2.id,
|
matchId: testMatch2.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(removedWinner, null);
|
expect(removedWinner, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Renaming a game works correctly', () async {
|
test('Renaming a match works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testGame1);
|
await database.matchDao.addMatch(match: testMatch1);
|
||||||
|
|
||||||
var fetchedGame = await database.gameDao.getGameById(
|
var fetchedMatch = await database.matchDao.getMatchById(
|
||||||
gameId: testGame1.id,
|
matchId: testMatch1.id,
|
||||||
);
|
);
|
||||||
expect(fetchedGame.name, testGame1.name);
|
expect(fetchedMatch.name, testMatch1.name);
|
||||||
|
|
||||||
const newName = 'Updated Game Name';
|
const newName = 'Updated Match Name';
|
||||||
await database.gameDao.updateGameName(
|
await database.matchDao.updateMatchName(
|
||||||
gameId: testGame1.id,
|
matchId: testMatch1.id,
|
||||||
newName: newName,
|
newName: newName,
|
||||||
);
|
);
|
||||||
|
|
||||||
fetchedGame = await database.gameDao.getGameById(gameId: testGame1.id);
|
fetchedMatch = await database.matchDao.getMatchById(
|
||||||
expect(fetchedGame.name, newName);
|
matchId: testMatch1.id,
|
||||||
|
);
|
||||||
|
expect(fetchedMatch.name, newName);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import 'package:clock/clock.dart';
|
import 'package:clock/clock.dart';
|
||||||
import 'package:drift/drift.dart';
|
import 'package:drift/drift.dart' hide isNotNull;
|
||||||
import 'package:drift/native.dart';
|
import 'package:drift/native.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
@@ -16,12 +16,12 @@ void main() {
|
|||||||
late Player testPlayer5;
|
late Player testPlayer5;
|
||||||
late Group testGroup1;
|
late Group testGroup1;
|
||||||
late Group testGroup2;
|
late Group testGroup2;
|
||||||
late Game testgameWithGroup;
|
late Match testMatchWithGroup;
|
||||||
late Game testgameWithPlayers;
|
late Match testMatchWithPlayers;
|
||||||
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
|
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
|
||||||
final fakeClock = Clock(() => fixedDate);
|
final fakeClock = Clock(() => fixedDate);
|
||||||
|
|
||||||
setUp(() {
|
setUp(() async {
|
||||||
database = AppDatabase(
|
database = AppDatabase(
|
||||||
DatabaseConnection(
|
DatabaseConnection(
|
||||||
NativeDatabase.memory(),
|
NativeDatabase.memory(),
|
||||||
@@ -44,81 +44,94 @@ void main() {
|
|||||||
name: 'Test Group',
|
name: 'Test Group',
|
||||||
members: [testPlayer3, testPlayer2],
|
members: [testPlayer3, testPlayer2],
|
||||||
);
|
);
|
||||||
testgameWithPlayers = Game(
|
testMatchWithPlayers = Match(
|
||||||
name: 'Test Game with Players',
|
name: 'Test Match with Players',
|
||||||
players: [testPlayer4, testPlayer5],
|
players: [testPlayer4, testPlayer5],
|
||||||
);
|
);
|
||||||
testgameWithGroup = Game(name: 'Test Game with Group', group: testGroup1);
|
testMatchWithGroup = Match(
|
||||||
|
name: 'Test Match with Group',
|
||||||
|
group: testGroup1,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
await database.playerDao.addPlayersAsList(
|
||||||
|
players: [
|
||||||
|
testPlayer1,
|
||||||
|
testPlayer2,
|
||||||
|
testPlayer3,
|
||||||
|
testPlayer4,
|
||||||
|
testPlayer5,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
await database.groupDao.addGroupsAsList(groups: [testGroup1, testGroup2]);
|
||||||
});
|
});
|
||||||
tearDown(() async {
|
tearDown(() async {
|
||||||
await database.close();
|
await database.close();
|
||||||
});
|
});
|
||||||
group('Group-Game Tests', () {
|
group('Group-Match Tests', () {
|
||||||
test('Game has group works correctly', () async {
|
test('matchHasGroup() has group works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testgameWithPlayers);
|
await database.matchDao.addMatch(match: testMatchWithPlayers);
|
||||||
await database.groupDao.addGroup(group: testGroup1);
|
await database.groupDao.addGroup(group: testGroup1);
|
||||||
|
|
||||||
var gameHasGroup = await database.groupGameDao.gameHasGroup(
|
var matchHasGroup = await database.groupMatchDao.matchHasGroup(
|
||||||
gameId: testgameWithPlayers.id,
|
matchId: testMatchWithPlayers.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(gameHasGroup, false);
|
expect(matchHasGroup, false);
|
||||||
|
|
||||||
await database.groupGameDao.addGroupToGame(
|
await database.groupMatchDao.addGroupToMatch(
|
||||||
gameId: testgameWithPlayers.id,
|
matchId: testMatchWithPlayers.id,
|
||||||
groupId: testGroup1.id,
|
groupId: testGroup1.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
gameHasGroup = await database.groupGameDao.gameHasGroup(
|
matchHasGroup = await database.groupMatchDao.matchHasGroup(
|
||||||
gameId: testgameWithPlayers.id,
|
matchId: testMatchWithPlayers.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(gameHasGroup, true);
|
expect(matchHasGroup, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Adding a group to a game works correctly', () async {
|
test('Adding a group to a match works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testgameWithPlayers);
|
await database.matchDao.addMatch(match: testMatchWithPlayers);
|
||||||
await database.groupDao.addGroup(group: testGroup1);
|
await database.groupDao.addGroup(group: testGroup1);
|
||||||
await database.groupGameDao.addGroupToGame(
|
await database.groupMatchDao.addGroupToMatch(
|
||||||
gameId: testgameWithPlayers.id,
|
matchId: testMatchWithPlayers.id,
|
||||||
groupId: testGroup1.id,
|
groupId: testGroup1.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
var groupAdded = await database.groupGameDao.isGroupInGame(
|
var groupAdded = await database.groupMatchDao.isGroupInMatch(
|
||||||
gameId: testgameWithPlayers.id,
|
matchId: testMatchWithPlayers.id,
|
||||||
groupId: testGroup1.id,
|
groupId: testGroup1.id,
|
||||||
);
|
);
|
||||||
expect(groupAdded, true);
|
expect(groupAdded, true);
|
||||||
|
|
||||||
groupAdded = await database.groupGameDao.isGroupInGame(
|
groupAdded = await database.groupMatchDao.isGroupInMatch(
|
||||||
gameId: testgameWithPlayers.id,
|
matchId: testMatchWithPlayers.id,
|
||||||
groupId: '',
|
groupId: '',
|
||||||
);
|
);
|
||||||
expect(groupAdded, false);
|
expect(groupAdded, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Removing group from game works correctly', () async {
|
test('Removing group from match works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testgameWithGroup);
|
await database.matchDao.addMatch(match: testMatchWithGroup);
|
||||||
|
|
||||||
final groupToRemove = testgameWithGroup.group!;
|
final groupToRemove = testMatchWithGroup.group!;
|
||||||
|
|
||||||
final removed = await database.groupGameDao.removeGroupFromGame(
|
final removed = await database.groupMatchDao.removeGroupFromMatch(
|
||||||
groupId: groupToRemove.id,
|
groupId: groupToRemove.id,
|
||||||
gameId: testgameWithGroup.id,
|
matchId: testMatchWithGroup.id,
|
||||||
);
|
);
|
||||||
expect(removed, true);
|
expect(removed, true);
|
||||||
|
|
||||||
final result = await database.gameDao.getGameById(
|
final result = await database.matchDao.getMatchById(
|
||||||
gameId: testgameWithGroup.id,
|
matchId: testMatchWithGroup.id,
|
||||||
);
|
);
|
||||||
expect(result.group, null);
|
expect(result.group, null);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Retrieving group of a game works correctly', () async {
|
test('Retrieving group of a match works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testgameWithGroup);
|
await database.matchDao.addMatch(match: testMatchWithGroup);
|
||||||
final group = await database.groupGameDao.getGroupOfGame(
|
final group = await database.groupMatchDao.getGroupOfMatch(
|
||||||
gameId: testgameWithGroup.id,
|
matchId: testMatchWithGroup.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
@@ -136,11 +149,11 @@ void main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Updating the group of a game works correctly', () async {
|
test('Updating the group of a match works correctly', () async {
|
||||||
await database.gameDao.addGame(game: testgameWithGroup);
|
await database.matchDao.addMatch(match: testMatchWithGroup);
|
||||||
|
|
||||||
var group = await database.groupGameDao.getGroupOfGame(
|
var group = await database.groupMatchDao.getGroupOfMatch(
|
||||||
gameId: testgameWithGroup.id,
|
matchId: testMatchWithGroup.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
@@ -153,13 +166,13 @@ void main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await database.groupDao.addGroup(group: testGroup2);
|
await database.groupDao.addGroup(group: testGroup2);
|
||||||
await database.groupGameDao.updateGroupOfGame(
|
await database.groupMatchDao.updateGroupOfMatch(
|
||||||
gameId: testgameWithGroup.id,
|
matchId: testMatchWithGroup.id,
|
||||||
newGroupId: testGroup2.id,
|
newGroupId: testGroup2.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
group = await database.groupGameDao.getGroupOfGame(
|
group = await database.groupMatchDao.getGroupOfMatch(
|
||||||
gameId: testgameWithGroup.id,
|
matchId: testMatchWithGroup.id,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
@@ -176,5 +189,33 @@ void main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Adding the same group to seperate matches works correctly', () async {
|
||||||
|
final match1 = Match(name: 'Match 1', group: testGroup1);
|
||||||
|
final match2 = Match(name: 'Match 2', group: testGroup1);
|
||||||
|
|
||||||
|
await Future.wait([
|
||||||
|
database.matchDao.addMatch(match: match1),
|
||||||
|
database.matchDao.addMatch(match: match2),
|
||||||
|
]);
|
||||||
|
|
||||||
|
final group1 = await database.groupMatchDao.getGroupOfMatch(
|
||||||
|
matchId: match1.id,
|
||||||
|
);
|
||||||
|
final group2 = await database.groupMatchDao.getGroupOfMatch(
|
||||||
|
matchId: match2.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(group1, isNotNull);
|
||||||
|
expect(group2, isNotNull);
|
||||||
|
|
||||||
|
final groups = [group1!, group2!];
|
||||||
|
for (final group in groups) {
|
||||||
|
expect(group.members.length, testGroup1.members.length);
|
||||||
|
expect(group.id, testGroup1.id);
|
||||||
|
expect(group.name, testGroup1.name);
|
||||||
|
expect(group.createdAt, testGroup1.createdAt);
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1,183 +0,0 @@
|
|||||||
import 'package:clock/clock.dart';
|
|
||||||
import 'package:drift/drift.dart';
|
|
||||||
import 'package:drift/native.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
late AppDatabase database;
|
|
||||||
late Player testPlayer1;
|
|
||||||
late Player testPlayer2;
|
|
||||||
late Player testPlayer3;
|
|
||||||
late Player testPlayer4;
|
|
||||||
late Player testPlayer5;
|
|
||||||
late Player testPlayer6;
|
|
||||||
late Group testgroup;
|
|
||||||
late Game testGameOnlyGroup;
|
|
||||||
late Game testGameOnlyPlayers;
|
|
||||||
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
|
|
||||||
final fakeClock = Clock(() => fixedDate);
|
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
database = AppDatabase(
|
|
||||||
DatabaseConnection(
|
|
||||||
NativeDatabase.memory(),
|
|
||||||
// Recommended for widget tests to avoid test errors.
|
|
||||||
closeStreamsSynchronously: true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
withClock(fakeClock, () {
|
|
||||||
testPlayer1 = Player(name: 'Alice');
|
|
||||||
testPlayer2 = Player(name: 'Bob');
|
|
||||||
testPlayer3 = Player(name: 'Charlie');
|
|
||||||
testPlayer4 = Player(name: 'Diana');
|
|
||||||
testPlayer5 = Player(name: 'Eve');
|
|
||||||
testPlayer6 = Player(name: 'Frank');
|
|
||||||
testgroup = Group(
|
|
||||||
name: 'Test Group',
|
|
||||||
members: [testPlayer1, testPlayer2, testPlayer3],
|
|
||||||
);
|
|
||||||
testGameOnlyGroup = Game(name: 'Test Game with Group', group: testgroup);
|
|
||||||
testGameOnlyPlayers = Game(
|
|
||||||
name: 'Test Game with Players',
|
|
||||||
players: [testPlayer4, testPlayer5, testPlayer6],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
tearDown(() async {
|
|
||||||
await database.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
group('Player-Game Tests', () {
|
|
||||||
test('Game has player works correctly', () async {
|
|
||||||
await database.gameDao.addGame(game: testGameOnlyGroup);
|
|
||||||
await database.playerDao.addPlayer(player: testPlayer1);
|
|
||||||
|
|
||||||
var gameHasPlayers = await database.playerGameDao.gameHasPlayers(
|
|
||||||
gameId: testGameOnlyGroup.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(gameHasPlayers, false);
|
|
||||||
|
|
||||||
await database.playerGameDao.addPlayerToGame(
|
|
||||||
gameId: testGameOnlyGroup.id,
|
|
||||||
playerId: testPlayer1.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
gameHasPlayers = await database.playerGameDao.gameHasPlayers(
|
|
||||||
gameId: testGameOnlyGroup.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(gameHasPlayers, true);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Adding a player to a game works correctly', () async {
|
|
||||||
await database.gameDao.addGame(game: testGameOnlyGroup);
|
|
||||||
await database.playerDao.addPlayer(player: testPlayer5);
|
|
||||||
await database.playerGameDao.addPlayerToGame(
|
|
||||||
gameId: testGameOnlyGroup.id,
|
|
||||||
playerId: testPlayer5.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
var playerAdded = await database.playerGameDao.isPlayerInGame(
|
|
||||||
gameId: testGameOnlyGroup.id,
|
|
||||||
playerId: testPlayer5.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(playerAdded, true);
|
|
||||||
|
|
||||||
playerAdded = await database.playerGameDao.isPlayerInGame(
|
|
||||||
gameId: testGameOnlyGroup.id,
|
|
||||||
playerId: '',
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(playerAdded, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Removing player from game works correctly', () async {
|
|
||||||
await database.gameDao.addGame(game: testGameOnlyPlayers);
|
|
||||||
|
|
||||||
final playerToRemove = testGameOnlyPlayers.players![0];
|
|
||||||
|
|
||||||
final removed = await database.playerGameDao.removePlayerFromGame(
|
|
||||||
playerId: playerToRemove.id,
|
|
||||||
gameId: testGameOnlyPlayers.id,
|
|
||||||
);
|
|
||||||
expect(removed, true);
|
|
||||||
|
|
||||||
final result = await database.gameDao.getGameById(
|
|
||||||
gameId: testGameOnlyPlayers.id,
|
|
||||||
);
|
|
||||||
expect(result.players!.length, testGameOnlyPlayers.players!.length - 1);
|
|
||||||
|
|
||||||
final playerExists = result.players!.any(
|
|
||||||
(p) => p.id == playerToRemove.id,
|
|
||||||
);
|
|
||||||
expect(playerExists, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Retrieving players of a game works correctly', () async {
|
|
||||||
await database.gameDao.addGame(game: testGameOnlyPlayers);
|
|
||||||
final players = await database.playerGameDao.getPlayersOfGame(
|
|
||||||
gameId: testGameOnlyPlayers.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (players == null) {
|
|
||||||
fail('Players should not be null');
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < players.length; i++) {
|
|
||||||
expect(players[i].id, testGameOnlyPlayers.players![i].id);
|
|
||||||
expect(players[i].name, testGameOnlyPlayers.players![i].name);
|
|
||||||
expect(players[i].createdAt, testGameOnlyPlayers.players![i].createdAt);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Updating the games players works coreclty', () async {
|
|
||||||
await database.gameDao.addGame(game: testGameOnlyPlayers);
|
|
||||||
|
|
||||||
final newPlayers = [testPlayer1, testPlayer2, testPlayer4];
|
|
||||||
await database.playerDao.addPlayersAsList(players: newPlayers);
|
|
||||||
|
|
||||||
// First, remove all existing players
|
|
||||||
final existingPlayers = await database.playerGameDao.getPlayersOfGame(
|
|
||||||
gameId: testGameOnlyPlayers.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existingPlayers == null || existingPlayers.isEmpty) {
|
|
||||||
fail('Existing players should not be null or empty');
|
|
||||||
}
|
|
||||||
|
|
||||||
await database.playerGameDao.updatePlayersFromGame(
|
|
||||||
gameId: testGameOnlyPlayers.id,
|
|
||||||
newPlayer: newPlayers,
|
|
||||||
);
|
|
||||||
|
|
||||||
final updatedPlayers = await database.playerGameDao.getPlayersOfGame(
|
|
||||||
gameId: testGameOnlyPlayers.id,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (updatedPlayers == null) {
|
|
||||||
fail('Updated players should not be null');
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(updatedPlayers.length, newPlayers.length);
|
|
||||||
|
|
||||||
/// Create a map of new players for easy lookup
|
|
||||||
final testPlayers = {for (var p in newPlayers) p.id: p};
|
|
||||||
|
|
||||||
/// Verify each updated player matches the new players
|
|
||||||
for (final player in updatedPlayers) {
|
|
||||||
final testPlayer = testPlayers[player.id]!;
|
|
||||||
|
|
||||||
expect(player.id, testPlayer.id);
|
|
||||||
expect(player.name, testPlayer.name);
|
|
||||||
expect(player.createdAt, testPlayer.createdAt);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
237
test/db_tests/player_match_test.dart
Normal file
237
test/db_tests/player_match_test.dart
Normal file
@@ -0,0 +1,237 @@
|
|||||||
|
import 'package:clock/clock.dart';
|
||||||
|
import 'package:drift/drift.dart' hide isNotNull;
|
||||||
|
import 'package:drift/native.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
|
import 'package:game_tracker/data/dto/match.dart';
|
||||||
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late AppDatabase database;
|
||||||
|
late Player testPlayer1;
|
||||||
|
late Player testPlayer2;
|
||||||
|
late Player testPlayer3;
|
||||||
|
late Player testPlayer4;
|
||||||
|
late Player testPlayer5;
|
||||||
|
late Player testPlayer6;
|
||||||
|
late Group testgroup;
|
||||||
|
late Match testMatchOnlyGroup;
|
||||||
|
late Match testMatchOnlyPlayers;
|
||||||
|
final fixedDate = DateTime(2025, 19, 11, 00, 11, 23);
|
||||||
|
final fakeClock = Clock(() => fixedDate);
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
database = AppDatabase(
|
||||||
|
DatabaseConnection(
|
||||||
|
NativeDatabase.memory(),
|
||||||
|
// Recommended for widget tests to avoid test errors.
|
||||||
|
closeStreamsSynchronously: true,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
withClock(fakeClock, () {
|
||||||
|
testPlayer1 = Player(name: 'Alice');
|
||||||
|
testPlayer2 = Player(name: 'Bob');
|
||||||
|
testPlayer3 = Player(name: 'Charlie');
|
||||||
|
testPlayer4 = Player(name: 'Diana');
|
||||||
|
testPlayer5 = Player(name: 'Eve');
|
||||||
|
testPlayer6 = Player(name: 'Frank');
|
||||||
|
testgroup = Group(
|
||||||
|
name: 'Test Group',
|
||||||
|
members: [testPlayer1, testPlayer2, testPlayer3],
|
||||||
|
);
|
||||||
|
testMatchOnlyGroup = Match(
|
||||||
|
name: 'Test Match with Group',
|
||||||
|
group: testgroup,
|
||||||
|
);
|
||||||
|
testMatchOnlyPlayers = Match(
|
||||||
|
name: 'Test Match with Players',
|
||||||
|
players: [testPlayer4, testPlayer5, testPlayer6],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
await database.playerDao.addPlayersAsList(
|
||||||
|
players: [
|
||||||
|
testPlayer1,
|
||||||
|
testPlayer2,
|
||||||
|
testPlayer3,
|
||||||
|
testPlayer4,
|
||||||
|
testPlayer5,
|
||||||
|
testPlayer6,
|
||||||
|
],
|
||||||
|
);
|
||||||
|
await database.groupDao.addGroup(group: testgroup);
|
||||||
|
});
|
||||||
|
tearDown(() async {
|
||||||
|
await database.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
group('Player-Match Tests', () {
|
||||||
|
test('Match has player works correctly', () async {
|
||||||
|
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||||
|
await database.playerDao.addPlayer(player: testPlayer1);
|
||||||
|
|
||||||
|
var matchHasPlayers = await database.playerMatchDao.matchHasPlayers(
|
||||||
|
matchId: testMatchOnlyGroup.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(matchHasPlayers, false);
|
||||||
|
|
||||||
|
await database.playerMatchDao.addPlayerToMatch(
|
||||||
|
matchId: testMatchOnlyGroup.id,
|
||||||
|
playerId: testPlayer1.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
matchHasPlayers = await database.playerMatchDao.matchHasPlayers(
|
||||||
|
matchId: testMatchOnlyGroup.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(matchHasPlayers, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Adding a player to a match works correctly', () async {
|
||||||
|
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||||
|
await database.playerDao.addPlayer(player: testPlayer5);
|
||||||
|
await database.playerMatchDao.addPlayerToMatch(
|
||||||
|
matchId: testMatchOnlyGroup.id,
|
||||||
|
playerId: testPlayer5.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
var playerAdded = await database.playerMatchDao.isPlayerInMatch(
|
||||||
|
matchId: testMatchOnlyGroup.id,
|
||||||
|
playerId: testPlayer5.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(playerAdded, true);
|
||||||
|
|
||||||
|
playerAdded = await database.playerMatchDao.isPlayerInMatch(
|
||||||
|
matchId: testMatchOnlyGroup.id,
|
||||||
|
playerId: '',
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(playerAdded, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Removing player from match works correctly', () async {
|
||||||
|
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||||
|
|
||||||
|
final playerToRemove = testMatchOnlyPlayers.players![0];
|
||||||
|
|
||||||
|
final removed = await database.playerMatchDao.removePlayerFromMatch(
|
||||||
|
playerId: playerToRemove.id,
|
||||||
|
matchId: testMatchOnlyPlayers.id,
|
||||||
|
);
|
||||||
|
expect(removed, true);
|
||||||
|
|
||||||
|
final result = await database.matchDao.getMatchById(
|
||||||
|
matchId: testMatchOnlyPlayers.id,
|
||||||
|
);
|
||||||
|
expect(result.players!.length, testMatchOnlyPlayers.players!.length - 1);
|
||||||
|
|
||||||
|
final playerExists = result.players!.any(
|
||||||
|
(p) => p.id == playerToRemove.id,
|
||||||
|
);
|
||||||
|
expect(playerExists, false);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Retrieving players of a match works correctly', () async {
|
||||||
|
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||||
|
final players = await database.playerMatchDao.getPlayersOfMatch(
|
||||||
|
matchId: testMatchOnlyPlayers.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (players == null) {
|
||||||
|
fail('Players should not be null');
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < players.length; i++) {
|
||||||
|
expect(players[i].id, testMatchOnlyPlayers.players![i].id);
|
||||||
|
expect(players[i].name, testMatchOnlyPlayers.players![i].name);
|
||||||
|
expect(
|
||||||
|
players[i].createdAt,
|
||||||
|
testMatchOnlyPlayers.players![i].createdAt,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Updating the match players works coreclty', () async {
|
||||||
|
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||||
|
|
||||||
|
final newPlayers = [testPlayer1, testPlayer2, testPlayer4];
|
||||||
|
await database.playerDao.addPlayersAsList(players: newPlayers);
|
||||||
|
|
||||||
|
// First, remove all existing players
|
||||||
|
final existingPlayers = await database.playerMatchDao.getPlayersOfMatch(
|
||||||
|
matchId: testMatchOnlyPlayers.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (existingPlayers == null || existingPlayers.isEmpty) {
|
||||||
|
fail('Existing players should not be null or empty');
|
||||||
|
}
|
||||||
|
|
||||||
|
await database.playerMatchDao.updatePlayersFromMatch(
|
||||||
|
matchId: testMatchOnlyPlayers.id,
|
||||||
|
newPlayer: newPlayers,
|
||||||
|
);
|
||||||
|
|
||||||
|
final updatedPlayers = await database.playerMatchDao.getPlayersOfMatch(
|
||||||
|
matchId: testMatchOnlyPlayers.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (updatedPlayers == null) {
|
||||||
|
fail('Updated players should not be null');
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(updatedPlayers.length, newPlayers.length);
|
||||||
|
|
||||||
|
/// Create a map of new players for easy lookup
|
||||||
|
final testPlayers = {for (var p in newPlayers) p.id: p};
|
||||||
|
|
||||||
|
/// Verify each updated player matches the new players
|
||||||
|
for (final player in updatedPlayers) {
|
||||||
|
final testPlayer = testPlayers[player.id]!;
|
||||||
|
|
||||||
|
expect(player.id, testPlayer.id);
|
||||||
|
expect(player.name, testPlayer.name);
|
||||||
|
expect(player.createdAt, testPlayer.createdAt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'Adding the same player to seperate matches works correctly',
|
||||||
|
() async {
|
||||||
|
final playersList = [testPlayer1, testPlayer2, testPlayer3];
|
||||||
|
final match1 = Match(name: 'Match 1', players: playersList);
|
||||||
|
final match2 = Match(name: 'Match 2', players: playersList);
|
||||||
|
|
||||||
|
await Future.wait([
|
||||||
|
database.matchDao.addMatch(match: match1),
|
||||||
|
database.matchDao.addMatch(match: match2),
|
||||||
|
]);
|
||||||
|
|
||||||
|
final players1 = await database.playerMatchDao.getPlayersOfMatch(
|
||||||
|
matchId: match1.id,
|
||||||
|
);
|
||||||
|
final players2 = await database.playerMatchDao.getPlayersOfMatch(
|
||||||
|
matchId: match2.id,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(players1, isNotNull);
|
||||||
|
expect(players2, isNotNull);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
players1!.map((p) => p.id).toList(),
|
||||||
|
equals(players2!.map((p) => p.id).toList()),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
players1.map((p) => p.name).toList(),
|
||||||
|
equals(players2.map((p) => p.name).toList()),
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
players1.map((p) => p.createdAt).toList(),
|
||||||
|
equals(players2.map((p) => p.createdAt).toList()),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user