Compare commits
96 Commits
e881cf0555
...
feature/11
| Author | SHA1 | Date | |
|---|---|---|---|
| 43e9196dca | |||
| 16dc9746bc | |||
| 487a921def | |||
| 69f9900f74 | |||
| 69d9397ab3 | |||
| 9c92ded4fa | |||
| d577acc185 | |||
| 244c1b0bb0 | |||
| 864fde35ef | |||
| 934c048687 | |||
| 73c8865eb5 | |||
| 9d2b6a0286 | |||
| 588b5053e8 | |||
| 0597b21ac1 | |||
| a846e4d7ea | |||
| 16aecffdbe | |||
| 7810443a00 | |||
| 27c6d8b293 | |||
| 0822039a5f | |||
| 0b118800e4 | |||
| 90cc9587ca | |||
| 4c479676d2 | |||
| 4bcb10df81 | |||
| 664af7ffee | |||
| 2bd5c30094 | |||
| e909f347e3 | |||
| 8e4fe26ad9 | |||
| a8ade294b5 | |||
| 688a8a1706 | |||
| 598b8d0f9e | |||
| cff95aff00 | |||
| f07532c1e2 | |||
| b68c570d47 | |||
| 8bd251ac7d | |||
| 89ad6824e6 | |||
| f9edf64e83 | |||
| 37955c5701 | |||
| 5ed35362ac | |||
| 8e75f6af56 | |||
| 5b8dd6adb2 | |||
| 1273c99fdc | |||
|
|
e5bc2076dc | ||
|
|
5d45339337 | ||
|
|
f04d57382c | ||
|
|
5094554475 | ||
|
|
866f79998c | ||
| e71943f6e2 | |||
| f07103a516 | |||
| b84a893706 | |||
| 527ffd194f | |||
| 9e9491c98e | |||
|
|
8e4cff19d1 | ||
| 048fb0ef43 | |||
| a4bc03111d | |||
| 00abc4d1c0 | |||
| d4fcc8106f | |||
|
|
e4ea46c6cd | ||
| 487efb4d61 | |||
| 3f790cfbb1 | |||
| ee1962ef9c | |||
| a4d4703069 | |||
| fabb7bae19 | |||
| d1458443eb | |||
| 58d8d07b63 | |||
| c983ca22dd | |||
| 7024699a61 | |||
| 9a5929382b | |||
| cca09cc27e | |||
| f00aa15518 | |||
| 810f635987 | |||
| 49a6259d8a | |||
| e4c3bc1c5e | |||
| 14d30f55a7 | |||
| f1df067824 | |||
| 765610b184 | |||
| 48d99a0386 | |||
| a56e738064 | |||
| 1450e9b958 | |||
| eb114f2853 | |||
| 7faf80de03 | |||
| 8fe01c332e | |||
| 374c9295ef | |||
| 8b7300eac3 | |||
| 919a38afe5 | |||
| def31acfb1 | |||
| 016c1ceb6e | |||
| 1b297d15b0 | |||
| ed642e3d4f | |||
| 7cc3873a31 | |||
| b1e9bb3aeb | |||
| caf60d046b | |||
| 38663c6b67 | |||
| ee84c60ba6 | |||
| b6dd0541ae | |||
| 525acec1d3 | |||
| 45a419cae7 |
@@ -85,7 +85,6 @@ jobs:
|
||||
strategy: 'patch'
|
||||
path: './pubspec.yaml'
|
||||
|
||||
|
||||
- name: Commit version update
|
||||
env:
|
||||
GITEA_TOKEN: ${{ secrets.BOT_TOKEN }}
|
||||
@@ -107,6 +106,7 @@ jobs:
|
||||
with:
|
||||
fetch-depth: 0
|
||||
token: ${{ secrets.BOT_TOKEN }}
|
||||
ref: ${{ gitea.ref_name }}
|
||||
|
||||
# Required for Flutter action
|
||||
- name: Install jq
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
include: package:flutter_lints/flutter.yaml
|
||||
|
||||
analyzer:
|
||||
exclude:
|
||||
- lib/presentation/views/main_menu/settings_view/licenses/oss_licenses.dart
|
||||
|
||||
linter:
|
||||
rules:
|
||||
avoid_print: false
|
||||
|
||||
@@ -20,7 +20,5 @@
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>MinimumOSVersion</key>
|
||||
<string>13.0</string>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -2,12 +2,15 @@ import Flutter
|
||||
import UIKit
|
||||
|
||||
@main
|
||||
@objc class AppDelegate: FlutterAppDelegate {
|
||||
@objc class AppDelegate: FlutterAppDelegate, FlutterImplicitEngineDelegate {
|
||||
override func application(
|
||||
_ application: UIApplication,
|
||||
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
|
||||
) -> Bool {
|
||||
GeneratedPluginRegistrant.register(with: self)
|
||||
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
|
||||
}
|
||||
|
||||
func didInitializeImplicitFlutterEngine(_ engineBridge: FlutterImplicitEngineBridge) {
|
||||
GeneratedPluginRegistrant.register(with: engineBridge.pluginRegistry)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,27 @@
|
||||
</array>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UIApplicationSceneManifest</key>
|
||||
<dict>
|
||||
<key>UIApplicationSupportsMultipleScenes</key>
|
||||
<false/>
|
||||
<key>UISceneConfigurations</key>
|
||||
<dict>
|
||||
<key>UIWindowSceneSessionRoleApplication</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>UISceneClassName</key>
|
||||
<string>UIWindowScene</string>
|
||||
<key>UISceneConfigurationName</key>
|
||||
<string>flutter</string>
|
||||
<key>UISceneDelegateClassName</key>
|
||||
<string>FlutterSceneDelegate</string>
|
||||
<key>UISceneStoryboardFile</key>
|
||||
<string>Main</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>UIApplicationSupportsIndirectInputEvents</key>
|
||||
<true/>
|
||||
<key>UILaunchStoryboardName</key>
|
||||
|
||||
90
lib/core/common.dart
Normal file
90
lib/core/common.dart
Normal file
@@ -0,0 +1,90 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
|
||||
/// 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.highestScore:
|
||||
return loc.highest_score;
|
||||
case Ruleset.lowestScore:
|
||||
return loc.lowest_score;
|
||||
case Ruleset.singleWinner:
|
||||
return loc.single_winner;
|
||||
case Ruleset.singleLoser:
|
||||
return loc.single_loser;
|
||||
case Ruleset.multipleWinners:
|
||||
return loc.multiple_winners;
|
||||
}
|
||||
}
|
||||
|
||||
/// Translates a [GameColor] enum value to its corresponding localized string.
|
||||
String translateGameColorToString(GameColor color, BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
switch (color) {
|
||||
case GameColor.red:
|
||||
return loc.color_red;
|
||||
case GameColor.blue:
|
||||
return loc.color_blue;
|
||||
case GameColor.green:
|
||||
return loc.color_green;
|
||||
case GameColor.yellow:
|
||||
return loc.color_yellow;
|
||||
case GameColor.purple:
|
||||
return loc.color_purple;
|
||||
case GameColor.orange:
|
||||
return loc.color_orange;
|
||||
case GameColor.pink:
|
||||
return loc.color_pink;
|
||||
case GameColor.teal:
|
||||
return loc.color_teal;
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the [Color] object corresponding to a [GameColor] enum value.
|
||||
Color getColorFromGameColor(GameColor color) {
|
||||
switch (color) {
|
||||
case GameColor.red:
|
||||
return Colors.red;
|
||||
case GameColor.blue:
|
||||
return Colors.blue;
|
||||
case GameColor.green:
|
||||
return Colors.green;
|
||||
case GameColor.yellow:
|
||||
return Colors.yellow;
|
||||
case GameColor.purple:
|
||||
return Colors.purple;
|
||||
case GameColor.orange:
|
||||
return Colors.orange;
|
||||
case GameColor.pink:
|
||||
return Colors.pink;
|
||||
case GameColor.teal:
|
||||
return Colors.teal;
|
||||
}
|
||||
}
|
||||
|
||||
/// Counts how many players in the match are not part of the group
|
||||
/// Returns the count as a string, or an empty string if there is no group
|
||||
String getExtraPlayerCount(Match match) {
|
||||
int count = 0;
|
||||
|
||||
if (match.group == null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
final groupMembers = match.group!.members;
|
||||
final players = match.players;
|
||||
|
||||
for (var player in players) {
|
||||
if (!groupMembers.any((member) => member.id == player.id)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
return '';
|
||||
}
|
||||
return ' + ${count.toString()}';
|
||||
}
|
||||
@@ -19,4 +19,7 @@ class Constants {
|
||||
|
||||
/// Maximum length for team names
|
||||
static const int MAX_TEAM_NAME_LENGTH = 32;
|
||||
|
||||
/// Maximum length for game descriptions
|
||||
static const int MAX_GAME_DESCRIPTION_LENGTH = 256;
|
||||
}
|
||||
|
||||
@@ -13,13 +13,13 @@ class CustomTheme {
|
||||
static const Color secondaryColor = Color(0xFFf2a981);
|
||||
|
||||
/// Background color of the app theme
|
||||
static const backgroundColor = Color(0xFF0B0B0B);
|
||||
static const Color backgroundColor = Color(0xFF0B0B0B);
|
||||
|
||||
/// Default color for boxes and containers
|
||||
static const Color boxColor = Color(0xFF101010);
|
||||
|
||||
/// Default border color for boxes and containers
|
||||
static const Color boxBorder = Color(0xFF272727);
|
||||
static const Color boxBorderColor = Color(0xFF272727);
|
||||
|
||||
/// Color for boxes and containers displayed on boxes
|
||||
static const Color onBoxColor = Color(0xFF181818);
|
||||
@@ -27,6 +27,12 @@ class CustomTheme {
|
||||
/// Text color used throughout the app
|
||||
static const Color textColor = Color(0xFFFFFFFF);
|
||||
|
||||
/// Text color used throughout the app
|
||||
static const Color hintColor = Color(0xFF888888);
|
||||
|
||||
/// Background color for the navigation bar
|
||||
static const Color navBarBackgroundColor = Color(0xFF131313);
|
||||
|
||||
/// Selected color for the [NavbarItem]
|
||||
static Color navBarItemSelectedColor = primaryColor.withGreen(100);
|
||||
|
||||
@@ -51,7 +57,7 @@ class CustomTheme {
|
||||
// ==================== Decorations ====================
|
||||
static BoxDecoration standardBoxDecoration = BoxDecoration(
|
||||
color: boxColor,
|
||||
border: Border.all(color: boxBorder),
|
||||
border: Border.all(color: boxBorderColor),
|
||||
borderRadius: standardBorderRadiusAll,
|
||||
);
|
||||
|
||||
@@ -62,7 +68,7 @@ class CustomTheme {
|
||||
boxShadow: [BoxShadow(color: primaryColor.withAlpha(120), blurRadius: 12)],
|
||||
);
|
||||
|
||||
// ==================== App Bar Theme ====================
|
||||
// ==================== Component Themes ====================
|
||||
static const AppBarTheme appBarTheme = AppBarTheme(
|
||||
backgroundColor: backgroundColor,
|
||||
foregroundColor: textColor,
|
||||
@@ -77,4 +83,23 @@ class CustomTheme {
|
||||
),
|
||||
iconTheme: IconThemeData(color: textColor),
|
||||
);
|
||||
|
||||
static const SearchBarThemeData searchBarTheme = SearchBarThemeData(
|
||||
textStyle: WidgetStatePropertyAll(TextStyle(color: CustomTheme.textColor)),
|
||||
hintStyle: WidgetStatePropertyAll(TextStyle(color: CustomTheme.hintColor)),
|
||||
);
|
||||
|
||||
static final RadioThemeData radioTheme = RadioThemeData(
|
||||
fillColor: WidgetStateProperty.resolveWith<Color>((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return CustomTheme.primaryColor;
|
||||
}
|
||||
return CustomTheme.textColor;
|
||||
}),
|
||||
);
|
||||
|
||||
static const InputDecorationTheme inputDecorationTheme = InputDecorationTheme(
|
||||
labelStyle: TextStyle(color: CustomTheme.textColor),
|
||||
hintStyle: TextStyle(color: CustomTheme.hintColor),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
|
||||
/// Button types used for styling the [CustomWidthButton]
|
||||
/// - [ButtonType.primary]: Primary button style.
|
||||
/// - [ButtonType.secondary]: Secondary button style.
|
||||
@@ -35,7 +32,13 @@ enum ExportResult { success, canceled, unknownException }
|
||||
/// - [Ruleset.singleWinner]: The match is won by a single player.
|
||||
/// - [Ruleset.singleLoser]: The match has a single loser.
|
||||
/// - [Ruleset.multipleWinners]: Multiple players can be winners.
|
||||
enum Ruleset { highestScore, lowestScore, singleWinner, singleLoser, multipleWinners }
|
||||
enum Ruleset {
|
||||
highestScore,
|
||||
lowestScore,
|
||||
singleWinner,
|
||||
singleLoser,
|
||||
multipleWinners,
|
||||
}
|
||||
|
||||
/// Different colors available for games
|
||||
/// - [GameColor.red]: Red color
|
||||
@@ -47,20 +50,3 @@ enum Ruleset { highestScore, lowestScore, singleWinner, singleLoser, multipleWin
|
||||
/// - [GameColor.pink]: Pink color
|
||||
/// - [GameColor.teal]: Teal color
|
||||
enum GameColor { red, blue, green, yellow, purple, orange, pink, teal }
|
||||
|
||||
/// 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.highestScore:
|
||||
return loc.highest_score;
|
||||
case Ruleset.lowestScore:
|
||||
return loc.lowest_score;
|
||||
case Ruleset.singleWinner:
|
||||
return loc.single_winner;
|
||||
case Ruleset.singleLoser:
|
||||
return loc.single_loser;
|
||||
case Ruleset.multipleWinners:
|
||||
return loc.multiple_winners;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
if (row.groupId != null) {
|
||||
group = await db.groupDao.getGroupById(groupId: row.groupId!);
|
||||
}
|
||||
final players = await db.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: row.id,
|
||||
) ?? [];
|
||||
final players =
|
||||
await db.playerMatchDao.getPlayersOfMatch(matchId: row.id) ?? [];
|
||||
final winner = await getWinner(matchId: row.id);
|
||||
return Match(
|
||||
id: row.id,
|
||||
name: row.name ?? '',
|
||||
@@ -39,6 +39,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
notes: row.notes ?? '',
|
||||
createdAt: row.createdAt,
|
||||
endedAt: row.endedAt,
|
||||
winner: winner,
|
||||
);
|
||||
}),
|
||||
);
|
||||
@@ -56,7 +57,10 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
group = await db.groupDao.getGroupById(groupId: result.groupId!);
|
||||
}
|
||||
|
||||
final players = await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
||||
final players =
|
||||
await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
||||
|
||||
final winner = await getWinner(matchId: matchId);
|
||||
|
||||
return Match(
|
||||
id: result.id,
|
||||
@@ -67,6 +71,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
notes: result.notes ?? '',
|
||||
createdAt: result.createdAt,
|
||||
endedAt: result.endedAt,
|
||||
winner: winner,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -94,6 +99,10 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
playerId: p.id,
|
||||
);
|
||||
}
|
||||
|
||||
if (match.winner != null) {
|
||||
await setWinner(matchId: match.id, winnerId: match.winner!.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -112,20 +121,20 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
|
||||
if (uniqueGames.isNotEmpty) {
|
||||
await db.batch(
|
||||
(b) => b.insertAll(
|
||||
(b) => b.insertAll(
|
||||
db.gameTable,
|
||||
uniqueGames.values
|
||||
.map(
|
||||
(game) => GameTableCompanion.insert(
|
||||
id: game.id,
|
||||
name: game.name,
|
||||
ruleset: game.ruleset.name,
|
||||
description: game.description,
|
||||
color: game.color.name,
|
||||
icon: game.icon,
|
||||
createdAt: game.createdAt,
|
||||
),
|
||||
)
|
||||
id: game.id,
|
||||
name: game.name,
|
||||
ruleset: game.ruleset.name,
|
||||
description: game.description,
|
||||
color: game.color.name,
|
||||
icon: game.icon,
|
||||
createdAt: game.createdAt,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrIgnore,
|
||||
),
|
||||
@@ -134,18 +143,18 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
|
||||
// Add all groups of the matches in batch
|
||||
await db.batch(
|
||||
(b) => b.insertAll(
|
||||
(b) => b.insertAll(
|
||||
db.groupTable,
|
||||
matches
|
||||
.where((match) => match.group != null)
|
||||
.map(
|
||||
(match) => GroupTableCompanion.insert(
|
||||
id: match.group!.id,
|
||||
name: match.group!.name,
|
||||
description: match.group!.description,
|
||||
createdAt: match.group!.createdAt,
|
||||
),
|
||||
)
|
||||
id: match.group!.id,
|
||||
name: match.group!.name,
|
||||
description: match.group!.description,
|
||||
createdAt: match.group!.createdAt,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrIgnore,
|
||||
),
|
||||
@@ -153,20 +162,20 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
|
||||
// Add all matches in batch
|
||||
await db.batch(
|
||||
(b) => b.insertAll(
|
||||
(b) => b.insertAll(
|
||||
matchTable,
|
||||
matches
|
||||
.map(
|
||||
(match) => MatchTableCompanion.insert(
|
||||
id: match.id,
|
||||
gameId: match.game.id,
|
||||
groupId: Value(match.group?.id),
|
||||
name: Value(match.name),
|
||||
notes: Value(match.notes),
|
||||
createdAt: match.createdAt,
|
||||
endedAt: Value(match.endedAt),
|
||||
),
|
||||
)
|
||||
id: match.id,
|
||||
gameId: match.game.id,
|
||||
groupId: Value(match.group?.id),
|
||||
name: Value(match.name),
|
||||
notes: Value(match.notes),
|
||||
createdAt: match.createdAt,
|
||||
endedAt: Value(match.endedAt),
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
@@ -188,17 +197,17 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
|
||||
if (uniquePlayers.isNotEmpty) {
|
||||
await db.batch(
|
||||
(b) => b.insertAll(
|
||||
(b) => b.insertAll(
|
||||
db.playerTable,
|
||||
uniquePlayers.values
|
||||
.map(
|
||||
(p) => PlayerTableCompanion.insert(
|
||||
id: p.id,
|
||||
name: p.name,
|
||||
description: p.description,
|
||||
createdAt: p.createdAt,
|
||||
),
|
||||
)
|
||||
id: p.id,
|
||||
name: p.name,
|
||||
description: p.description,
|
||||
createdAt: p.createdAt,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrIgnore,
|
||||
),
|
||||
@@ -253,9 +262,9 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
/// 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();
|
||||
await (selectOnly(matchTable)..addColumns([matchTable.id.count()]))
|
||||
.map((row) => row.read(matchTable.id.count()))
|
||||
.getSingle();
|
||||
return count ?? 0;
|
||||
}
|
||||
|
||||
@@ -315,15 +324,16 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
}
|
||||
|
||||
/// Updates the group of the match with the given [matchId].
|
||||
/// Replaces the existing group association with the new group specified by [newGroupId].
|
||||
/// Pass null to remove the group association.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateMatchGroup({
|
||||
required String matchId,
|
||||
required String? groupId,
|
||||
required String? newGroupId,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
MatchTableCompanion(groupId: Value(groupId)),
|
||||
MatchTableCompanion(groupId: Value(newGroupId)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
@@ -379,10 +389,12 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
|
||||
// Add the new players to the match
|
||||
await Future.wait(
|
||||
newPlayers.map((player) => db.playerMatchDao.addPlayerToMatch(
|
||||
matchId: matchId,
|
||||
playerId: player.id,
|
||||
)),
|
||||
newPlayers.map(
|
||||
(player) => db.playerMatchDao.addPlayerToMatch(
|
||||
matchId: matchId,
|
||||
playerId: player.id,
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -394,7 +406,8 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
/// Checks if a match has a winner.
|
||||
/// Returns true if any player in the match has their score set to 1.
|
||||
Future<bool> hasWinner({required String matchId}) async {
|
||||
final players = await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
||||
final players =
|
||||
await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
||||
|
||||
for (final player in players) {
|
||||
final score = await db.playerMatchDao.getPlayerScore(
|
||||
@@ -411,7 +424,8 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
/// Gets the winner of a match.
|
||||
/// Returns the player with score 1, or null if no winner is set.
|
||||
Future<Player?> getWinner({required String matchId}) async {
|
||||
final players = await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
||||
final players =
|
||||
await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
||||
|
||||
for (final player in players) {
|
||||
final score = await db.playerMatchDao.getPlayerScore(
|
||||
@@ -433,7 +447,8 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
required String winnerId,
|
||||
}) async {
|
||||
await db.transaction(() async {
|
||||
final players = await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
||||
final players =
|
||||
await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
||||
|
||||
// Set all players' scores to 0
|
||||
for (final player in players) {
|
||||
|
||||
@@ -6,7 +6,7 @@ class MatchTable extends Table {
|
||||
TextColumn get id => text()();
|
||||
TextColumn get gameId =>
|
||||
text().references(GameTable, #id, onDelete: KeyAction.cascade)();
|
||||
// Nullable if not part of a group
|
||||
// Nullable if there is no group associated with the match
|
||||
TextColumn get groupId =>
|
||||
text().references(GroupTable, #id, onDelete: KeyAction.cascade).nullable()();
|
||||
TextColumn get name => text().nullable()();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class Game {
|
||||
final String id;
|
||||
@@ -16,11 +16,13 @@ class Game {
|
||||
DateTime? createdAt,
|
||||
required this.name,
|
||||
required this.ruleset,
|
||||
required this.description,
|
||||
String? description,
|
||||
required this.color,
|
||||
required this.icon,
|
||||
String? icon,
|
||||
}) : id = id ?? const Uuid().v4(),
|
||||
createdAt = createdAt ?? clock.now();
|
||||
createdAt = createdAt ?? clock.now(),
|
||||
description = description ?? '',
|
||||
icon = icon ?? '';
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -48,4 +50,3 @@ class Game {
|
||||
'icon': icon,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,11 @@ class Group {
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
required this.name,
|
||||
required this.description,
|
||||
String? description,
|
||||
required this.members,
|
||||
}) : id = id ?? const Uuid().v4(),
|
||||
createdAt = createdAt ?? clock.now();
|
||||
createdAt = createdAt ?? clock.now(),
|
||||
description = description ?? '';
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
||||
@@ -24,10 +24,11 @@ class Match {
|
||||
required this.game,
|
||||
this.group,
|
||||
this.players = const [],
|
||||
required this.notes,
|
||||
String? notes,
|
||||
this.winner,
|
||||
}) : id = id ?? const Uuid().v4(),
|
||||
createdAt = createdAt ?? clock.now();
|
||||
createdAt = createdAt ?? clock.now(),
|
||||
notes = notes ?? '';
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -37,14 +38,21 @@ class Match {
|
||||
/// Creates a Match instance from a JSON object (ID references format).
|
||||
/// Related objects are reconstructed from IDs by the DataTransferService.
|
||||
Match.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
createdAt = DateTime.parse(json['createdAt']),
|
||||
endedAt = json['endedAt'] != null ? DateTime.parse(json['endedAt']) : null,
|
||||
name = json['name'],
|
||||
game = Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: GameColor.blue, icon: ''), // Populated during import via DataTransferService
|
||||
group = null, // Populated during import via DataTransferService
|
||||
players = [], // Populated during import via DataTransferService
|
||||
notes = json['notes'] ?? '';
|
||||
: id = json['id'],
|
||||
createdAt = DateTime.parse(json['createdAt']),
|
||||
endedAt = json['endedAt'] != null
|
||||
? DateTime.parse(json['endedAt'])
|
||||
: null,
|
||||
name = json['name'],
|
||||
game = Game(
|
||||
name: '',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: '',
|
||||
color: GameColor.blue,
|
||||
), // Populated during import via DataTransferService
|
||||
group = null, // Populated during import via DataTransferService
|
||||
players = [], // Populated during import via DataTransferService
|
||||
notes = json['notes'] ?? '';
|
||||
|
||||
/// Converts the Match instance to a JSON object using normalized format (ID references only).
|
||||
Map<String, dynamic> toJson() => {
|
||||
|
||||
@@ -11,9 +11,10 @@ class Player {
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
required this.name,
|
||||
required this.description,
|
||||
String? description,
|
||||
}) : id = id ?? const Uuid().v4(),
|
||||
createdAt = createdAt ?? clock.now();
|
||||
createdAt = createdAt ?? clock.now(),
|
||||
description = description ?? '';
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
"choose_game": "Spielvorlage wählen",
|
||||
"choose_group": "Gruppe wählen",
|
||||
"choose_ruleset": "Regelwerk wählen",
|
||||
"choose_color": "Farbe wählen",
|
||||
"could_not_add_player": "Spieler:in {playerName} konnte nicht hinzugefügt werden",
|
||||
"create_game": "Spielvorlage erstellen",
|
||||
"create_group": "Gruppe erstellen",
|
||||
"create_match": "Spiel erstellen",
|
||||
"create_new_group": "Neue Gruppe erstellen",
|
||||
@@ -22,9 +24,19 @@
|
||||
"days_ago": "vor {count} Tagen",
|
||||
"delete": "Löschen",
|
||||
"delete_all_data": "Alle Daten löschen",
|
||||
"delete_group": "Diese Gruppe löschen",
|
||||
"delete_match": "Spiel löschen",
|
||||
"delete_game": "Spielvorlage löschen",
|
||||
"delete_group": "Gruppe löschen",
|
||||
"description": "Beschreibung",
|
||||
"edit_game": "Spielvorlage bearbeiten",
|
||||
"edit_group": "Gruppe bearbeiten",
|
||||
"edit_match": "Gruppe bearbeiten",
|
||||
"enter_results": "Ergebnisse eintragen",
|
||||
"error_creating_group": "Fehler beim Erstellen der Gruppe, bitte erneut versuchen",
|
||||
"error_deleting_game": "Fehler beim Löschen der Spielvorlage, bitte erneut versuchen",
|
||||
"error_deleting_group": "Fehler beim Löschen der Gruppe, bitte erneut versuchen",
|
||||
"error_editing_group": "Fehler beim Bearbeiten der Gruppe, bitte erneut versuchen",
|
||||
"error_reading_file": "Fehler beim Lesen der Datei",
|
||||
"export_canceled": "Export abgebrochen",
|
||||
"export_data": "Daten exportieren",
|
||||
@@ -46,6 +58,7 @@
|
||||
"licenses": "Lizenzen",
|
||||
"match_in_progress": "Spiel läuft...",
|
||||
"match_name": "Spieltitel",
|
||||
"match_profile": "Spielprofil",
|
||||
"matches": "Spiele",
|
||||
"members": "Mitglieder",
|
||||
"most_points": "Höchste Punkte",
|
||||
@@ -58,6 +71,7 @@
|
||||
"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_results_entered_yet": "Noch keine Ergebnisse eingetragen",
|
||||
"no_second_match_available": "Kein zweites Spiel verfügbar",
|
||||
"no_statistics_available": "Keine Statistiken verfügbar",
|
||||
"none": "Kein",
|
||||
@@ -70,11 +84,14 @@
|
||||
"privacy_policy": "Datenschutzerklärung",
|
||||
"quick_create": "Schnellzugriff",
|
||||
"recent_matches": "Letzte Spiele",
|
||||
"result": "Ergebnis",
|
||||
"results": "Ergebnisse",
|
||||
"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.",
|
||||
"save_changes": "Änderungen speichern",
|
||||
"search_for_groups": "Nach Gruppen suchen",
|
||||
"search_for_players": "Nach Spieler:innen suchen",
|
||||
"select_winner": "Gewinner:in wählen:",
|
||||
@@ -96,5 +113,14 @@
|
||||
"winner": "Gewinner:in",
|
||||
"winrate": "Siegquote",
|
||||
"wins": "Siege",
|
||||
"yesterday_at": "Gestern um"
|
||||
"yesterday_at": "Gestern um",
|
||||
"color_red": "Rot",
|
||||
"color_blue": "Blau",
|
||||
"color_green": "Grün",
|
||||
"color_yellow": "Gelb",
|
||||
"color_purple": "Lila",
|
||||
"color_orange": "Orange",
|
||||
"color_pink": "Rosa",
|
||||
"color_teal": "Türkis",
|
||||
"color": "Farbe"
|
||||
}
|
||||
@@ -27,9 +27,15 @@
|
||||
"@choose_ruleset": {
|
||||
"description": "Label for choosing a ruleset"
|
||||
},
|
||||
"@choose_color": {
|
||||
"description": "Label for choosing a color"
|
||||
},
|
||||
"@could_not_add_player": {
|
||||
"description": "Error message when adding a player fails"
|
||||
},
|
||||
"@create_game": {
|
||||
"description": "Button text to create a game"
|
||||
},
|
||||
"@create_group": {
|
||||
"description": "Button text to create a group"
|
||||
},
|
||||
@@ -37,10 +43,10 @@
|
||||
"description": "Button text to create a match"
|
||||
},
|
||||
"@create_new_group": {
|
||||
"description": "Button text to create a new group"
|
||||
"description": "Appbar text to create a new group"
|
||||
},
|
||||
"@create_new_match": {
|
||||
"description": "Button text to create a new match"
|
||||
"description": "Appbar text to create a new match"
|
||||
},
|
||||
"@created_on": {
|
||||
"description": "Label for creation date"
|
||||
@@ -71,15 +77,42 @@
|
||||
"@delete_all_data": {
|
||||
"description": "Confirmation dialog for deleting all data"
|
||||
},
|
||||
"@delete_group": {
|
||||
"description": "Button text to delete a group"
|
||||
"@delete_game": {
|
||||
"description": "Button text to delete a game"
|
||||
},
|
||||
"@delete_group": {
|
||||
"description": "Confirmation dialog for deleting a group"
|
||||
},
|
||||
"@delete_match": {
|
||||
"description": "Button text to delete a match"
|
||||
},
|
||||
"description": {
|
||||
"description": "Description label"
|
||||
},
|
||||
"edit_game": {
|
||||
"description": "Button text to edit a game"
|
||||
},
|
||||
"@edit_group": {
|
||||
"description": "Button text to edit a group"
|
||||
"description": "Button & Appbar label for editing a group"
|
||||
},
|
||||
"@edit_match": {
|
||||
"description": "Button & Appbar label for editing a match"
|
||||
},
|
||||
"@enter_results": {
|
||||
"description": "Button text to enter match results"
|
||||
},
|
||||
"@error_creating_group": {
|
||||
"description": "Error message when group creation fails"
|
||||
},
|
||||
"@error_deleting_game": {
|
||||
"description": "Error message when game deletion fails"
|
||||
},
|
||||
"@error_deleting_group": {
|
||||
"description": "Error message when group deletion fails"
|
||||
},
|
||||
"@error_editing_group": {
|
||||
"description": "Error message when group editing fails"
|
||||
},
|
||||
"@error_reading_file": {
|
||||
"description": "Error message when file cannot be read"
|
||||
},
|
||||
@@ -143,6 +176,9 @@
|
||||
"@match_name": {
|
||||
"description": "Placeholder for match name input"
|
||||
},
|
||||
"@match_profile": {
|
||||
"description": "Title for match profile view"
|
||||
},
|
||||
"@matches": {
|
||||
"description": "Label for matches"
|
||||
},
|
||||
@@ -179,6 +215,9 @@
|
||||
"@no_recent_matches_available": {
|
||||
"description": "Message when no recent matches exist"
|
||||
},
|
||||
"@no_results_entered_yet": {
|
||||
"description": "Message when no results have been entered yet"
|
||||
},
|
||||
"@no_second_match_available": {
|
||||
"description": "Message when no second match exists"
|
||||
},
|
||||
@@ -220,6 +259,9 @@
|
||||
"@recent_matches": {
|
||||
"description": "Title for recent matches section"
|
||||
},
|
||||
"@results": {
|
||||
"description": "Label for match results"
|
||||
},
|
||||
"@ruleset": {
|
||||
"description": "Ruleset label"
|
||||
},
|
||||
@@ -235,6 +277,9 @@
|
||||
"@ruleset_single_winner": {
|
||||
"description": "Description for single winner ruleset"
|
||||
},
|
||||
"@save_changes": {
|
||||
"description": "Save changes button text"
|
||||
},
|
||||
"@search_for_groups": {
|
||||
"description": "Hint text for group search input field"
|
||||
},
|
||||
@@ -298,6 +343,9 @@
|
||||
"@yesterday_at": {
|
||||
"description": "Date format for yesterday"
|
||||
},
|
||||
"@color": {
|
||||
"description": "Color label"
|
||||
},
|
||||
"all_players": "All players",
|
||||
"all_players_selected": "All players selected",
|
||||
"amount_of_matches": "Amount of Matches",
|
||||
@@ -307,7 +355,9 @@
|
||||
"choose_game": "Choose Game",
|
||||
"choose_group": "Choose Group",
|
||||
"choose_ruleset": "Choose Ruleset",
|
||||
"choose_color": "Choose Color",
|
||||
"could_not_add_player": "Could not add player",
|
||||
"create_game": "Create Game",
|
||||
"create_group": "Create Group",
|
||||
"create_match": "Create match",
|
||||
"create_new_group": "Create new group",
|
||||
@@ -320,9 +370,18 @@
|
||||
"days_ago": "{count} days ago",
|
||||
"delete": "Delete",
|
||||
"delete_all_data": "Delete all data",
|
||||
"delete_game": "Delete Game",
|
||||
"delete_group": "Delete Group",
|
||||
"delete_match": "Delete Match",
|
||||
"description": "Description",
|
||||
"edit_game": "Edit Game",
|
||||
"edit_group": "Edit Group",
|
||||
"edit_match": "Edit Match",
|
||||
"enter_results": "Enter Results",
|
||||
"error_creating_group": "Error while creating group, please try again",
|
||||
"error_deleting_game": "Error while deleting game, please try again",
|
||||
"error_deleting_group": "Error while deleting group, please try again",
|
||||
"error_editing_group": "Error while editing group, please try again",
|
||||
"error_reading_file": "Error reading file",
|
||||
"export_canceled": "Export canceled",
|
||||
"export_data": "Export data",
|
||||
@@ -344,6 +403,7 @@
|
||||
"licenses": "Licenses",
|
||||
"match_in_progress": "Match in progress...",
|
||||
"match_name": "Match name",
|
||||
"match_profile": "Match Profile",
|
||||
"matches": "Matches",
|
||||
"members": "Members",
|
||||
"most_points": "Most Points",
|
||||
@@ -356,6 +416,7 @@
|
||||
"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_results_entered_yet": "No results entered yet",
|
||||
"no_second_match_available": "No second match available",
|
||||
"no_statistics_available": "No statistics available",
|
||||
"none": "None",
|
||||
@@ -368,11 +429,13 @@
|
||||
"privacy_policy": "Privacy Policy",
|
||||
"quick_create": "Quick Create",
|
||||
"recent_matches": "Recent Matches",
|
||||
"results": "Results",
|
||||
"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.",
|
||||
"save_changes": "Save Changes",
|
||||
"search_for_groups": "Search for groups",
|
||||
"search_for_players": "Search for players",
|
||||
"select_winner": "Select Winner:",
|
||||
@@ -394,5 +457,14 @@
|
||||
"winner": "Winner",
|
||||
"winrate": "Winrate",
|
||||
"wins": "Wins",
|
||||
"yesterday_at": "Yesterday at"
|
||||
"yesterday_at": "Yesterday at",
|
||||
"color_red": "Red",
|
||||
"color_blue": "Blue",
|
||||
"color_green": "Green",
|
||||
"color_yellow": "Yellow",
|
||||
"color_purple": "Purple",
|
||||
"color_orange": "Orange",
|
||||
"color_pink": "Pink",
|
||||
"color_teal": "Teal",
|
||||
"color": "Color"
|
||||
}
|
||||
@@ -98,6 +98,18 @@ abstract class AppLocalizations {
|
||||
Locale('en'),
|
||||
];
|
||||
|
||||
/// No description provided for @description.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Description'**
|
||||
String get description;
|
||||
|
||||
/// No description provided for @edit_game.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Edit Game'**
|
||||
String get edit_game;
|
||||
|
||||
/// Label for all players list
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
@@ -152,12 +164,24 @@ abstract class AppLocalizations {
|
||||
/// **'Choose Ruleset'**
|
||||
String get choose_ruleset;
|
||||
|
||||
/// Label for choosing a color
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Choose Color'**
|
||||
String get choose_color;
|
||||
|
||||
/// 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 game
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Create Game'**
|
||||
String get create_game;
|
||||
|
||||
/// Button text to create a group
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
@@ -170,7 +194,7 @@ abstract class AppLocalizations {
|
||||
/// **'Create match'**
|
||||
String get create_match;
|
||||
|
||||
/// Button text to create a new group
|
||||
/// Appbar text to create a new group
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Create new group'**
|
||||
@@ -182,7 +206,7 @@ abstract class AppLocalizations {
|
||||
/// **'Created on'**
|
||||
String get created_on;
|
||||
|
||||
/// Button text to create a new match
|
||||
/// Appbar text to create a new match
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Create new match'**
|
||||
@@ -230,24 +254,66 @@ abstract class AppLocalizations {
|
||||
/// **'Delete all data'**
|
||||
String get delete_all_data;
|
||||
|
||||
/// Button text to delete a group
|
||||
/// Button text to delete a game
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Delete Game'**
|
||||
String get delete_game;
|
||||
|
||||
/// Confirmation dialog for deleting a group
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Delete Group'**
|
||||
String get delete_group;
|
||||
|
||||
/// Button text to edit a group
|
||||
/// Button text to delete a match
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Delete Match'**
|
||||
String get delete_match;
|
||||
|
||||
/// Button & Appbar label for editing a group
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Edit Group'**
|
||||
String get edit_group;
|
||||
|
||||
/// Button & Appbar label for editing a match
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Edit Match'**
|
||||
String get edit_match;
|
||||
|
||||
/// Button text to enter match results
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Enter Results'**
|
||||
String get enter_results;
|
||||
|
||||
/// 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 game deletion fails
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Error while deleting game, please try again'**
|
||||
String get error_deleting_game;
|
||||
|
||||
/// Error message when group deletion fails
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Error while deleting group, please try again'**
|
||||
String get error_deleting_group;
|
||||
|
||||
/// Error message when group editing fails
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Error while editing group, please try again'**
|
||||
String get error_editing_group;
|
||||
|
||||
/// Error message when file cannot be read
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
@@ -374,6 +440,12 @@ abstract class AppLocalizations {
|
||||
/// **'Match name'**
|
||||
String get match_name;
|
||||
|
||||
/// Title for match profile view
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Match Profile'**
|
||||
String get match_profile;
|
||||
|
||||
/// Label for matches
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
@@ -446,6 +518,12 @@ abstract class AppLocalizations {
|
||||
/// **'No recent matches available'**
|
||||
String get no_recent_matches_available;
|
||||
|
||||
/// Message when no results have been entered yet
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No results entered yet'**
|
||||
String get no_results_entered_yet;
|
||||
|
||||
/// Message when no second match exists
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
@@ -518,6 +596,12 @@ abstract class AppLocalizations {
|
||||
/// **'Recent Matches'**
|
||||
String get recent_matches;
|
||||
|
||||
/// Label for match results
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Results'**
|
||||
String get results;
|
||||
|
||||
/// Ruleset label
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
@@ -548,6 +632,12 @@ abstract class AppLocalizations {
|
||||
/// **'Exactly one winner is chosen; ties are resolved by a predefined tiebreaker.'**
|
||||
String get ruleset_single_winner;
|
||||
|
||||
/// Save changes button text
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Save Changes'**
|
||||
String get save_changes;
|
||||
|
||||
/// Hint text for group search input field
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
@@ -679,6 +769,60 @@ abstract class AppLocalizations {
|
||||
/// In en, this message translates to:
|
||||
/// **'Yesterday at'**
|
||||
String get yesterday_at;
|
||||
|
||||
/// No description provided for @color_red.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Red'**
|
||||
String get color_red;
|
||||
|
||||
/// No description provided for @color_blue.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Blue'**
|
||||
String get color_blue;
|
||||
|
||||
/// No description provided for @color_green.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Green'**
|
||||
String get color_green;
|
||||
|
||||
/// No description provided for @color_yellow.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Yellow'**
|
||||
String get color_yellow;
|
||||
|
||||
/// No description provided for @color_purple.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Purple'**
|
||||
String get color_purple;
|
||||
|
||||
/// No description provided for @color_orange.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Orange'**
|
||||
String get color_orange;
|
||||
|
||||
/// No description provided for @color_pink.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Pink'**
|
||||
String get color_pink;
|
||||
|
||||
/// No description provided for @color_teal.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Teal'**
|
||||
String get color_teal;
|
||||
|
||||
/// Color label
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Color'**
|
||||
String get color;
|
||||
}
|
||||
|
||||
class _AppLocalizationsDelegate
|
||||
|
||||
@@ -8,6 +8,12 @@ import 'app_localizations.dart';
|
||||
class AppLocalizationsDe extends AppLocalizations {
|
||||
AppLocalizationsDe([String locale = 'de']) : super(locale);
|
||||
|
||||
@override
|
||||
String get description => 'Beschreibung';
|
||||
|
||||
@override
|
||||
String get edit_game => 'Spielvorlage bearbeiten';
|
||||
|
||||
@override
|
||||
String get all_players => 'Alle Spieler:innen';
|
||||
|
||||
@@ -35,11 +41,17 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get choose_ruleset => 'Regelwerk wählen';
|
||||
|
||||
@override
|
||||
String get choose_color => 'Farbe wählen';
|
||||
|
||||
@override
|
||||
String could_not_add_player(Object playerName) {
|
||||
return 'Spieler:in $playerName konnte nicht hinzugefügt werden';
|
||||
}
|
||||
|
||||
@override
|
||||
String get create_game => 'Spielvorlage erstellen';
|
||||
|
||||
@override
|
||||
String get create_group => 'Gruppe erstellen';
|
||||
|
||||
@@ -78,16 +90,40 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get delete_all_data => 'Alle Daten löschen';
|
||||
|
||||
@override
|
||||
String get delete_game => 'Spielvorlage löschen';
|
||||
|
||||
@override
|
||||
String get delete_group => 'Gruppe löschen';
|
||||
|
||||
@override
|
||||
String get delete_match => 'Spiel löschen';
|
||||
|
||||
@override
|
||||
String get edit_group => 'Gruppe bearbeiten';
|
||||
|
||||
@override
|
||||
String get edit_match => 'Gruppe bearbeiten';
|
||||
|
||||
@override
|
||||
String get enter_results => 'Ergebnisse eintragen';
|
||||
|
||||
@override
|
||||
String get error_creating_group =>
|
||||
'Fehler beim Erstellen der Gruppe, bitte erneut versuchen';
|
||||
|
||||
@override
|
||||
String get error_deleting_game =>
|
||||
'Fehler beim Löschen der Spielvorlage, bitte erneut versuchen';
|
||||
|
||||
@override
|
||||
String get error_deleting_group =>
|
||||
'Fehler beim Löschen der Gruppe, bitte erneut versuchen';
|
||||
|
||||
@override
|
||||
String get error_editing_group =>
|
||||
'Fehler beim Bearbeiten der Gruppe, bitte erneut versuchen';
|
||||
|
||||
@override
|
||||
String get error_reading_file => 'Fehler beim Lesen der Datei';
|
||||
|
||||
@@ -151,6 +187,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get match_name => 'Spieltitel';
|
||||
|
||||
@override
|
||||
String get match_profile => 'Spielprofil';
|
||||
|
||||
@override
|
||||
String get matches => 'Spiele';
|
||||
|
||||
@@ -188,6 +227,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get no_recent_matches_available => 'Keine letzten Spiele verfügbar';
|
||||
|
||||
@override
|
||||
String get no_results_entered_yet => 'Noch keine Ergebnisse eingetragen';
|
||||
|
||||
@override
|
||||
String get no_second_match_available => 'Kein zweites Spiel verfügbar';
|
||||
|
||||
@@ -226,6 +268,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get recent_matches => 'Letzte Spiele';
|
||||
|
||||
@override
|
||||
String get results => 'Ergebnisse';
|
||||
|
||||
@override
|
||||
String get ruleset => 'Regelwerk';
|
||||
|
||||
@@ -245,6 +290,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
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 save_changes => 'Änderungen speichern';
|
||||
|
||||
@override
|
||||
String get search_for_groups => 'Nach Gruppen suchen';
|
||||
|
||||
@@ -314,4 +362,31 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
|
||||
@override
|
||||
String get yesterday_at => 'Gestern um';
|
||||
|
||||
@override
|
||||
String get color_red => 'Rot';
|
||||
|
||||
@override
|
||||
String get color_blue => 'Blau';
|
||||
|
||||
@override
|
||||
String get color_green => 'Grün';
|
||||
|
||||
@override
|
||||
String get color_yellow => 'Gelb';
|
||||
|
||||
@override
|
||||
String get color_purple => 'Lila';
|
||||
|
||||
@override
|
||||
String get color_orange => 'Orange';
|
||||
|
||||
@override
|
||||
String get color_pink => 'Rosa';
|
||||
|
||||
@override
|
||||
String get color_teal => 'Türkis';
|
||||
|
||||
@override
|
||||
String get color => 'Farbe';
|
||||
}
|
||||
|
||||
@@ -8,6 +8,12 @@ import 'app_localizations.dart';
|
||||
class AppLocalizationsEn extends AppLocalizations {
|
||||
AppLocalizationsEn([String locale = 'en']) : super(locale);
|
||||
|
||||
@override
|
||||
String get description => 'Description';
|
||||
|
||||
@override
|
||||
String get edit_game => 'Edit Game';
|
||||
|
||||
@override
|
||||
String get all_players => 'All players';
|
||||
|
||||
@@ -35,11 +41,17 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get choose_ruleset => 'Choose Ruleset';
|
||||
|
||||
@override
|
||||
String get choose_color => 'Choose Color';
|
||||
|
||||
@override
|
||||
String could_not_add_player(Object playerName) {
|
||||
return 'Could not add player';
|
||||
}
|
||||
|
||||
@override
|
||||
String get create_game => 'Create Game';
|
||||
|
||||
@override
|
||||
String get create_group => 'Create Group';
|
||||
|
||||
@@ -78,16 +90,40 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get delete_all_data => 'Delete all data';
|
||||
|
||||
@override
|
||||
String get delete_game => 'Delete Game';
|
||||
|
||||
@override
|
||||
String get delete_group => 'Delete Group';
|
||||
|
||||
@override
|
||||
String get delete_match => 'Delete Match';
|
||||
|
||||
@override
|
||||
String get edit_group => 'Edit Group';
|
||||
|
||||
@override
|
||||
String get edit_match => 'Edit Match';
|
||||
|
||||
@override
|
||||
String get enter_results => 'Enter Results';
|
||||
|
||||
@override
|
||||
String get error_creating_group =>
|
||||
'Error while creating group, please try again';
|
||||
|
||||
@override
|
||||
String get error_deleting_game =>
|
||||
'Error while deleting game, please try again';
|
||||
|
||||
@override
|
||||
String get error_deleting_group =>
|
||||
'Error while deleting group, please try again';
|
||||
|
||||
@override
|
||||
String get error_editing_group =>
|
||||
'Error while editing group, please try again';
|
||||
|
||||
@override
|
||||
String get error_reading_file => 'Error reading file';
|
||||
|
||||
@@ -151,6 +187,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get match_name => 'Match name';
|
||||
|
||||
@override
|
||||
String get match_profile => 'Match Profile';
|
||||
|
||||
@override
|
||||
String get matches => 'Matches';
|
||||
|
||||
@@ -188,6 +227,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get no_recent_matches_available => 'No recent matches available';
|
||||
|
||||
@override
|
||||
String get no_results_entered_yet => 'No results entered yet';
|
||||
|
||||
@override
|
||||
String get no_second_match_available => 'No second match available';
|
||||
|
||||
@@ -226,6 +268,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get recent_matches => 'Recent Matches';
|
||||
|
||||
@override
|
||||
String get results => 'Results';
|
||||
|
||||
@override
|
||||
String get ruleset => 'Ruleset';
|
||||
|
||||
@@ -245,6 +290,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get ruleset_single_winner =>
|
||||
'Exactly one winner is chosen; ties are resolved by a predefined tiebreaker.';
|
||||
|
||||
@override
|
||||
String get save_changes => 'Save Changes';
|
||||
|
||||
@override
|
||||
String get search_for_groups => 'Search for groups';
|
||||
|
||||
@@ -313,4 +361,31 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
|
||||
@override
|
||||
String get yesterday_at => 'Yesterday at';
|
||||
|
||||
@override
|
||||
String get color_red => 'Red';
|
||||
|
||||
@override
|
||||
String get color_blue => 'Blue';
|
||||
|
||||
@override
|
||||
String get color_green => 'Green';
|
||||
|
||||
@override
|
||||
String get color_yellow => 'Yellow';
|
||||
|
||||
@override
|
||||
String get color_purple => 'Purple';
|
||||
|
||||
@override
|
||||
String get color_orange => 'Orange';
|
||||
|
||||
@override
|
||||
String get color_pink => 'Pink';
|
||||
|
||||
@override
|
||||
String get color_teal => 'Teal';
|
||||
|
||||
@override
|
||||
String get color => 'Color';
|
||||
}
|
||||
|
||||
@@ -29,19 +29,31 @@ class GameTracker extends StatelessWidget {
|
||||
return supportedLocale;
|
||||
}
|
||||
}
|
||||
return supportedLocales.firstWhere((locale) => locale.languageCode == 'en');
|
||||
return supportedLocales.firstWhere(
|
||||
(locale) => locale.languageCode == 'en',
|
||||
);
|
||||
},
|
||||
debugShowCheckedModeBanner: false,
|
||||
onGenerateTitle: (context) => AppLocalizations.of(context).app_name,
|
||||
themeMode: ThemeMode.dark, // forces dark mode
|
||||
themeMode: ThemeMode.dark,
|
||||
theme: ThemeData(
|
||||
// main colors
|
||||
primaryColor: CustomTheme.primaryColor,
|
||||
scaffoldBackgroundColor: CustomTheme.backgroundColor,
|
||||
// themes
|
||||
appBarTheme: CustomTheme.appBarTheme,
|
||||
inputDecorationTheme: CustomTheme.inputDecorationTheme,
|
||||
searchBarTheme: CustomTheme.searchBarTheme,
|
||||
radioTheme: CustomTheme.radioTheme,
|
||||
// color scheme
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: CustomTheme.primaryColor,
|
||||
seedColor: CustomTheme.textColor,
|
||||
brightness: Brightness.dark,
|
||||
).copyWith(surface: CustomTheme.backgroundColor),
|
||||
primary: CustomTheme.primaryColor,
|
||||
onPrimary: CustomTheme.textColor,
|
||||
surface: CustomTheme.backgroundColor,
|
||||
onSurface: CustomTheme.textColor,
|
||||
),
|
||||
pageTransitionsTheme: const PageTransitionsTheme(
|
||||
builders: {
|
||||
TargetPlatform.iOS: CupertinoPageTransitionsBuilder(),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/group_view/groups_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/group_view/group_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/home_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/match_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/settings_view/settings_view.dart';
|
||||
@@ -40,7 +38,7 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
||||
),
|
||||
KeyedSubtree(
|
||||
key: ValueKey('groups_$tabKeyCount'),
|
||||
child: const GroupsView(),
|
||||
child: const GroupView(),
|
||||
),
|
||||
KeyedSubtree(
|
||||
key: ValueKey('stats_$tabKeyCount'),
|
||||
@@ -75,103 +73,62 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
body: tabs[currentIndex],
|
||||
extendBody: true,
|
||||
bottomNavigationBar: SizedBox(
|
||||
height: 70 + MediaQuery.of(context).padding.bottom,
|
||||
child: Stack(
|
||||
children: [
|
||||
// Dynamically generated blur layers for ultra-smooth transition
|
||||
...List.generate(34, (index) {
|
||||
// Use cubic curve for an even more natural, smoother transition
|
||||
final progress = index / 34.0; // 0.0 to 1.0
|
||||
final cubic = progress * progress * progress; // cubic curve
|
||||
final blurStrength =
|
||||
0.5 + (cubic * 50.0); // Very smooth from 0.5 to 50.5
|
||||
|
||||
// Height goes completely from 100% to 0% (all the way down)
|
||||
// With extra density at the bottom for softer transition
|
||||
final heightFactor = index < 25
|
||||
// First 25 layers: 100% to 30%
|
||||
? 1.0 - (progress * 0.7)
|
||||
// Last 10 layers: 30% to 0% (denser)
|
||||
: 0.3 - ((index - 25) / 34.0);
|
||||
|
||||
return Positioned(
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
height:
|
||||
(70 + MediaQuery.of(context).padding.bottom) *
|
||||
heightFactor.clamp(0.05, 1.0),
|
||||
child: ClipRect(
|
||||
child: BackdropFilter(
|
||||
filter: ImageFilter.blur(
|
||||
sigmaX: blurStrength,
|
||||
sigmaY: blurStrength,
|
||||
),
|
||||
child: Container(color: Colors.transparent),
|
||||
),
|
||||
),
|
||||
);
|
||||
}),
|
||||
// Gradient overlay
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.bottomCenter,
|
||||
end: Alignment.topCenter,
|
||||
colors: [
|
||||
CustomTheme.boxColor.withValues(alpha: 1),
|
||||
CustomTheme.boxColor.withValues(alpha: 0.5),
|
||||
CustomTheme.boxColor.withValues(alpha: 0.2),
|
||||
CustomTheme.boxColor.withValues(alpha: 0.0),
|
||||
],
|
||||
stops: const [0.0, 0.4, 0.8, 1],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Navbar content
|
||||
SafeArea(
|
||||
child: SizedBox(
|
||||
height: 70,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
NavbarItem(
|
||||
index: 0,
|
||||
isSelected: currentIndex == 0,
|
||||
icon: Icons.home_rounded,
|
||||
label: loc.home,
|
||||
onTabTapped: onTabTapped,
|
||||
),
|
||||
NavbarItem(
|
||||
index: 1,
|
||||
isSelected: currentIndex == 1,
|
||||
icon: Icons.gamepad_rounded,
|
||||
label: loc.matches,
|
||||
onTabTapped: onTabTapped,
|
||||
),
|
||||
NavbarItem(
|
||||
index: 2,
|
||||
isSelected: currentIndex == 2,
|
||||
icon: Icons.group_rounded,
|
||||
label: loc.groups,
|
||||
onTabTapped: onTabTapped,
|
||||
),
|
||||
NavbarItem(
|
||||
index: 3,
|
||||
isSelected: currentIndex == 3,
|
||||
icon: Icons.bar_chart_rounded,
|
||||
label: loc.statistics,
|
||||
onTabTapped: onTabTapped,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
bottomNavigationBar: Container(
|
||||
height: 115,
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.navBarBackgroundColor,
|
||||
border: Border.all(
|
||||
strokeAlign: BorderSide.strokeAlignOutside,
|
||||
color: CustomTheme.boxBorderColor,
|
||||
width: 2,
|
||||
),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(30),
|
||||
topRight: Radius.circular(30),
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withValues(alpha: 0.1),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, -5),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: <Widget>[
|
||||
NavbarItem(
|
||||
index: 0,
|
||||
isSelected: currentIndex == 0,
|
||||
icon: Icons.home_rounded,
|
||||
label: loc.home,
|
||||
onTabTapped: onTabTapped,
|
||||
),
|
||||
NavbarItem(
|
||||
index: 1,
|
||||
isSelected: currentIndex == 1,
|
||||
icon: Icons.gamepad_rounded,
|
||||
label: loc.matches,
|
||||
onTabTapped: onTabTapped,
|
||||
),
|
||||
NavbarItem(
|
||||
index: 2,
|
||||
isSelected: currentIndex == 2,
|
||||
icon: Icons.group_rounded,
|
||||
label: loc.groups,
|
||||
onTabTapped: onTabTapped,
|
||||
),
|
||||
NavbarItem(
|
||||
index: 3,
|
||||
isSelected: currentIndex == 3,
|
||||
icon: Icons.bar_chart_rounded,
|
||||
label: loc.statistics,
|
||||
onTabTapped: onTabTapped,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -184,7 +141,7 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
||||
}
|
||||
|
||||
/// Returns the title of the current tab based on [currentIndex].
|
||||
String _currentTabTitle(context) {
|
||||
String _currentTabTitle(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
switch (currentIndex) {
|
||||
case 0:
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tallee/core/constants.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
@@ -12,8 +11,10 @@ import 'package:tallee/presentation/widgets/player_selection.dart';
|
||||
import 'package:tallee/presentation/widgets/text_input/text_input_field.dart';
|
||||
|
||||
class CreateGroupView extends StatefulWidget {
|
||||
/// A view that allows the user to create a new group
|
||||
const CreateGroupView({super.key});
|
||||
const CreateGroupView({super.key, this.groupToEdit});
|
||||
|
||||
/// The group to edit, if any
|
||||
final Group? groupToEdit;
|
||||
|
||||
@override
|
||||
State<CreateGroupView> createState() => _CreateGroupViewState();
|
||||
@@ -22,16 +23,29 @@ class CreateGroupView extends StatefulWidget {
|
||||
class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
late final AppDatabase db;
|
||||
|
||||
/// GlobalKey for ScaffoldMessenger to show snackbars
|
||||
final _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
|
||||
|
||||
/// Controller for the group name input field
|
||||
final _groupNameController = TextEditingController();
|
||||
|
||||
/// List of currently selected players
|
||||
List<Player> selectedPlayers = [];
|
||||
|
||||
/// List of initially selected players (when editing a group)
|
||||
List<Player> initialSelectedPlayers = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
if (widget.groupToEdit != null) {
|
||||
_groupNameController.text = widget.groupToEdit!.name;
|
||||
setState(() {
|
||||
initialSelectedPlayers = widget.groupToEdit!.members;
|
||||
selectedPlayers = widget.groupToEdit!.members;
|
||||
});
|
||||
}
|
||||
_groupNameController.addListener(() {
|
||||
setState(() {});
|
||||
});
|
||||
@@ -47,10 +61,58 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
return ScaffoldMessenger(
|
||||
key: _scaffoldMessengerKey,
|
||||
child: Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
appBar: AppBar(title: Text(loc.create_new_group)),
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
widget.groupToEdit == null ? loc.create_new_group : loc.edit_group,
|
||||
),
|
||||
actions: widget.groupToEdit == null
|
||||
? []
|
||||
: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
if (widget.groupToEdit != null) {
|
||||
showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text(loc.delete_group),
|
||||
content: Text(loc.this_cannot_be_undone),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(false),
|
||||
child: Text(loc.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(true),
|
||||
child: Text(loc.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
).then((confirmed) async {
|
||||
if (confirmed == true && context.mounted) {
|
||||
bool success = await db.groupDao.deleteGroup(
|
||||
groupId: widget.groupToEdit!.id,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
if (success) {
|
||||
Navigator.pop(context);
|
||||
} else {
|
||||
if (!mounted) return;
|
||||
showSnackbar(message: loc.error_deleting_group);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
@@ -60,11 +122,11 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
child: TextInputField(
|
||||
controller: _groupNameController,
|
||||
hintText: loc.group_name,
|
||||
maxLength: Constants.MAX_GROUP_NAME_LENGTH,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: PlayerSelection(
|
||||
initialSelectedPlayers: initialSelectedPlayers,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
selectedPlayers = [...value];
|
||||
@@ -73,7 +135,9 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
),
|
||||
),
|
||||
CustomWidthButton(
|
||||
text: loc.create_group,
|
||||
text: widget.groupToEdit == null
|
||||
? loc.create_group
|
||||
: loc.edit_group,
|
||||
sizeRelativeToWidth: 0.95,
|
||||
buttonType: ButtonType.primary,
|
||||
onPressed:
|
||||
@@ -81,29 +145,38 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
(selectedPlayers.length < 2))
|
||||
? null
|
||||
: () async {
|
||||
bool success = await db.groupDao.addGroup(
|
||||
group: Group(
|
||||
late Group? updatedGroup;
|
||||
late bool success;
|
||||
if (widget.groupToEdit == null) {
|
||||
success = await db.groupDao.addGroup(
|
||||
group: Group(
|
||||
name: _groupNameController.text.trim(),
|
||||
members: selectedPlayers,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
updatedGroup = Group(
|
||||
id: widget.groupToEdit!.id,
|
||||
name: _groupNameController.text.trim(),
|
||||
description: '',
|
||||
members: selectedPlayers,
|
||||
),
|
||||
);
|
||||
);
|
||||
//TODO: Implement group editing in database
|
||||
/*
|
||||
success = await db.groupDao.updateGroup(
|
||||
group: updatedGroup,
|
||||
);
|
||||
*/
|
||||
success = true;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
if (success) {
|
||||
Navigator.pop(context);
|
||||
Navigator.pop(context, updatedGroup);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: CustomTheme.boxColor,
|
||||
content: Center(
|
||||
child: Text(
|
||||
AppLocalizations.of(
|
||||
context,
|
||||
).error_creating_group,
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
showSnackbar(
|
||||
message: widget.groupToEdit == null
|
||||
? loc.error_creating_group
|
||||
: loc.error_editing_group,
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -115,4 +188,20 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Displays a snackbar with the given message and optional action.
|
||||
///
|
||||
/// [message] The message to display in the snackbar.
|
||||
void showSnackbar({required String message}) {
|
||||
final messenger = _scaffoldMessengerKey.currentState;
|
||||
if (messenger != null) {
|
||||
messenger.hideCurrentSnackBar();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message, style: const TextStyle(color: Colors.white)),
|
||||
backgroundColor: CustomTheme.boxColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/group.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/group_view/create_group_view.dart';
|
||||
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/animated_dialog_button.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||
@@ -15,10 +17,10 @@ import 'package:tallee/presentation/widgets/custom_alert_dialog.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/info_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/text_icon_tile.dart';
|
||||
|
||||
class GroupProfileView extends StatefulWidget {
|
||||
class GroupDetailView extends StatefulWidget {
|
||||
/// A view that displays the profile of a group
|
||||
/// - [group]: The group to display
|
||||
const GroupProfileView({
|
||||
const GroupDetailView({
|
||||
super.key,
|
||||
required this.group,
|
||||
required this.callback,
|
||||
@@ -30,21 +32,24 @@ class GroupProfileView extends StatefulWidget {
|
||||
final VoidCallback callback;
|
||||
|
||||
@override
|
||||
State<GroupProfileView> createState() => _GroupProfileViewState();
|
||||
State<GroupDetailView> createState() => _GroupDetailViewState();
|
||||
}
|
||||
|
||||
class _GroupProfileViewState extends State<GroupProfileView> {
|
||||
class _GroupDetailViewState extends State<GroupDetailView> {
|
||||
late final AppDatabase db;
|
||||
bool isLoading = true;
|
||||
late Group _group;
|
||||
|
||||
/// Total matches played in this group
|
||||
int totalMatches = 0;
|
||||
|
||||
/// The best player in this group
|
||||
String bestPlayer = '';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_group = widget.group;
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
_loadStatistics();
|
||||
}
|
||||
@@ -87,7 +92,7 @@ class _GroupProfileViewState extends State<GroupProfileView> {
|
||||
),
|
||||
).then((confirmed) async {
|
||||
if (confirmed! && context.mounted) {
|
||||
await db.groupDao.deleteGroup(groupId: widget.group.id);
|
||||
await db.groupDao.deleteGroup(groupId: _group.id);
|
||||
if (!context.mounted) return;
|
||||
Navigator.pop(context);
|
||||
widget.callback.call();
|
||||
@@ -118,7 +123,7 @@ class _GroupProfileViewState extends State<GroupProfileView> {
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
widget.group.name,
|
||||
_group.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -128,7 +133,7 @@ class _GroupProfileViewState extends State<GroupProfileView> {
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
'${loc.created_on} ${DateFormat.yMMMd(Localizations.localeOf(context).toString()).format(widget.group.createdAt)}',
|
||||
'${loc.created_on} ${DateFormat.yMMMd(Localizations.localeOf(context).toString()).format(_group.createdAt)}',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: CustomTheme.textColor,
|
||||
@@ -145,7 +150,7 @@ class _GroupProfileViewState extends State<GroupProfileView> {
|
||||
crossAxisAlignment: WrapCrossAlignment.start,
|
||||
spacing: 12,
|
||||
runSpacing: 8,
|
||||
children: widget.group.members.map((member) {
|
||||
children: _group.members.map((member) {
|
||||
return TextIconTile(
|
||||
text: member.name,
|
||||
iconEnabled: false,
|
||||
@@ -163,7 +168,7 @@ class _GroupProfileViewState extends State<GroupProfileView> {
|
||||
children: [
|
||||
_buildStatRow(
|
||||
loc.members,
|
||||
widget.group.members.length.toString(),
|
||||
_group.members.length.toString(),
|
||||
),
|
||||
_buildStatRow(
|
||||
loc.played_matches,
|
||||
@@ -181,19 +186,22 @@ class _GroupProfileViewState extends State<GroupProfileView> {
|
||||
child: MainMenuButton(
|
||||
text: loc.edit_group,
|
||||
icon: Icons.edit,
|
||||
onPressed: () {
|
||||
// TODO: Uncomment when GroupDetailView is implemented
|
||||
/*
|
||||
await Navigator.push(
|
||||
onPressed: () async {
|
||||
final updatedGroup = await Navigator.push<Group?>(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) {
|
||||
|
||||
return const GroupDetailView();
|
||||
return CreateGroupView(groupToEdit: _group);
|
||||
},
|
||||
),
|
||||
);*/
|
||||
print('Edit Group pressed');
|
||||
);
|
||||
if (updatedGroup != null && mounted) {
|
||||
setState(() {
|
||||
_group = updatedGroup;
|
||||
});
|
||||
_loadStatistics();
|
||||
widget.callback();
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -236,7 +244,7 @@ class _GroupProfileViewState extends State<GroupProfileView> {
|
||||
Future<void> _loadStatistics() async {
|
||||
final matches = await db.matchDao.getAllMatches();
|
||||
final groupMatches = matches
|
||||
.where((match) => match.group?.id == widget.group.id)
|
||||
.where((match) => match.group?.id == _group.id)
|
||||
.toList();
|
||||
|
||||
setState(() {
|
||||
@@ -8,21 +8,21 @@ import 'package:tallee/data/dto/group.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/group_view/create_group_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/group_view/group_profile_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/group_view/group_detail_view.dart';
|
||||
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/group_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/top_centered_message.dart';
|
||||
|
||||
class GroupsView extends StatefulWidget {
|
||||
class GroupView extends StatefulWidget {
|
||||
/// A view that displays a list of groups
|
||||
const GroupsView({super.key});
|
||||
const GroupView({super.key});
|
||||
|
||||
@override
|
||||
State<GroupsView> createState() => _GroupsViewState();
|
||||
State<GroupView> createState() => _GroupViewState();
|
||||
}
|
||||
|
||||
class _GroupsViewState extends State<GroupsView> {
|
||||
class _GroupViewState extends State<GroupView> {
|
||||
late final AppDatabase db;
|
||||
|
||||
/// Loaded groups from the database
|
||||
@@ -83,7 +83,7 @@ class _GroupsViewState extends State<GroupsView> {
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) {
|
||||
return GroupProfileView(
|
||||
return GroupDetailView(
|
||||
group: groups[index],
|
||||
callback: loadGroups,
|
||||
);
|
||||
@@ -42,7 +42,12 @@ class _HomeViewState extends State<HomeView> {
|
||||
2,
|
||||
Match(
|
||||
name: 'Skeleton Match',
|
||||
game: Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: GameColor.blue, icon: ''),
|
||||
game: Game(
|
||||
name: '',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: '',
|
||||
color: GameColor.blue,
|
||||
),
|
||||
group: Group(
|
||||
name: 'Skeleton Group',
|
||||
description: '',
|
||||
@@ -104,7 +109,9 @@ class _HomeViewState extends State<HomeView> {
|
||||
if (recentMatches.isNotEmpty)
|
||||
for (Match match in recentMatches)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6.0),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 6.0,
|
||||
),
|
||||
child: MatchTile(
|
||||
compact: true,
|
||||
width: constraints.maxWidth * 0.9,
|
||||
@@ -113,7 +120,8 @@ class _HomeViewState extends State<HomeView> {
|
||||
await Navigator.of(context).push(
|
||||
adaptivePageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (context) => MatchResultView(match: match),
|
||||
builder: (context) =>
|
||||
MatchResultView(match: match),
|
||||
),
|
||||
);
|
||||
await updatedWinnerInRecentMatches(match.id);
|
||||
@@ -121,7 +129,10 @@ class _HomeViewState extends State<HomeView> {
|
||||
),
|
||||
)
|
||||
else
|
||||
Center(heightFactor: 5, child: Text(loc.no_recent_matches_available)),
|
||||
Center(
|
||||
heightFactor: 5,
|
||||
child: Text(loc.no_recent_matches_available),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -137,22 +148,40 @@ class _HomeViewState extends State<HomeView> {
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
QuickCreateButton(text: 'Category 1', onPressed: () {}),
|
||||
QuickCreateButton(text: 'Category 2', onPressed: () {}),
|
||||
QuickCreateButton(
|
||||
text: 'Category 1',
|
||||
onPressed: () {},
|
||||
),
|
||||
QuickCreateButton(
|
||||
text: 'Category 2',
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
QuickCreateButton(text: 'Category 3', onPressed: () {}),
|
||||
QuickCreateButton(text: 'Category 4', onPressed: () {}),
|
||||
QuickCreateButton(
|
||||
text: 'Category 3',
|
||||
onPressed: () {},
|
||||
),
|
||||
QuickCreateButton(
|
||||
text: 'Category 4',
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
QuickCreateButton(text: 'Category 5', onPressed: () {}),
|
||||
QuickCreateButton(text: 'Category 6', onPressed: () {}),
|
||||
QuickCreateButton(
|
||||
text: 'Category 5',
|
||||
onPressed: () {},
|
||||
),
|
||||
QuickCreateButton(
|
||||
text: 'Category 6',
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
@@ -181,9 +210,11 @@ class _HomeViewState extends State<HomeView> {
|
||||
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();
|
||||
recentMatches =
|
||||
(loadedRecentMatches
|
||||
..sort((a, b) => b.createdAt.compareTo(a.createdAt)))
|
||||
.take(2)
|
||||
.toList();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
|
||||
@@ -1,25 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/game_view/create_game_view.dart';
|
||||
import 'package:tallee/presentation/widgets/text_input/custom_search_bar.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/title_description_list_tile.dart';
|
||||
|
||||
class ChooseGameView extends StatefulWidget {
|
||||
/// A view that allows the user to choose a game from a list of available games
|
||||
/// - [games]: A list of tuples containing the game name, description and ruleset
|
||||
/// - [initialGameIndex]: The index of the initially selected game
|
||||
/// - [games]: The list of available games
|
||||
/// - [initialSelectedGameId]: The id of the initially selected game
|
||||
/// - [onGamesUpdated]: Optional callback invoked when the games are updated
|
||||
const ChooseGameView({
|
||||
super.key,
|
||||
required this.games,
|
||||
required this.initialGameIndex,
|
||||
required this.initialSelectedGameId,
|
||||
this.onGamesUpdated,
|
||||
});
|
||||
|
||||
/// A list of tuples containing the game name, description and ruleset
|
||||
final List<(String, String, Ruleset)> games;
|
||||
final List<Game> games;
|
||||
|
||||
/// The index of the initially selected game
|
||||
final int initialGameIndex;
|
||||
final String initialSelectedGameId;
|
||||
|
||||
/// Optional callback invoked when the games are updated
|
||||
final VoidCallback? onGamesUpdated;
|
||||
|
||||
@override
|
||||
State<ChooseGameView> createState() => _ChooseGameViewState();
|
||||
@@ -29,12 +37,18 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
/// Controller for the search bar
|
||||
final TextEditingController searchBarController = TextEditingController();
|
||||
|
||||
/// Currently selected game index
|
||||
late int selectedGameIndex;
|
||||
/// Currently selected game id
|
||||
late String selectedGameId;
|
||||
|
||||
/// Games filtered according to the current search query
|
||||
late List<Game> filteredGames;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
selectedGameIndex = widget.initialGameIndex;
|
||||
selectedGameId = widget.initialSelectedGameId;
|
||||
|
||||
// Start with all games visible
|
||||
filteredGames = List<Game>.from(widget.games);
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -48,9 +62,32 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(selectedGameIndex);
|
||||
Navigator.of(context).pop(selectedGameId);
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () async {
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) => CreateGameView(
|
||||
onGameChanged: () {
|
||||
widget.onGamesUpdated?.call();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
if (result != null && result.game != null) {
|
||||
setState(() {
|
||||
widget.games.insert(0, result.game);
|
||||
});
|
||||
_refreshFromSource();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
title: Text(loc.choose_game),
|
||||
),
|
||||
body: PopScope(
|
||||
@@ -61,7 +98,7 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
if (didPop) {
|
||||
return;
|
||||
}
|
||||
Navigator.of(context).pop(selectedGameIndex);
|
||||
Navigator.of(context).pop(selectedGameId);
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
@@ -70,30 +107,63 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
child: CustomSearchBar(
|
||||
controller: searchBarController,
|
||||
hintText: loc.game_name,
|
||||
onChanged: (value) {
|
||||
_applySearchFilter(value);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: widget.games.length,
|
||||
itemCount: filteredGames.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final game = filteredGames[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 {
|
||||
title: game.name,
|
||||
description: game.description,
|
||||
badgeText: translateRulesetToString(game.ruleset, context),
|
||||
isHighlighted: selectedGameId == game.id,
|
||||
onTap: () async {
|
||||
setState(() {
|
||||
if (selectedGameIndex == index) {
|
||||
selectedGameIndex = -1;
|
||||
if (selectedGameId == game.id) {
|
||||
selectedGameId = '';
|
||||
} else {
|
||||
selectedGameIndex = index;
|
||||
selectedGameId = game.id;
|
||||
}
|
||||
});
|
||||
},
|
||||
onLongPress: () async {
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) => CreateGameView(
|
||||
gameToEdit: game,
|
||||
onGameChanged: () {
|
||||
widget.onGamesUpdated?.call();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
if (result != null && result.game != null) {
|
||||
// Find the index in the original list to mutate
|
||||
final originalIndex = widget.games.indexWhere(
|
||||
(g) => g.id == game.id,
|
||||
);
|
||||
if (originalIndex == -1) {
|
||||
return;
|
||||
}
|
||||
if (result.delete) {
|
||||
setState(() {
|
||||
widget.games.removeAt(originalIndex);
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
widget.games[originalIndex] = result.game;
|
||||
});
|
||||
}
|
||||
_refreshFromSource();
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -103,4 +173,28 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Applies the search filter to the games list based on [query].
|
||||
void _applySearchFilter(String query) {
|
||||
final q = query.toLowerCase().trim();
|
||||
if (q.isEmpty) {
|
||||
setState(() {
|
||||
filteredGames = List<Game>.from(widget.games);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
filteredGames = widget.games.where((game) {
|
||||
final name = game.name.toLowerCase();
|
||||
final description = game.description.toLowerCase();
|
||||
return name.contains(q) || description.contains(q);
|
||||
}).toList();
|
||||
});
|
||||
}
|
||||
|
||||
/// Re-applies the current filter after the underlying games list changed.
|
||||
void _refreshFromSource() {
|
||||
_applySearchFilter(searchBarController.text);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,53 +18,65 @@ import 'package:tallee/presentation/widgets/player_selection.dart';
|
||||
import 'package:tallee/presentation/widgets/text_input/text_input_field.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/choose_tile.dart';
|
||||
|
||||
/// A stateful widget for creating or editing a match.
|
||||
class CreateMatchView extends StatefulWidget {
|
||||
/// A view that allows creating a new match
|
||||
/// [onWinnerChanged]: Optional callback invoked when the winner is changed
|
||||
const CreateMatchView({super.key, this.onWinnerChanged});
|
||||
/// Constructor for `CreateMatchView`.
|
||||
///
|
||||
/// [onWinnerChanged] is an optional callback invoked when the winner is changed.
|
||||
/// [matchToEdit] is an optional match to prefill the fields.
|
||||
/// [onMatchUpdated] is an optional callback invoked when the match is updated.
|
||||
const CreateMatchView({
|
||||
super.key,
|
||||
this.onWinnerChanged,
|
||||
this.matchToEdit,
|
||||
this.onMatchUpdated,
|
||||
});
|
||||
|
||||
/// Optional callback invoked when the winner is changed
|
||||
/// Optional callback invoked when the winner is changed.
|
||||
final VoidCallback? onWinnerChanged;
|
||||
|
||||
/// Optional callback invoked when the match is updated.
|
||||
final void Function(Match)? onMatchUpdated;
|
||||
|
||||
/// An optional match to prefill the fields.
|
||||
final Match? matchToEdit;
|
||||
|
||||
@override
|
||||
State<CreateMatchView> createState() => _CreateMatchViewState();
|
||||
}
|
||||
|
||||
/// The state class for `CreateMatchView`, managing the UI and logic for creating or editing a match.
|
||||
class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
/// The database instance for accessing match data.
|
||||
late final AppDatabase db;
|
||||
|
||||
/// Controller for the match name input field
|
||||
/// Controller for the match name input field.
|
||||
final TextEditingController _matchNameController = TextEditingController();
|
||||
|
||||
/// Hint text for the match name input field
|
||||
/// Hint text for the match name input field.
|
||||
String? hintText;
|
||||
|
||||
/// List of all groups from the database
|
||||
/// List of all games from the database.
|
||||
List<Game> gamesList = [];
|
||||
|
||||
/// List of all groups from the database.
|
||||
List<Group> groupsList = [];
|
||||
|
||||
/// List of all players from the database
|
||||
/// 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
|
||||
/// 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 game.
|
||||
Game? selectedGame;
|
||||
|
||||
/// The index of the currently selected game in [games] to mark it in
|
||||
/// the [ChooseGameView]
|
||||
int selectedGameIndex = -1;
|
||||
|
||||
/// The currently selected players
|
||||
/// The currently selected players.
|
||||
List<Player> selectedPlayers = [];
|
||||
|
||||
/// GlobalKey for ScaffoldMessenger to show snackbars.
|
||||
final _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -74,15 +86,21 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
|
||||
// Load games, groups, and players from the database.
|
||||
Future.wait([
|
||||
db.gameDao.getAllGames(),
|
||||
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);
|
||||
});
|
||||
gamesList = result[0] as List<Game>;
|
||||
gamesList.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
groupsList = result[1] as List<Group>;
|
||||
playerList = result[2] as List<Player>;
|
||||
|
||||
// If a match is provided, prefill the fields.
|
||||
if (widget.matchToEdit != null) {
|
||||
prefillMatchDetails();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -99,23 +117,27 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
hintText ??= loc.match_name;
|
||||
}
|
||||
|
||||
List<(String, String, Ruleset)> games = [
|
||||
('Example Game 1', 'This is a description', Ruleset.lowestScore),
|
||||
('Example Game 2', '', Ruleset.singleWinner),
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
final buttonText = widget.matchToEdit != null
|
||||
? loc.save_changes
|
||||
: loc.create_match;
|
||||
final viewTitle = widget.matchToEdit != null
|
||||
? loc.edit_match
|
||||
: loc.create_new_match;
|
||||
|
||||
return ScaffoldMessenger(
|
||||
key: _scaffoldMessengerKey,
|
||||
child: Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
appBar: AppBar(title: Text(loc.create_new_match)),
|
||||
appBar: AppBar(title: Text(viewTitle)),
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
// Match name input field.
|
||||
Container(
|
||||
margin: CustomTheme.tileMargin,
|
||||
child: TextInputField(
|
||||
@@ -124,125 +146,96 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
maxLength: Constants.MAX_MATCH_NAME_LENGTH,
|
||||
),
|
||||
),
|
||||
// Game selection tile.
|
||||
ChooseTile(
|
||||
title: loc.game,
|
||||
trailingText: selectedGameIndex == -1
|
||||
trailingText: selectedGame == null
|
||||
? loc.none
|
||||
: games[selectedGameIndex].$1,
|
||||
: selectedGame!.name,
|
||||
onPressed: () async {
|
||||
selectedGameIndex = await Navigator.of(context).push(
|
||||
adaptivePageRoute(
|
||||
builder: (context) => ChooseGameView(
|
||||
games: games,
|
||||
initialGameIndex: selectedGameIndex,
|
||||
),
|
||||
),
|
||||
);
|
||||
final String? selectedGameId = await Navigator.of(context)
|
||||
.push(
|
||||
adaptivePageRoute(
|
||||
builder: (context) => ChooseGameView(
|
||||
games: gamesList,
|
||||
initialSelectedGameId: selectedGame?.id ?? '',
|
||||
onGamesUpdated: loadGames,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
try {
|
||||
selectedGame = gamesList.firstWhere(
|
||||
(g) => g.id == selectedGameId,
|
||||
);
|
||||
} catch (_) {
|
||||
selectedGame = null;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
if (selectedGameIndex != -1) {
|
||||
hintText = games[selectedGameIndex].$1;
|
||||
if (selectedGame != null) {
|
||||
hintText = selectedGame!.name;
|
||||
} else {
|
||||
hintText = loc.match_name;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
// Group selection tile.
|
||||
ChooseTile(
|
||||
title: loc.group,
|
||||
trailingText: selectedGroup == null
|
||||
? loc.none_group
|
||||
: selectedGroup!.name,
|
||||
onPressed: () async {
|
||||
selectedPlayers.removeWhere(
|
||||
(player) =>
|
||||
selectedGroup?.members.any(
|
||||
(member) => member.id == player.id,
|
||||
) ??
|
||||
false,
|
||||
);
|
||||
|
||||
selectedGroup = await Navigator.of(context).push(
|
||||
adaptivePageRoute(
|
||||
builder: (context) => ChooseGroupView(
|
||||
groups: groupsList,
|
||||
initialGroupId: selectedGroupId,
|
||||
initialGroupId: selectedGroup?.id ?? '',
|
||||
),
|
||||
),
|
||||
);
|
||||
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(() {});
|
||||
|
||||
setState(() {
|
||||
if (selectedGroup != null) {
|
||||
setState(() {
|
||||
selectedPlayers += [...selectedGroup!.members];
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
// Player selection widget.
|
||||
Expanded(
|
||||
child: PlayerSelection(
|
||||
key: ValueKey(selectedGroup?.id ?? 'no_group'),
|
||||
initialSelectedPlayers: selectedPlayers,
|
||||
availablePlayers: filteredPlayerList,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
selectedPlayers = value;
|
||||
removeGroupWhenNoMemberLeft();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
// Create or save button.
|
||||
CustomWidthButton(
|
||||
text: loc.create_match,
|
||||
text: buttonText,
|
||||
sizeRelativeToWidth: 0.95,
|
||||
buttonType: ButtonType.primary,
|
||||
onPressed: _enableCreateGameButton()
|
||||
? () async {
|
||||
// Use a game from the games list
|
||||
Game? gameToUse;
|
||||
if (selectedGameIndex == -1) {
|
||||
// Use the first game as default if none selected
|
||||
final selectedGame = games[0];
|
||||
gameToUse = Game(
|
||||
name: selectedGame.$1,
|
||||
description: selectedGame.$2,
|
||||
ruleset: selectedGame.$3,
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
} else {
|
||||
// Use the selected game from the list
|
||||
final selectedGame = games[selectedGameIndex];
|
||||
gameToUse = Game(
|
||||
name: selectedGame.$1,
|
||||
description: selectedGame.$2,
|
||||
ruleset: selectedGame.$3,
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
);
|
||||
}
|
||||
// Add the game to the database if it doesn't exist
|
||||
await db.gameDao.addGame(game: gameToUse);
|
||||
|
||||
Match match = Match(
|
||||
name: _matchNameController.text.isEmpty
|
||||
? (hintText ?? '')
|
||||
: _matchNameController.text.trim(),
|
||||
createdAt: DateTime.now(),
|
||||
game: gameToUse,
|
||||
group: selectedGroup,
|
||||
players: selectedPlayers,
|
||||
notes: '',
|
||||
);
|
||||
await db.matchDao.addMatch(match: match);
|
||||
if (context.mounted) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (context) => MatchResultView(
|
||||
match: match,
|
||||
onWinnerChanged: widget.onWinnerChanged,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
? () {
|
||||
buttonNavigation(context);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
],
|
||||
@@ -256,9 +249,148 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
///
|
||||
/// Returns `true` if:
|
||||
/// - A ruleset is selected AND
|
||||
/// - Either a group is selected OR at least 2 players are selected
|
||||
/// - Either a group is selected OR at least 2 players are selected.
|
||||
bool _enableCreateGameButton() {
|
||||
return (selectedGroup != null ||
|
||||
(selectedPlayers.length > 1));
|
||||
(selectedPlayers.length > 1) && selectedGame != null);
|
||||
}
|
||||
|
||||
/// Handles navigation when the create or save button is pressed.
|
||||
///
|
||||
/// If a match is being edited, updates the match in the database.
|
||||
/// Otherwise, creates a new match and navigates to the MatchResultView.
|
||||
void buttonNavigation(BuildContext context) async {
|
||||
if (widget.matchToEdit != null) {
|
||||
await updateMatch();
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
} else {
|
||||
final match = await createMatch();
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (context) => MatchResultView(
|
||||
match: match,
|
||||
onWinnerChanged: widget.onWinnerChanged,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates the existing match in the database.
|
||||
Future<void> updateMatch() async {
|
||||
final updatedMatch = Match(
|
||||
id: widget.matchToEdit!.id,
|
||||
name: _matchNameController.text.isEmpty
|
||||
? (hintText ?? '')
|
||||
: _matchNameController.text.trim(),
|
||||
group: selectedGroup,
|
||||
players: selectedPlayers,
|
||||
game: selectedGame!,
|
||||
winner: widget.matchToEdit!.winner,
|
||||
createdAt: widget.matchToEdit!.createdAt,
|
||||
endedAt: widget.matchToEdit!.endedAt,
|
||||
notes: widget.matchToEdit!.notes,
|
||||
);
|
||||
|
||||
if (widget.matchToEdit!.name != updatedMatch.name) {
|
||||
await db.matchDao.updateMatchName(
|
||||
matchId: widget.matchToEdit!.id,
|
||||
newName: updatedMatch.name,
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.matchToEdit!.group?.id != updatedMatch.group?.id) {
|
||||
await db.matchDao.updateMatchGroup(
|
||||
matchId: widget.matchToEdit!.id,
|
||||
newGroupId: updatedMatch.group?.id,
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.matchToEdit!.game.id != updatedMatch.game.id) {
|
||||
await db.matchDao.updateMatchGame(
|
||||
matchId: widget.matchToEdit!.id,
|
||||
gameId: updatedMatch.game.id,
|
||||
);
|
||||
}
|
||||
|
||||
for (var player in updatedMatch.players) {
|
||||
if (!widget.matchToEdit!.players.any((p) => p.id == player.id)) {
|
||||
await db.playerMatchDao.addPlayerToMatch(
|
||||
matchId: widget.matchToEdit!.id,
|
||||
playerId: player.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (var player in widget.matchToEdit!.players) {
|
||||
if (!updatedMatch.players.any((p) => p.id == player.id)) {
|
||||
await db.playerMatchDao.removePlayerFromMatch(
|
||||
matchId: widget.matchToEdit!.id,
|
||||
playerId: player.id,
|
||||
);
|
||||
if (widget.matchToEdit!.winner?.id == player.id) {
|
||||
updatedMatch.winner = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
widget.onMatchUpdated?.call(updatedMatch);
|
||||
}
|
||||
|
||||
/// Creates a new match and adds it to the database.
|
||||
Future<Match> createMatch() async {
|
||||
Match match = Match(
|
||||
name: _matchNameController.text.isEmpty
|
||||
? (hintText ?? '')
|
||||
: _matchNameController.text.trim(),
|
||||
createdAt: DateTime.now(),
|
||||
group: selectedGroup,
|
||||
players: selectedPlayers,
|
||||
game: selectedGame!,
|
||||
);
|
||||
await db.matchDao.addMatch(match: match);
|
||||
return match;
|
||||
}
|
||||
|
||||
/// Prefills the input fields if a match was provided to the view.
|
||||
void prefillMatchDetails() {
|
||||
final match = widget.matchToEdit!;
|
||||
_matchNameController.text = match.name;
|
||||
selectedPlayers = match.players;
|
||||
selectedGame = match.game;
|
||||
|
||||
if (match.group != null) {
|
||||
selectedGroup = match.group;
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes the group if none of its members are in the selected players list.
|
||||
Future<void> removeGroupWhenNoMemberLeft() async {
|
||||
if (selectedGroup == null) return;
|
||||
|
||||
if (!selectedPlayers.any(
|
||||
(player) =>
|
||||
selectedGroup!.members.any((member) => member.id == player.id),
|
||||
)) {
|
||||
setState(() {
|
||||
selectedGroup = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Loads all games from the database and updates the state.
|
||||
Future<void> loadGames() async {
|
||||
final result = await db.gameDao.getAllGames();
|
||||
result.sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
setState(() {
|
||||
gamesList = result;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/title_description_list_tile.dart';
|
||||
|
||||
class ChooseColorView extends StatefulWidget {
|
||||
/// A view that allows the user to choose a color from a list of available game colors
|
||||
/// - [initialColor]: The initially selected color
|
||||
const ChooseColorView({super.key, this.initialColor});
|
||||
|
||||
/// The initially selected color
|
||||
final GameColor? initialColor;
|
||||
|
||||
@override
|
||||
State<ChooseColorView> createState() => _ChooseColorViewState();
|
||||
}
|
||||
|
||||
class _ChooseColorViewState extends State<ChooseColorView> {
|
||||
/// Currently selected color
|
||||
GameColor? selectedColor;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
selectedColor = widget.initialColor;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
const colors = GameColor.values;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(selectedColor);
|
||||
},
|
||||
),
|
||||
title: Text(loc.choose_color),
|
||||
),
|
||||
body: PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (bool didPop, Object? result) {
|
||||
if (didPop) return;
|
||||
Navigator.of(context).pop(selectedColor);
|
||||
},
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.only(bottom: 85),
|
||||
itemCount: colors.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final color = colors[index];
|
||||
return TitleDescriptionListTile(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
if (selectedColor == color) {
|
||||
selectedColor = null;
|
||||
} else {
|
||||
selectedColor = color;
|
||||
}
|
||||
});
|
||||
},
|
||||
title: translateGameColorToString(color, context),
|
||||
description: '',
|
||||
isHighlighted: selectedColor == color,
|
||||
badgeText: ' ', //Breite für Color Badge
|
||||
badgeColor: getColorFromGameColor(color),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/title_description_list_tile.dart';
|
||||
|
||||
class ChooseRulesetView extends StatefulWidget {
|
||||
/// A view that allows the user to choose a ruleset from a list of available rulesets
|
||||
/// - [rulesets]: A list of tuples containing the ruleset and its description
|
||||
/// - [initialRulesetIndex]: The index of the initially selected ruleset
|
||||
const ChooseRulesetView({
|
||||
super.key,
|
||||
required this.rulesets,
|
||||
required this.initialRulesetIndex,
|
||||
});
|
||||
|
||||
/// A list of tuples containing the ruleset and its description
|
||||
final List<(Ruleset, String)> rulesets;
|
||||
|
||||
/// The index of the initially selected ruleset
|
||||
final int 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(
|
||||
onTap: () 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,351 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/constants.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/data/dto/group.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/game_view/choose_color_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/game_view/choose_ruleset_view.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/custom_width_button.dart';
|
||||
import 'package:tallee/presentation/widgets/custom_alert_dialog.dart';
|
||||
import 'package:tallee/presentation/widgets/text_input/text_input_field.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/choose_tile.dart';
|
||||
|
||||
/// A stateful widget for creating or editing a game.
|
||||
/// - [gameToEdit] An optional game to prefill the fields
|
||||
/// - [onGameChanged] Callback to invoke when the game is created or edited
|
||||
class CreateGameView extends StatefulWidget {
|
||||
const CreateGameView({
|
||||
super.key,
|
||||
this.gameToEdit,
|
||||
required this.onGameChanged,
|
||||
});
|
||||
|
||||
/// An optional game to prefill the fields
|
||||
final Game? gameToEdit;
|
||||
|
||||
/// Callback to invoke when the game is created or edited
|
||||
final VoidCallback onGameChanged;
|
||||
|
||||
@override
|
||||
State<CreateGameView> createState() => _CreateGameViewState();
|
||||
}
|
||||
|
||||
class _CreateGameViewState extends State<CreateGameView> {
|
||||
/// GlobalKey for ScaffoldMessenger to show snackbars
|
||||
final _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
|
||||
|
||||
/// The database instance for accessing game data.
|
||||
late final AppDatabase db;
|
||||
|
||||
/// The currently selected ruleset for the game.
|
||||
Ruleset? selectedRuleset;
|
||||
|
||||
/// The index of the currently selected ruleset.
|
||||
int selectedRulesetIndex = -1;
|
||||
|
||||
/// A list of available rulesets and their localized names.
|
||||
late List<(Ruleset, String)> _rulesets;
|
||||
|
||||
/// The currently selected color for the game.
|
||||
GameColor? selectedColor;
|
||||
|
||||
/// Controller for the game name input field.
|
||||
final _gameNameController = TextEditingController();
|
||||
|
||||
/// Controller for the game description input field.
|
||||
final _descriptionController = TextEditingController();
|
||||
|
||||
/// The ID of the currently selected group.
|
||||
late String selectedGroupId;
|
||||
|
||||
/// A controller for the search bar input field.
|
||||
final TextEditingController controller = TextEditingController();
|
||||
|
||||
/// A list of groups filtered based on the search query.
|
||||
late final List<Group> filteredGroups;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
_gameNameController.addListener(() => setState(() {}));
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_rulesets = [
|
||||
(
|
||||
Ruleset.singleWinner,
|
||||
translateRulesetToString(Ruleset.singleWinner, context),
|
||||
),
|
||||
(
|
||||
Ruleset.singleLoser,
|
||||
translateRulesetToString(Ruleset.singleLoser, context),
|
||||
),
|
||||
(
|
||||
Ruleset.highestScore,
|
||||
translateRulesetToString(Ruleset.highestScore, context),
|
||||
),
|
||||
(
|
||||
Ruleset.lowestScore,
|
||||
translateRulesetToString(Ruleset.lowestScore, context),
|
||||
),
|
||||
(
|
||||
Ruleset.multipleWinners,
|
||||
translateRulesetToString(Ruleset.multipleWinners, context),
|
||||
),
|
||||
];
|
||||
|
||||
if (widget.gameToEdit != null) {
|
||||
_gameNameController.text = widget.gameToEdit!.name;
|
||||
_descriptionController.text = widget.gameToEdit!.description;
|
||||
selectedRuleset = widget.gameToEdit!.ruleset;
|
||||
selectedColor = widget.gameToEdit!.color;
|
||||
|
||||
selectedRulesetIndex = _rulesets.indexWhere(
|
||||
(r) => r.$1 == selectedRuleset,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_gameNameController.dispose();
|
||||
_descriptionController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var loc = AppLocalizations.of(context);
|
||||
final isEditing = widget.gameToEdit != null;
|
||||
|
||||
return ScaffoldMessenger(
|
||||
child: Scaffold(
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
appBar: AppBar(
|
||||
title: Text(isEditing ? loc.edit_game : loc.create_game),
|
||||
actions: widget.gameToEdit == null
|
||||
? []
|
||||
: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
if (widget.gameToEdit != null) {
|
||||
showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => CustomAlertDialog(
|
||||
title: loc.delete_game,
|
||||
content: loc.this_cannot_be_undone,
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(false),
|
||||
child: Text(loc.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () =>
|
||||
Navigator.of(context).pop(true),
|
||||
child: Text(loc.delete),
|
||||
),
|
||||
],
|
||||
),
|
||||
).then((confirmed) async {
|
||||
if (confirmed == true && context.mounted) {
|
||||
bool success = await db.gameDao.deleteGame(
|
||||
gameId: widget.gameToEdit!.id,
|
||||
);
|
||||
if (!context.mounted) return;
|
||||
if (success) {
|
||||
widget.onGameChanged.call();
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop((game: widget.gameToEdit, delete: true));
|
||||
} else {
|
||||
if (!mounted) return;
|
||||
showSnackbar(message: loc.error_deleting_game);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
margin: CustomTheme.tileMargin,
|
||||
child: TextInputField(
|
||||
controller: _gameNameController,
|
||||
maxLength: Constants.MAX_MATCH_NAME_LENGTH,
|
||||
hintText: loc.game_name,
|
||||
),
|
||||
),
|
||||
ChooseTile(
|
||||
title: loc.ruleset,
|
||||
trailingText: selectedRuleset == null
|
||||
? loc.none
|
||||
: translateRulesetToString(selectedRuleset!, context),
|
||||
onPressed: () async {
|
||||
final result = await Navigator.of(context).push<Ruleset?>(
|
||||
adaptivePageRoute(
|
||||
builder: (context) => ChooseRulesetView(
|
||||
rulesets: _rulesets,
|
||||
initialRulesetIndex: selectedRulesetIndex,
|
||||
),
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
selectedRuleset = result;
|
||||
selectedRulesetIndex = result == null
|
||||
? -1
|
||||
: _rulesets.indexWhere((r) => r.$1 == result);
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
ChooseTile(
|
||||
title: loc.color,
|
||||
trailingText: selectedColor == null
|
||||
? loc.none
|
||||
: translateGameColorToString(selectedColor!, context),
|
||||
onPressed: () async {
|
||||
final result = await Navigator.of(context).push<GameColor?>(
|
||||
adaptivePageRoute(
|
||||
builder: (context) =>
|
||||
ChooseColorView(initialColor: selectedColor),
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
selectedColor = result;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
Container(
|
||||
margin: CustomTheme.tileMargin,
|
||||
child: TextInputField(
|
||||
controller: _descriptionController,
|
||||
hintText: loc.description,
|
||||
minLines: 6,
|
||||
maxLines: 6,
|
||||
maxLength: Constants.MAX_GAME_DESCRIPTION_LENGTH,
|
||||
showCounterText: true,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: CustomWidthButton(
|
||||
text: isEditing ? loc.edit_game : loc.create_game,
|
||||
sizeRelativeToWidth: 1,
|
||||
buttonType: ButtonType.primary,
|
||||
onPressed:
|
||||
_gameNameController.text.trim().isNotEmpty &&
|
||||
selectedRulesetIndex != -1 &&
|
||||
selectedColor != null
|
||||
? () async {
|
||||
Game newGame = Game(
|
||||
name: _gameNameController.text.trim(),
|
||||
description: _descriptionController.text.trim(),
|
||||
ruleset: selectedRuleset!,
|
||||
color: selectedColor!,
|
||||
);
|
||||
if (isEditing) {
|
||||
await handleGameUpdate(newGame);
|
||||
} else {
|
||||
await handleGameCreation(newGame);
|
||||
}
|
||||
widget.onGameChanged.call();
|
||||
if (context.mounted) {
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop((game: newGame, delete: false));
|
||||
}
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Handles updating an existing game in the database.
|
||||
///
|
||||
/// [newGame] The updated game object.
|
||||
Future<void> handleGameUpdate(Game newGame) async {
|
||||
final oldGame = widget.gameToEdit!;
|
||||
|
||||
if (oldGame.name != newGame.name) {
|
||||
await db.gameDao.updateGameName(
|
||||
gameId: oldGame.id,
|
||||
newName: newGame.name,
|
||||
);
|
||||
}
|
||||
|
||||
if (oldGame.description != newGame.description) {
|
||||
await db.gameDao.updateGameDescription(
|
||||
gameId: oldGame.id,
|
||||
newDescription: newGame.description,
|
||||
);
|
||||
}
|
||||
|
||||
if (oldGame.ruleset != newGame.ruleset) {
|
||||
await db.gameDao.updateGameRuleset(
|
||||
gameId: oldGame.id,
|
||||
newRuleset: newGame.ruleset,
|
||||
);
|
||||
}
|
||||
|
||||
if (oldGame.color != newGame.color) {
|
||||
await db.gameDao.updateGameColor(
|
||||
gameId: oldGame.id,
|
||||
newColor: newGame.color,
|
||||
);
|
||||
}
|
||||
|
||||
if (oldGame.icon != newGame.icon) {
|
||||
await db.gameDao.updateGameIcon(
|
||||
gameId: oldGame.id,
|
||||
newIcon: newGame.icon,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles creating a new game in the database.
|
||||
///
|
||||
/// [newGame] The game object to be created.
|
||||
Future<void> handleGameCreation(Game newGame) async {
|
||||
await db.gameDao.addGame(game: newGame);
|
||||
}
|
||||
|
||||
/// Displays a snackbar with the given message and optional action.
|
||||
///
|
||||
/// [message] The message to display in the snackbar.
|
||||
void showSnackbar({required String message}) {
|
||||
final messenger = _scaffoldMessengerKey.currentState;
|
||||
if (messenger != null) {
|
||||
messenger.hideCurrentSnackBar();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message, style: const TextStyle(color: Colors.white)),
|
||||
backgroundColor: CustomTheme.boxColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/create_match_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/match_result_view.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/animated_dialog_button.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||
import 'package:tallee/presentation/widgets/colored_icon_container.dart';
|
||||
import 'package:tallee/presentation/widgets/custom_alert_dialog.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/info_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/text_icon_tile.dart';
|
||||
|
||||
class MatchDetailView extends StatefulWidget {
|
||||
/// A view that displays the profile of a match
|
||||
/// - [match]: The match to display
|
||||
/// - [onMatchUpdate]: Callback to refresh the match list
|
||||
const MatchDetailView({
|
||||
super.key,
|
||||
required this.match,
|
||||
required this.onMatchUpdate,
|
||||
});
|
||||
|
||||
/// The match to display
|
||||
final Match match;
|
||||
|
||||
/// Callback to refresh the match list
|
||||
final VoidCallback onMatchUpdate;
|
||||
|
||||
@override
|
||||
State<MatchDetailView> createState() => _MatchDetailViewState();
|
||||
}
|
||||
|
||||
class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
late final AppDatabase db;
|
||||
|
||||
late Match match;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
match = widget.match;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
appBar: AppBar(
|
||||
title: Text(loc.match_profile),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => CustomAlertDialog(
|
||||
title: '${loc.delete_match}?',
|
||||
content: loc.this_cannot_be_undone,
|
||||
actions: [
|
||||
AnimatedDialogButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: Text(
|
||||
loc.cancel,
|
||||
style: const TextStyle(color: CustomTheme.textColor),
|
||||
),
|
||||
),
|
||||
AnimatedDialogButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: Text(
|
||||
loc.delete,
|
||||
style: const TextStyle(
|
||||
color: CustomTheme.secondaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
).then((confirmed) async {
|
||||
if (confirmed! && context.mounted) {
|
||||
await db.matchDao.deleteMatch(matchId: match.id);
|
||||
if (!context.mounted) return;
|
||||
Navigator.pop(context);
|
||||
widget.onMatchUpdate.call();
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
ListView(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 12,
|
||||
right: 12,
|
||||
top: 20,
|
||||
bottom: 100,
|
||||
),
|
||||
children: [
|
||||
const Center(
|
||||
child: ColoredIconContainer(
|
||||
icon: Icons.sports_esports,
|
||||
containerSize: 55,
|
||||
iconSize: 38,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
match.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 28,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: CustomTheme.textColor,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Text(
|
||||
'${loc.created_on} ${DateFormat.yMMMd(Localizations.localeOf(context).toString()).format(match.createdAt)}',
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: CustomTheme.textColor,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (match.group != null) ...[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.group),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'${match.group!.name}${getExtraPlayerCount(match)}',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
InfoTile(
|
||||
title: loc.players,
|
||||
icon: Icons.people,
|
||||
horizontalAlignment: CrossAxisAlignment.start,
|
||||
content: Wrap(
|
||||
alignment: WrapAlignment.start,
|
||||
crossAxisAlignment: WrapCrossAlignment.start,
|
||||
spacing: 12,
|
||||
runSpacing: 8,
|
||||
children: match.players.map((player) {
|
||||
return TextIconTile(
|
||||
text: player.name,
|
||||
iconEnabled: false,
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
InfoTile(
|
||||
title: loc.results,
|
||||
icon: Icons.emoji_events,
|
||||
content: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 4,
|
||||
horizontal: 8,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
/// TODO: Implement different ruleset results display
|
||||
if (match.winner != null) ...[
|
||||
Text(
|
||||
loc.winner,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: CustomTheme.textColor,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
match.winner!.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: CustomTheme.primaryColor,
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
Text(
|
||||
loc.no_results_entered_yet,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: CustomTheme.textColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Positioned(
|
||||
bottom: MediaQuery.paddingOf(context).bottom,
|
||||
child: Row(
|
||||
children: [
|
||||
MainMenuButton(
|
||||
icon: Icons.edit,
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (context) => CreateMatchView(
|
||||
matchToEdit: match,
|
||||
onMatchUpdated: onMatchUpdated,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
MainMenuButton(
|
||||
text: loc.enter_results,
|
||||
icon: Icons.emoji_events,
|
||||
onPressed: () async {
|
||||
match.winner = await Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (context) => MatchResultView(
|
||||
match: match,
|
||||
onWinnerChanged: () {
|
||||
widget.onMatchUpdate.call();
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Callback for when the match is updated in the edit view,
|
||||
/// updates the match in this view
|
||||
void onMatchUpdated(Match editedMatch) {
|
||||
setState(() {
|
||||
match = editedMatch;
|
||||
});
|
||||
widget.onMatchUpdate.call();
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,10 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
@override
|
||||
void initState() {
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
allPlayers = getAllPlayers(widget.match);
|
||||
|
||||
allPlayers = widget.match.players;
|
||||
allPlayers.sort((a, b) => a.name.compareTo(b.name));
|
||||
|
||||
if (widget.match.winner != null) {
|
||||
_selectedPlayer = allPlayers.firstWhere(
|
||||
(p) => p.id == widget.match.winner!.id,
|
||||
@@ -54,7 +57,7 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
icon: const Icon(Icons.close),
|
||||
onPressed: () {
|
||||
widget.onWinnerChanged?.call();
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pop(_selectedPlayer);
|
||||
},
|
||||
),
|
||||
title: Text(widget.match.name),
|
||||
@@ -74,7 +77,7 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.boxColor,
|
||||
border: Border.all(color: CustomTheme.boxBorder),
|
||||
border: Border.all(color: CustomTheme.boxBorderColor),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
@@ -145,21 +148,4 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
}
|
||||
widget.onWinnerChanged?.call();
|
||||
}
|
||||
|
||||
/// Retrieves all players associated with the given [match].
|
||||
/// This includes players directly assigned to the match
|
||||
/// as well as members of the group (if any).
|
||||
/// The returned list is sorted alphabetically by player name.
|
||||
List<Player> getAllPlayers(Match match) {
|
||||
List<Player> players = [];
|
||||
|
||||
if (match.group == null) {
|
||||
players = [...match.players];
|
||||
} else {
|
||||
players = [...match.players, ...match.group!.members];
|
||||
}
|
||||
|
||||
players.sort((a, b) => a.name.compareTo(b.name));
|
||||
return players;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:core' hide Match;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttericon/rpg_awesome_icons.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@@ -14,14 +12,14 @@ import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/create_match_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/match_result_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/match_detail_view.dart';
|
||||
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/match_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/top_centered_message.dart';
|
||||
|
||||
class MatchView extends StatefulWidget {
|
||||
/// A view that displays a list of matches
|
||||
/// A view that displays a list of matches.
|
||||
const MatchView({super.key});
|
||||
|
||||
@override
|
||||
@@ -29,16 +27,24 @@ class MatchView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MatchViewState extends State<MatchView> {
|
||||
/// Database instance used to access match data.
|
||||
late final AppDatabase db;
|
||||
|
||||
/// Indicates whether matches are currently being loaded.
|
||||
bool isLoading = true;
|
||||
|
||||
/// Loaded matches from the database,
|
||||
/// initially filled with skeleton matches
|
||||
/// initially filled with skeleton matches.
|
||||
List<Match> matches = List.filled(
|
||||
4,
|
||||
Match(
|
||||
name: 'Skeleton match name',
|
||||
game: Game(name: '', ruleset: Ruleset.singleWinner, description: '', color: GameColor.blue, icon: ''),
|
||||
game: Game(
|
||||
name: '',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: '',
|
||||
color: GameColor.blue,
|
||||
),
|
||||
group: Group(
|
||||
name: 'Group name',
|
||||
description: '',
|
||||
@@ -54,7 +60,7 @@ class _MatchViewState extends State<MatchView> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
loadGames();
|
||||
loadMatches();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -94,10 +100,9 @@ class _MatchViewState extends State<MatchView> {
|
||||
Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (context) => MatchResultView(
|
||||
builder: (context) => MatchDetailView(
|
||||
match: matches[index],
|
||||
onWinnerChanged: loadGames,
|
||||
onMatchUpdate: loadMatches,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -120,7 +125,7 @@ class _MatchViewState extends State<MatchView> {
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) =>
|
||||
CreateMatchView(onWinnerChanged: loadGames),
|
||||
CreateMatchView(onWinnerChanged: loadMatches),
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -131,8 +136,9 @@ class _MatchViewState extends State<MatchView> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Loads the games from the database and sorts them by creation date.
|
||||
void loadGames() {
|
||||
/// Loads the matches from the database and sorts them by creation date.
|
||||
void loadMatches() {
|
||||
isLoading = true;
|
||||
Future.wait([
|
||||
db.matchDao.getAllMatches(),
|
||||
Future.delayed(Constants.MINIMUM_SKELETON_DURATION),
|
||||
@@ -140,7 +146,7 @@ class _MatchViewState extends State<MatchView> {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
final loadedMatches = results[0] as List<Match>;
|
||||
matches = loadedMatches
|
||||
matches = [...loadedMatches]
|
||||
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
isLoading = false;
|
||||
});
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -31,6 +31,7 @@ class _SettingsViewState extends State<SettingsView> {
|
||||
version: 'n.A.',
|
||||
buildNumber: 'n.A.',
|
||||
);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
@@ -47,10 +47,7 @@ class _AppSkeletonState extends State<AppSkeleton> {
|
||||
: (Widget? currentChild, List<Widget> previousChildren) {
|
||||
return Stack(
|
||||
alignment: Alignment.topCenter,
|
||||
children: [
|
||||
...previousChildren,
|
||||
if (currentChild != null) currentChild,
|
||||
],
|
||||
children: [...previousChildren, ?currentChild],
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -2,25 +2,25 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class MainMenuButton extends StatefulWidget {
|
||||
/// A button for the main menu with an optional icon and a press animation.
|
||||
/// - [text]: The text of the button.
|
||||
/// - [icon]: The icon of the button.
|
||||
/// - [onPressed]: The callback to be invoked when the button is pressed.
|
||||
/// - [icon]: The icon of the button.
|
||||
/// - [text]: The text of the button.
|
||||
const MainMenuButton({
|
||||
super.key,
|
||||
required this.text,
|
||||
this.icon,
|
||||
required this.onPressed,
|
||||
required this.icon,
|
||||
this.text,
|
||||
});
|
||||
|
||||
/// The text of the button.
|
||||
final String text;
|
||||
|
||||
/// The icon of the button.
|
||||
final IconData? icon;
|
||||
|
||||
/// The callback to be invoked when the button is pressed.
|
||||
final void Function() onPressed;
|
||||
|
||||
/// The icon of the button.
|
||||
final IconData icon;
|
||||
|
||||
/// The text of the button.
|
||||
final String? text;
|
||||
|
||||
@override
|
||||
State<MainMenuButton> createState() => _MainMenuButtonState();
|
||||
}
|
||||
@@ -71,18 +71,18 @@ class _MainMenuButtonState extends State<MainMenuButton>
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
if (widget.icon != null) ...[
|
||||
Icon(widget.icon, size: 26, color: Colors.black),
|
||||
Icon(widget.icon, size: 26, color: Colors.black),
|
||||
if (widget.text != null) ...[
|
||||
const SizedBox(width: 7),
|
||||
],
|
||||
Text(
|
||||
widget.text,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
Text(
|
||||
widget.text!,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -32,7 +32,7 @@ class CustomAlertDialog extends StatelessWidget {
|
||||
actionsAlignment: MainAxisAlignment.spaceAround,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: CustomTheme.standardBorderRadiusAll,
|
||||
side: const BorderSide(color: CustomTheme.boxBorder),
|
||||
side: const BorderSide(color: CustomTheme.boxBorderColor),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -87,19 +87,29 @@ class _NavbarItemState extends State<NavbarItem>
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
ScaleTransition(
|
||||
scale: widget.isSelected
|
||||
? _scaleAnimation
|
||||
: const AlwaysStoppedAnimation(1.0),
|
||||
child: Icon(
|
||||
widget.icon,
|
||||
AnimatedContainer(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: widget.isSelected
|
||||
? CustomTheme.navBarItemSelectedColor
|
||||
: CustomTheme.navBarItemUnselectedColor,
|
||||
size: 32,
|
||||
? CustomTheme.primaryColor.withAlpha(50)
|
||||
: Colors.transparent,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(15)),
|
||||
),
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: ScaleTransition(
|
||||
scale: widget.isSelected
|
||||
? _scaleAnimation
|
||||
: const AlwaysStoppedAnimation(1.0),
|
||||
child: Icon(
|
||||
widget.icon,
|
||||
color: widget.isSelected
|
||||
? CustomTheme.navBarItemSelectedColor
|
||||
: CustomTheme.navBarItemUnselectedColor,
|
||||
size: 32,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
widget.label,
|
||||
style: TextStyle(
|
||||
|
||||
@@ -70,6 +70,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
||||
super.initState();
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
suggestedPlayers = skeletonData;
|
||||
selectedPlayers = widget.initialSelectedPlayers ?? [];
|
||||
loadPlayerList();
|
||||
}
|
||||
|
||||
@@ -100,7 +101,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
||||
if (value.isEmpty) {
|
||||
// If the search is empty, it shows all unselected players.
|
||||
suggestedPlayers = allPlayers.where((player) {
|
||||
return !selectedPlayers.contains(player);
|
||||
return !selectedPlayers.any((p) => p.id == player.id);
|
||||
}).toList();
|
||||
} else {
|
||||
// If there is input, it filters by name match (case-insensitive) and ensures
|
||||
@@ -109,8 +110,8 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
||||
final bool nameMatches = player.name.toLowerCase().contains(
|
||||
value.toLowerCase(),
|
||||
);
|
||||
final bool isNotSelected = !selectedPlayers.contains(
|
||||
player,
|
||||
final bool isNotSelected = !selectedPlayers.any(
|
||||
(p) => p.id == player.id,
|
||||
);
|
||||
return nameMatches && isNotSelected;
|
||||
}).toList();
|
||||
@@ -126,46 +127,49 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
||||
const SizedBox(height: 10),
|
||||
SizedBox(
|
||||
height: 50,
|
||||
child: selectedPlayers.isEmpty
|
||||
? Center(child: Text(loc.no_players_selected))
|
||||
: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
for (var player in selectedPlayers)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: TextIconTile(
|
||||
text: player.name,
|
||||
onIconTap: () {
|
||||
setState(() {
|
||||
// Removes the player from the selection and notifies the parent.
|
||||
selectedPlayers.remove(player);
|
||||
widget.onChanged([...selectedPlayers]);
|
||||
child: AppSkeleton(
|
||||
enabled: isLoading,
|
||||
child: selectedPlayers.isEmpty
|
||||
? Center(child: Text(loc.no_players_selected))
|
||||
: SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: [
|
||||
for (var player in selectedPlayers)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: TextIconTile(
|
||||
text: player.name,
|
||||
onIconTap: () {
|
||||
setState(() {
|
||||
// Removes the player from the selection and notifies the parent.
|
||||
selectedPlayers.remove(player);
|
||||
widget.onChanged([...selectedPlayers]);
|
||||
|
||||
// Get the current search query
|
||||
final currentSearch = _searchBarController
|
||||
.text
|
||||
.toLowerCase();
|
||||
// Get the current search query
|
||||
final currentSearch = _searchBarController
|
||||
.text
|
||||
.toLowerCase();
|
||||
|
||||
// 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),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
// 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),
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
@@ -222,35 +226,53 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
||||
db.playerDao.getAllPlayers(),
|
||||
Future.delayed(Constants.MINIMUM_SKELETON_DURATION),
|
||||
]).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();
|
||||
}
|
||||
_allPlayersFuture.then((loadedPlayers) {
|
||||
if (!mounted) return;
|
||||
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];
|
||||
if (widget.initialSelectedPlayers != null) {
|
||||
// Excludes already selected players from the suggested players list.
|
||||
suggestedPlayers = loadedPlayers
|
||||
.where(
|
||||
(p) => !widget.initialSelectedPlayers!.any(
|
||||
(ip) => ip.id == p.id,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
// Ensures that only players available for selection are pre-selected.
|
||||
selectedPlayers = widget.initialSelectedPlayers!
|
||||
.where(
|
||||
(p) => allPlayers.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];
|
||||
// If no initial selection, all loaded players are suggested.
|
||||
suggestedPlayers = [...loadedPlayers];
|
||||
}
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Adds a new player to the database from the search bar input.
|
||||
|
||||
@@ -69,7 +69,6 @@ class CustomSearchBar extends StatelessWidget {
|
||||
constraints ?? const BoxConstraints(maxHeight: 45, minHeight: 45),
|
||||
hintText: hintText,
|
||||
onChanged: onChanged,
|
||||
hintStyle: WidgetStateProperty.all(const TextStyle(fontSize: 16)),
|
||||
leading: const Icon(Icons.search),
|
||||
trailing: [
|
||||
Visibility(
|
||||
@@ -88,7 +87,7 @@ class CustomSearchBar extends StatelessWidget {
|
||||
],
|
||||
backgroundColor: WidgetStateProperty.all(CustomTheme.boxColor),
|
||||
side: WidgetStateProperty.all(
|
||||
const BorderSide(color: CustomTheme.boxBorder),
|
||||
const BorderSide(color: CustomTheme.boxBorderColor),
|
||||
),
|
||||
shape: WidgetStateProperty.all(
|
||||
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
|
||||
@@ -8,12 +8,18 @@ class TextInputField extends StatelessWidget {
|
||||
/// - [onChanged]: Optional callback invoked when the text in the field changes.
|
||||
/// - [hintText]: The hint text displayed in the text input field when it is empty
|
||||
/// - [maxLength]: Optional parameter for maximum length of the input text.
|
||||
/// - [maxLines]: The maximum number of lines for the text input field. Defaults to 1.
|
||||
/// - [minLines]: The minimum number of lines for the text input field. Defaults to 1.
|
||||
/// - [showCounterText]: Whether to show the counter text in the text input field. Defaults to false.
|
||||
const TextInputField({
|
||||
super.key,
|
||||
required this.controller,
|
||||
required this.hintText,
|
||||
this.onChanged,
|
||||
this.maxLength,
|
||||
this.maxLines = 1,
|
||||
this.minLines = 1,
|
||||
this.showCounterText = false,
|
||||
});
|
||||
|
||||
/// The controller for the text input field.
|
||||
@@ -28,6 +34,15 @@ class TextInputField extends StatelessWidget {
|
||||
/// Optional parameter for maximum length of the input text.
|
||||
final int? maxLength;
|
||||
|
||||
/// The maximum number of lines for the text input field.
|
||||
final int? maxLines;
|
||||
|
||||
/// The minimum number of lines for the text input field.
|
||||
final int? minLines;
|
||||
|
||||
/// Whether to show the counter text in the text input field.
|
||||
final bool showCounterText;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return TextField(
|
||||
@@ -35,20 +50,21 @@ class TextInputField extends StatelessWidget {
|
||||
onChanged: onChanged,
|
||||
maxLength: maxLength,
|
||||
maxLengthEnforcement: MaxLengthEnforcement.truncateAfterCompositionEnds,
|
||||
maxLines: maxLines,
|
||||
minLines: minLines,
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: CustomTheme.boxColor,
|
||||
hintText: hintText,
|
||||
hintStyle: const TextStyle(fontSize: 18),
|
||||
// Hides the character counter
|
||||
counterText: '',
|
||||
counterText: showCounterText ? null : '',
|
||||
enabledBorder: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||
borderSide: BorderSide(color: CustomTheme.boxBorder),
|
||||
borderSide: BorderSide(color: CustomTheme.boxBorderColor),
|
||||
),
|
||||
focusedBorder: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||
borderSide: BorderSide(color: CustomTheme.boxBorder),
|
||||
borderSide: BorderSide(color: CustomTheme.boxBorderColor),
|
||||
),
|
||||
floatingLabelBehavior: FloatingLabelBehavior.never,
|
||||
),
|
||||
|
||||
@@ -31,16 +31,12 @@ class CustomRadioListTile<T> extends StatelessWidget {
|
||||
padding: const EdgeInsets.symmetric(horizontal: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.boxColor,
|
||||
border: Border.all(color: CustomTheme.boxBorder),
|
||||
border: Border.all(color: CustomTheme.boxBorderColor),
|
||||
borderRadius: CustomTheme.standardBorderRadiusAll,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Radio<T>(
|
||||
value: value,
|
||||
activeColor: CustomTheme.primaryColor,
|
||||
toggleable: true,
|
||||
),
|
||||
Radio<T>(value: value, toggleable: true),
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'dart:core' hide Match;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/text_icon_tile.dart';
|
||||
|
||||
@@ -38,18 +40,13 @@ class MatchTile extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MatchTileState extends State<MatchTile> {
|
||||
late final List<Player> _allPlayers;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_allPlayers = _getCombinedPlayers();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final group = widget.match.group;
|
||||
final winner = widget.match.winner;
|
||||
final match = widget.match;
|
||||
final group = match.group;
|
||||
final winner = match.winner;
|
||||
final players = [...match.players]
|
||||
..sort((a, b) => a.name.compareTo(b.name));
|
||||
final loc = AppLocalizations.of(context);
|
||||
|
||||
return GestureDetector(
|
||||
@@ -67,7 +64,7 @@ class _MatchTileState extends State<MatchTile> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
widget.match.name,
|
||||
match.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
@@ -76,7 +73,7 @@ class _MatchTileState extends State<MatchTile> {
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_formatDate(widget.match.createdAt, context),
|
||||
_formatDate(match.createdAt, context),
|
||||
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||
),
|
||||
],
|
||||
@@ -91,7 +88,7 @@ class _MatchTileState extends State<MatchTile> {
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${group.name} + ${widget.match.players.length}',
|
||||
'${match.group!.name}${getExtraPlayerCount(match)}',
|
||||
style: const TextStyle(fontSize: 14, color: Colors.grey),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@@ -106,7 +103,7 @@ class _MatchTileState extends State<MatchTile> {
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${widget.match.players.length} ${loc.players}',
|
||||
'${match.players.length} ${loc.players}',
|
||||
style: const TextStyle(fontSize: 14, color: Colors.grey),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
@@ -192,7 +189,7 @@ class _MatchTileState extends State<MatchTile> {
|
||||
const SizedBox(height: 12),
|
||||
],
|
||||
|
||||
if (_allPlayers.isNotEmpty && widget.compact == false) ...[
|
||||
if (players.isNotEmpty && widget.compact == false) ...[
|
||||
Text(
|
||||
loc.players,
|
||||
style: const TextStyle(
|
||||
@@ -205,7 +202,7 @@ class _MatchTileState extends State<MatchTile> {
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 6,
|
||||
children: _allPlayers.map((player) {
|
||||
children: players.map((player) {
|
||||
return TextIconTile(text: player.name, iconEnabled: false);
|
||||
}).toList(),
|
||||
),
|
||||
@@ -233,32 +230,4 @@ class _MatchTileState extends State<MatchTile> {
|
||||
return '${loc.created_on} ${DateFormat.yMMMd(Localizations.localeOf(context).toString()).format(dateTime)}';
|
||||
}
|
||||
}
|
||||
|
||||
/// Retrieves all unique players associated with the match,
|
||||
/// combining players from both the match and its group.
|
||||
List<Player> _getCombinedPlayers() {
|
||||
final allPlayers = <Player>[];
|
||||
final playerIds = <String>{};
|
||||
|
||||
// Add players from game.players
|
||||
for (var player in widget.match.players) {
|
||||
if (!playerIds.contains(player.id)) {
|
||||
allPlayers.add(player);
|
||||
playerIds.add(player.id);
|
||||
}
|
||||
}
|
||||
|
||||
// Add players from game.group.players
|
||||
if (widget.match.group?.members != null) {
|
||||
for (var player in widget.match.group!.members) {
|
||||
if (!playerIds.contains(player.id)) {
|
||||
allPlayers.add(player);
|
||||
playerIds.add(player.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allPlayers.sort((a, b) => a.name.compareTo(b.name));
|
||||
return allPlayers;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ class TitleDescriptionListTile extends StatelessWidget {
|
||||
/// - [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.
|
||||
/// - [onLongPress]: 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.
|
||||
@@ -13,7 +14,8 @@ class TitleDescriptionListTile extends StatelessWidget {
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.description,
|
||||
this.onPressed,
|
||||
this.onTap,
|
||||
this.onLongPress,
|
||||
this.isHighlighted = false,
|
||||
this.badgeText,
|
||||
this.badgeColor,
|
||||
@@ -26,7 +28,10 @@ class TitleDescriptionListTile extends StatelessWidget {
|
||||
final String description;
|
||||
|
||||
/// The callback invoked when the tile is tapped.
|
||||
final VoidCallback? onPressed;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
/// The callback invoked when the tile is long-pressed.
|
||||
final VoidCallback? onLongPress;
|
||||
|
||||
/// A boolean to determine if the tile should be highlighted.
|
||||
final bool isHighlighted;
|
||||
@@ -40,7 +45,8 @@ class TitleDescriptionListTile extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onPressed,
|
||||
onTap: onTap,
|
||||
onLongPress: onLongPress,
|
||||
child: AnimatedContainer(
|
||||
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
|
||||
|
||||
@@ -40,33 +40,39 @@ class DataTransferService {
|
||||
'players': players.map((p) => p.toJson()).toList(),
|
||||
'games': games.map((g) => g.toJson()).toList(),
|
||||
'groups': groups
|
||||
.map((g) => {
|
||||
'id': g.id,
|
||||
'name': g.name,
|
||||
'description': g.description,
|
||||
'createdAt': g.createdAt.toIso8601String(),
|
||||
'memberIds': (g.members).map((m) => m.id).toList(),
|
||||
})
|
||||
.map(
|
||||
(g) => {
|
||||
'id': g.id,
|
||||
'name': g.name,
|
||||
'description': g.description,
|
||||
'createdAt': g.createdAt.toIso8601String(),
|
||||
'memberIds': (g.members).map((m) => m.id).toList(),
|
||||
},
|
||||
)
|
||||
.toList(),
|
||||
'teams': teams
|
||||
.map((t) => {
|
||||
'id': t.id,
|
||||
'name': t.name,
|
||||
'createdAt': t.createdAt.toIso8601String(),
|
||||
'memberIds': (t.members).map((m) => m.id).toList(),
|
||||
})
|
||||
.map(
|
||||
(t) => {
|
||||
'id': t.id,
|
||||
'name': t.name,
|
||||
'createdAt': t.createdAt.toIso8601String(),
|
||||
'memberIds': (t.members).map((m) => m.id).toList(),
|
||||
},
|
||||
)
|
||||
.toList(),
|
||||
'matches': matches
|
||||
.map((m) => {
|
||||
'id': m.id,
|
||||
'name': m.name,
|
||||
'createdAt': m.createdAt.toIso8601String(),
|
||||
'endedAt': m.endedAt?.toIso8601String(),
|
||||
'gameId': m.game.id,
|
||||
'groupId': m.group?.id,
|
||||
'playerIds': m.players.map((p) => p.id).toList(),
|
||||
'notes': m.notes,
|
||||
})
|
||||
.map(
|
||||
(m) => {
|
||||
'id': m.id,
|
||||
'name': m.name,
|
||||
'createdAt': m.createdAt.toIso8601String(),
|
||||
'endedAt': m.endedAt?.toIso8601String(),
|
||||
'gameId': m.game.id,
|
||||
'groupId': m.group?.id,
|
||||
'playerIds': m.players.map((p) => p.id).toList(),
|
||||
'notes': m.notes,
|
||||
},
|
||||
)
|
||||
.toList(),
|
||||
};
|
||||
|
||||
@@ -79,9 +85,9 @@ class DataTransferService {
|
||||
/// [jsonString] The JSON string to be exported.
|
||||
/// [fileName] The desired name for the exported file (without extension).
|
||||
static Future<ExportResult> exportData(
|
||||
String jsonString,
|
||||
String fileName
|
||||
) async {
|
||||
String jsonString,
|
||||
String fileName,
|
||||
) async {
|
||||
try {
|
||||
final bytes = Uint8List.fromList(utf8.encode(jsonString));
|
||||
final path = await FilePicker.platform.saveFile(
|
||||
@@ -94,7 +100,6 @@ class DataTransferService {
|
||||
} else {
|
||||
return ExportResult.success;
|
||||
}
|
||||
|
||||
} catch (e, stack) {
|
||||
print('[exportData] $e');
|
||||
print(stack);
|
||||
@@ -122,13 +127,19 @@ class DataTransferService {
|
||||
final isValid = await _validateJsonSchema(jsonString);
|
||||
if (!isValid) return ImportResult.invalidSchema;
|
||||
|
||||
final Map<String, dynamic> decoded = json.decode(jsonString) as Map<String, dynamic>;
|
||||
final Map<String, dynamic> decoded =
|
||||
json.decode(jsonString) as Map<String, dynamic>;
|
||||
|
||||
final List<dynamic> playersJson = (decoded['players'] as List<dynamic>?) ?? [];
|
||||
final List<dynamic> gamesJson = (decoded['games'] as List<dynamic>?) ?? [];
|
||||
final List<dynamic> groupsJson = (decoded['groups'] as List<dynamic>?) ?? [];
|
||||
final List<dynamic> teamsJson = (decoded['teams'] as List<dynamic>?) ?? [];
|
||||
final List<dynamic> matchesJson = (decoded['matches'] as List<dynamic>?) ?? [];
|
||||
final List<dynamic> playersJson =
|
||||
(decoded['players'] as List<dynamic>?) ?? [];
|
||||
final List<dynamic> gamesJson =
|
||||
(decoded['games'] as List<dynamic>?) ?? [];
|
||||
final List<dynamic> groupsJson =
|
||||
(decoded['groups'] as List<dynamic>?) ?? [];
|
||||
final List<dynamic> teamsJson =
|
||||
(decoded['teams'] as List<dynamic>?) ?? [];
|
||||
final List<dynamic> matchesJson =
|
||||
(decoded['matches'] as List<dynamic>?) ?? [];
|
||||
|
||||
// Import Players
|
||||
final List<Player> importedPlayers = playersJson
|
||||
@@ -151,7 +162,8 @@ class DataTransferService {
|
||||
// Import 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 memberIds = (map['memberIds'] as List<dynamic>? ?? [])
|
||||
.cast<String>();
|
||||
|
||||
final members = memberIds
|
||||
.map((id) => playerById[id])
|
||||
@@ -174,7 +186,8 @@ class DataTransferService {
|
||||
// Import Teams
|
||||
final List<Team> importedTeams = teamsJson.map((t) {
|
||||
final map = t as Map<String, dynamic>;
|
||||
final memberIds = (map['memberIds'] as List<dynamic>? ?? []).cast<String>();
|
||||
final memberIds = (map['memberIds'] as List<dynamic>? ?? [])
|
||||
.cast<String>();
|
||||
|
||||
final members = memberIds
|
||||
.map((id) => playerById[id])
|
||||
@@ -195,8 +208,11 @@ class DataTransferService {
|
||||
|
||||
final String gameId = map['gameId'] as String;
|
||||
final String? groupId = map['groupId'] as String?;
|
||||
final List<String> playerIds = (map['playerIds'] as List<dynamic>? ?? []).cast<String>();
|
||||
final DateTime? endedAt = map['endedAt'] != null ? DateTime.parse(map['endedAt'] as String) : null;
|
||||
final List<String> playerIds =
|
||||
(map['playerIds'] as List<dynamic>? ?? []).cast<String>();
|
||||
final DateTime? endedAt = map['endedAt'] != null
|
||||
? DateTime.parse(map['endedAt'] as String)
|
||||
: null;
|
||||
|
||||
final game = gameById[gameId];
|
||||
final group = (groupId == null) ? null : groupById[groupId];
|
||||
@@ -208,7 +224,14 @@ class DataTransferService {
|
||||
return Match(
|
||||
id: map['id'] as String,
|
||||
name: map['name'] as String,
|
||||
game: game ?? Game(name: 'Unknown', ruleset: Ruleset.singleWinner, description: '', color: GameColor.blue, icon: ''),
|
||||
game:
|
||||
game ??
|
||||
Game(
|
||||
name: 'Unknown',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: '',
|
||||
color: GameColor.blue,
|
||||
),
|
||||
group: group,
|
||||
players: players,
|
||||
createdAt: DateTime.parse(map['createdAt'] as String),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name: tallee
|
||||
description: "Tracking App for Card Games"
|
||||
publish_to: 'none'
|
||||
version: 0.0.14+248
|
||||
version: 0.0.18+252
|
||||
|
||||
environment:
|
||||
sdk: ^3.8.1
|
||||
@@ -34,7 +34,7 @@ dev_dependencies:
|
||||
build_runner: ^2.5.4
|
||||
dart_pubspec_licenses: ^3.0.14
|
||||
drift_dev: ^2.27.0
|
||||
flutter_lints: ^5.0.0
|
||||
flutter_lints: ^6.0.0
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/drift.dart' hide isNotNull;
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/data/dto/group.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
@@ -51,7 +51,12 @@ void main() {
|
||||
description: '',
|
||||
members: [testPlayer4, testPlayer5],
|
||||
);
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: GameColor.blue, icon: '');
|
||||
testGame = Game(
|
||||
name: 'Test Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A test game',
|
||||
color: GameColor.blue,
|
||||
);
|
||||
testMatch1 = Match(
|
||||
name: 'First Test Match',
|
||||
game: testGame,
|
||||
@@ -99,7 +104,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Match Tests', () {
|
||||
|
||||
// Verifies that a single match can be added and retrieved with all fields, group, and players intact.
|
||||
test('Adding and fetching single match works correctly', () async {
|
||||
await database.matchDao.addMatch(match: testMatch1);
|
||||
@@ -127,10 +131,7 @@ void main() {
|
||||
for (int i = 0; i < testMatch1.players.length; i++) {
|
||||
expect(result.players[i].id, testMatch1.players[i].id);
|
||||
expect(result.players[i].name, testMatch1.players[i].name);
|
||||
expect(
|
||||
result.players[i].createdAt,
|
||||
testMatch1.players[i].createdAt,
|
||||
);
|
||||
expect(result.players[i].createdAt, testMatch1.players[i].createdAt);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -191,10 +192,7 @@ void main() {
|
||||
for (int i = 0; i < testMatch.players.length; i++) {
|
||||
expect(match.players[i].id, testMatch.players[i].id);
|
||||
expect(match.players[i].name, testMatch.players[i].name);
|
||||
expect(
|
||||
match.players[i].createdAt,
|
||||
testMatch.players[i].createdAt,
|
||||
);
|
||||
expect(match.players[i].createdAt, testMatch.players[i].createdAt);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -282,5 +280,31 @@ void main() {
|
||||
);
|
||||
expect(fetchedMatch.name, newName);
|
||||
});
|
||||
|
||||
test('Fetching a winner works correctly', () async {
|
||||
await database.matchDao.addMatch(match: testMatch1);
|
||||
|
||||
var fetchedMatch = await database.matchDao.getMatchById(
|
||||
matchId: testMatch1.id,
|
||||
);
|
||||
|
||||
expect(fetchedMatch.winner, isNotNull);
|
||||
expect(fetchedMatch.winner!.id, testPlayer4.id);
|
||||
});
|
||||
|
||||
test('Setting a winner works correctly', () async {
|
||||
await database.matchDao.addMatch(match: testMatch1);
|
||||
|
||||
await database.matchDao.setWinner(
|
||||
matchId: testMatch1.id,
|
||||
winnerId: testPlayer5.id,
|
||||
);
|
||||
|
||||
final fetchedMatch = await database.matchDao.getMatchById(
|
||||
matchId: testMatch1.id,
|
||||
);
|
||||
expect(fetchedMatch.winner, isNotNull);
|
||||
expect(fetchedMatch.winner!.id, testPlayer5.id);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@ import 'package:clock/clock.dart';
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/data/dto/team.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
@@ -37,20 +37,21 @@ void main() {
|
||||
testPlayer2 = Player(name: 'Bob', description: '');
|
||||
testPlayer3 = Player(name: 'Charlie', description: '');
|
||||
testPlayer4 = Player(name: 'Diana', description: '');
|
||||
testTeam1 = Team(
|
||||
name: 'Team Alpha',
|
||||
members: [testPlayer1, testPlayer2],
|
||||
testTeam1 = Team(name: 'Team Alpha', members: [testPlayer1, testPlayer2]);
|
||||
testTeam2 = Team(name: 'Team Beta', members: [testPlayer3, testPlayer4]);
|
||||
testTeam3 = Team(name: 'Team Gamma', members: [testPlayer1, testPlayer3]);
|
||||
testGame1 = Game(
|
||||
name: 'Game 1',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'Test game 1',
|
||||
color: GameColor.blue,
|
||||
);
|
||||
testTeam2 = Team(
|
||||
name: 'Team Beta',
|
||||
members: [testPlayer3, testPlayer4],
|
||||
testGame2 = Game(
|
||||
name: 'Game 2',
|
||||
ruleset: Ruleset.highestScore,
|
||||
description: 'Test game 2',
|
||||
color: GameColor.red,
|
||||
);
|
||||
testTeam3 = Team(
|
||||
name: 'Team Gamma',
|
||||
members: [testPlayer1, testPlayer3],
|
||||
);
|
||||
testGame1 = Game(name: 'Game 1', ruleset: Ruleset.singleWinner, description: 'Test game 1', color: GameColor.blue, icon: '');
|
||||
testGame2 = Game(name: 'Game 2', ruleset: Ruleset.highestScore, description: 'Test game 2', color: GameColor.red, icon: '');
|
||||
});
|
||||
|
||||
await database.playerDao.addPlayersAsList(
|
||||
@@ -65,7 +66,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Team Tests', () {
|
||||
|
||||
// Verifies that a single team can be added and retrieved with all fields intact.
|
||||
test('Adding and fetching a single team works correctly', () async {
|
||||
final added = await database.teamDao.addTeam(team: testTeam1);
|
||||
@@ -285,10 +285,7 @@ void main() {
|
||||
test('Updating team name to empty string works', () async {
|
||||
await database.teamDao.addTeam(team: testTeam1);
|
||||
|
||||
await database.teamDao.updateTeamName(
|
||||
teamId: testTeam1.id,
|
||||
newName: '',
|
||||
);
|
||||
await database.teamDao.updateTeamName(teamId: testTeam1.id, newName: '');
|
||||
|
||||
final updatedTeam = await database.teamDao.getTeamById(
|
||||
teamId: testTeam1.id,
|
||||
@@ -350,9 +347,7 @@ void main() {
|
||||
await database.matchDao.addMatch(match: match2);
|
||||
|
||||
// Add teams to database
|
||||
await database.teamDao.addTeamsAsList(
|
||||
teams: [testTeam1, testTeam3],
|
||||
);
|
||||
await database.teamDao.addTeamsAsList(teams: [testTeam1, testTeam3]);
|
||||
|
||||
// Associate players with teams through match1
|
||||
// testTeam1: player1, player2
|
||||
@@ -420,10 +415,11 @@ void main() {
|
||||
final allTeams = await database.teamDao.getAllTeams();
|
||||
|
||||
expect(allTeams.length, 3);
|
||||
expect(
|
||||
allTeams.map((t) => t.id).toSet(),
|
||||
{testTeam1.id, testTeam2.id, testTeam3.id},
|
||||
);
|
||||
expect(allTeams.map((t) => t.id).toSet(), {
|
||||
testTeam1.id,
|
||||
testTeam2.id,
|
||||
testTeam3.id,
|
||||
});
|
||||
});
|
||||
|
||||
// Verifies that teamExists returns false for deleted teams.
|
||||
@@ -462,9 +458,7 @@ void main() {
|
||||
|
||||
// Verifies that addTeam after deleteAllTeams works correctly.
|
||||
test('Adding team after deleteAllTeams works correctly', () async {
|
||||
await database.teamDao.addTeamsAsList(
|
||||
teams: [testTeam1, testTeam2],
|
||||
);
|
||||
await database.teamDao.addTeamsAsList(teams: [testTeam1, testTeam2]);
|
||||
expect(await database.teamDao.getTeamCount(), 2);
|
||||
|
||||
await database.teamDao.deleteAllTeams();
|
||||
|
||||
@@ -44,7 +44,6 @@ void main() {
|
||||
ruleset: Ruleset.highestScore,
|
||||
description: 'A board game about real estate',
|
||||
color: GameColor.orange,
|
||||
icon: '',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -54,7 +53,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Game Tests', () {
|
||||
|
||||
// Verifies that getAllGames returns an empty list when the database has no games.
|
||||
test('getAllGames returns empty list when no games exist', () async {
|
||||
final allGames = await database.gameDao.getAllGames();
|
||||
@@ -106,7 +104,7 @@ void main() {
|
||||
// Verifies that getGameById throws a StateError when the game doesn't exist.
|
||||
test('getGameById throws exception for non-existent game', () async {
|
||||
expect(
|
||||
() => database.gameDao.getGameById(gameId: 'non-existent-id'),
|
||||
() => database.gameDao.getGameById(gameId: 'non-existent-id'),
|
||||
throwsA(isA<StateError>()),
|
||||
);
|
||||
});
|
||||
@@ -134,7 +132,12 @@ void main() {
|
||||
|
||||
// Verifies that a game with empty optional fields can be added and retrieved.
|
||||
test('addGame handles game with null optional fields', () async {
|
||||
final gameWithNulls = Game(name: 'Simple Game', ruleset: Ruleset.lowestScore, description: 'A simple game', color: GameColor.green, icon: '');
|
||||
final gameWithNulls = Game(
|
||||
name: 'Simple Game',
|
||||
ruleset: Ruleset.lowestScore,
|
||||
description: 'A simple game',
|
||||
color: GameColor.green,
|
||||
);
|
||||
final result = await database.gameDao.addGame(game: gameWithNulls);
|
||||
expect(result, true);
|
||||
|
||||
@@ -419,9 +422,7 @@ void main() {
|
||||
|
||||
// Verifies that getGameCount updates correctly after deleting a game.
|
||||
test('getGameCount updates correctly after deletion', () async {
|
||||
await database.gameDao.addGamesAsList(
|
||||
games: [testGame1, testGame2],
|
||||
);
|
||||
await database.gameDao.addGamesAsList(games: [testGame1, testGame2]);
|
||||
|
||||
final countBefore = await database.gameDao.getGameCount();
|
||||
expect(countBefore, 2);
|
||||
@@ -461,7 +462,6 @@ void main() {
|
||||
ruleset: Ruleset.multipleWinners,
|
||||
description: 'Description with émojis 🎮🎲',
|
||||
color: GameColor.purple,
|
||||
icon: '',
|
||||
);
|
||||
await database.gameDao.addGame(game: specialGame);
|
||||
|
||||
@@ -478,7 +478,6 @@ void main() {
|
||||
name: '',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: '',
|
||||
icon: '',
|
||||
color: GameColor.red,
|
||||
);
|
||||
await database.gameDao.addGame(game: emptyGame);
|
||||
@@ -500,7 +499,6 @@ void main() {
|
||||
description: longString,
|
||||
ruleset: Ruleset.multipleWinners,
|
||||
color: GameColor.yellow,
|
||||
icon: '',
|
||||
);
|
||||
await database.gameDao.addGame(game: longGame);
|
||||
|
||||
|
||||
@@ -48,7 +48,12 @@ void main() {
|
||||
description: '',
|
||||
members: [testPlayer1, testPlayer2, testPlayer3],
|
||||
);
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: GameColor.blue, icon: '');
|
||||
testGame = Game(
|
||||
name: 'Test Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A test game',
|
||||
color: GameColor.blue,
|
||||
);
|
||||
testMatchOnlyGroup = Match(
|
||||
name: 'Test Match with Group',
|
||||
game: testGame,
|
||||
@@ -61,14 +66,8 @@ void main() {
|
||||
players: [testPlayer4, testPlayer5, testPlayer6],
|
||||
notes: '',
|
||||
);
|
||||
testTeam1 = Team(
|
||||
name: 'Team Alpha',
|
||||
members: [testPlayer1, testPlayer2],
|
||||
);
|
||||
testTeam2 = Team(
|
||||
name: 'Team Beta',
|
||||
members: [testPlayer3, testPlayer4],
|
||||
);
|
||||
testTeam1 = Team(name: 'Team Alpha', members: [testPlayer1, testPlayer2]);
|
||||
testTeam2 = Team(name: 'Team Beta', members: [testPlayer3, testPlayer4]);
|
||||
});
|
||||
await database.playerDao.addPlayersAsList(
|
||||
players: [
|
||||
@@ -88,7 +87,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Player-Match Tests', () {
|
||||
|
||||
// Verifies that matchHasPlayers returns false initially and true after adding a player.
|
||||
test('Match has player works correctly', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
@@ -153,26 +151,23 @@ void main() {
|
||||
);
|
||||
expect(result.players.length, testMatchOnlyPlayers.players.length - 1);
|
||||
|
||||
final playerExists = result.players.any(
|
||||
(p) => p.id == playerToRemove.id,
|
||||
);
|
||||
final playerExists = result.players.any((p) => p.id == playerToRemove.id);
|
||||
expect(playerExists, false);
|
||||
});
|
||||
|
||||
// Verifies that getPlayersOfMatch returns all players of a match with correct data.
|
||||
test('Retrieving players of a match works correctly', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||
final players = await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
) ?? [];
|
||||
final players =
|
||||
await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
) ??
|
||||
[];
|
||||
|
||||
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,
|
||||
);
|
||||
expect(players[i].createdAt, testMatchOnlyPlayers.players[i].createdAt);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -223,10 +218,20 @@ void main() {
|
||||
// Verifies that the same player can be added to multiple different matches.
|
||||
test(
|
||||
'Adding the same player to separate matches works correctly',
|
||||
() async {
|
||||
() async {
|
||||
final playersList = [testPlayer1, testPlayer2, testPlayer3];
|
||||
final match1 = Match(name: 'Match 1', game: testGame, players: playersList, notes: '');
|
||||
final match2 = Match(name: 'Match 2', game: testGame, players: playersList, notes: '');
|
||||
final match1 = Match(
|
||||
name: 'Match 1',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
final match2 = Match(
|
||||
name: 'Match 2',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
|
||||
await Future.wait([
|
||||
database.matchDao.addMatch(match: match1),
|
||||
@@ -299,16 +304,19 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that getPlayerScore returns null for non-existent player-match combination.
|
||||
test('getPlayerScore returns null for non-existent player in match', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
test(
|
||||
'getPlayerScore returns null for non-existent player in match',
|
||||
() async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
|
||||
final score = await database.playerMatchDao.getPlayerScore(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
);
|
||||
final score = await database.playerMatchDao.getPlayerScore(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
);
|
||||
|
||||
expect(score, isNull);
|
||||
});
|
||||
expect(score, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that updatePlayerScore updates the score correctly.
|
||||
test('updatePlayerScore updates score correctly', () async {
|
||||
@@ -331,17 +339,20 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updatePlayerScore returns false for non-existent player-match.
|
||||
test('updatePlayerScore returns false for non-existent player-match', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
test(
|
||||
'updatePlayerScore returns false for non-existent player-match',
|
||||
() async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
|
||||
final updated = await database.playerMatchDao.updatePlayerScore(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
newScore: 50,
|
||||
);
|
||||
final updated = await database.playerMatchDao.updatePlayerScore(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
newScore: 50,
|
||||
);
|
||||
|
||||
expect(updated, false);
|
||||
});
|
||||
expect(updated, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that adding a player with teamId works correctly.
|
||||
test('Adding player with teamId works correctly', () async {
|
||||
@@ -431,17 +442,20 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updatePlayerTeam returns false for non-existent player-match.
|
||||
test('updatePlayerTeam returns false for non-existent player-match', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
test(
|
||||
'updatePlayerTeam returns false for non-existent player-match',
|
||||
() async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyGroup);
|
||||
|
||||
final updated = await database.playerMatchDao.updatePlayerTeam(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
teamId: testTeam1.id,
|
||||
);
|
||||
final updated = await database.playerMatchDao.updatePlayerTeam(
|
||||
matchId: testMatchOnlyGroup.id,
|
||||
playerId: 'non-existent-player-id',
|
||||
teamId: testTeam1.id,
|
||||
);
|
||||
|
||||
expect(updated, false);
|
||||
});
|
||||
expect(updated, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that getPlayersInTeam returns empty list for non-existent team.
|
||||
test('getPlayersInTeam returns empty list for non-existent team', () async {
|
||||
@@ -483,16 +497,19 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that removePlayerFromMatch returns false for non-existent player.
|
||||
test('removePlayerFromMatch returns false for non-existent player', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||
test(
|
||||
'removePlayerFromMatch returns false for non-existent player',
|
||||
() async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||
|
||||
final removed = await database.playerMatchDao.removePlayerFromMatch(
|
||||
playerId: 'non-existent-player-id',
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
final removed = await database.playerMatchDao.removePlayerFromMatch(
|
||||
playerId: 'non-existent-player-id',
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
|
||||
expect(removed, false);
|
||||
});
|
||||
expect(removed, false);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that adding the same player twice to the same match is ignored.
|
||||
test('Adding same player twice to same match is ignored', () async {
|
||||
@@ -528,27 +545,30 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updatePlayersFromMatch with empty list removes all players.
|
||||
test('updatePlayersFromMatch with empty list removes all players', () async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||
test(
|
||||
'updatePlayersFromMatch with empty list removes all players',
|
||||
() async {
|
||||
await database.matchDao.addMatch(match: testMatchOnlyPlayers);
|
||||
|
||||
// Verify players exist initially
|
||||
var players = await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
expect(players?.length, 3);
|
||||
// Verify players exist initially
|
||||
var players = await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
expect(players?.length, 3);
|
||||
|
||||
// Update with empty list
|
||||
await database.playerMatchDao.updatePlayersFromMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
newPlayer: [],
|
||||
);
|
||||
// Update with empty list
|
||||
await database.playerMatchDao.updatePlayersFromMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
newPlayer: [],
|
||||
);
|
||||
|
||||
// Verify all players are removed
|
||||
players = await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
expect(players, isNull);
|
||||
});
|
||||
// Verify all players are removed
|
||||
players = await database.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: testMatchOnlyPlayers.id,
|
||||
);
|
||||
expect(players, isNull);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that updatePlayersFromMatch with same players makes no changes.
|
||||
test('updatePlayersFromMatch with same players makes no changes', () async {
|
||||
@@ -702,16 +722,19 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that getPlayersInTeam returns empty list for non-existent match.
|
||||
test('getPlayersInTeam returns empty list for non-existent match', () async {
|
||||
await database.teamDao.addTeam(team: testTeam1);
|
||||
test(
|
||||
'getPlayersInTeam returns empty list for non-existent match',
|
||||
() async {
|
||||
await database.teamDao.addTeam(team: testTeam1);
|
||||
|
||||
final players = await database.playerMatchDao.getPlayersInTeam(
|
||||
matchId: 'non-existent-match-id',
|
||||
teamId: testTeam1.id,
|
||||
);
|
||||
final players = await database.playerMatchDao.getPlayersInTeam(
|
||||
matchId: 'non-existent-match-id',
|
||||
teamId: testTeam1.id,
|
||||
);
|
||||
|
||||
expect(players.isEmpty, true);
|
||||
});
|
||||
expect(players.isEmpty, true);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that players in different teams within the same match are returned correctly.
|
||||
test('Players in different teams within same match are separate', () async {
|
||||
@@ -759,8 +782,18 @@ void main() {
|
||||
// Verifies that removePlayerFromMatch does not affect other matches.
|
||||
test('removePlayerFromMatch does not affect other matches', () async {
|
||||
final playersList = [testPlayer1, testPlayer2];
|
||||
final match1 = Match(name: 'Match 1', game: testGame, players: playersList, notes: '');
|
||||
final match2 = Match(name: 'Match 2', game: testGame, players: playersList, notes: '');
|
||||
final match1 = Match(
|
||||
name: 'Match 1',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
final match2 = Match(
|
||||
name: 'Match 2',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
|
||||
await Future.wait([
|
||||
database.matchDao.addMatch(match: match1),
|
||||
@@ -792,8 +825,18 @@ void main() {
|
||||
// Verifies that updating scores for players in different matches are independent.
|
||||
test('Player scores are independent across matches', () async {
|
||||
final playersList = [testPlayer1];
|
||||
final match1 = Match(name: 'Match 1', game: testGame, players: playersList, notes: '');
|
||||
final match2 = Match(name: 'Match 2', game: testGame, players: playersList, notes: '');
|
||||
final match1 = Match(
|
||||
name: 'Match 1',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
final match2 = Match(
|
||||
name: 'Match 2',
|
||||
game: testGame,
|
||||
players: playersList,
|
||||
notes: '',
|
||||
);
|
||||
|
||||
await Future.wait([
|
||||
database.matchDao.addMatch(match: match1),
|
||||
@@ -829,16 +872,19 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updatePlayersFromMatch on non-existent match fails with constraint error.
|
||||
test('updatePlayersFromMatch on non-existent match fails with foreign key constraint', () async {
|
||||
// Should throw due to foreign key constraint - match doesn't exist
|
||||
await expectLater(
|
||||
database.playerMatchDao.updatePlayersFromMatch(
|
||||
matchId: 'non-existent-match-id',
|
||||
newPlayer: [testPlayer1, testPlayer2],
|
||||
),
|
||||
throwsA(anything),
|
||||
);
|
||||
});
|
||||
test(
|
||||
'updatePlayersFromMatch on non-existent match fails with foreign key constraint',
|
||||
() async {
|
||||
// Should throw due to foreign key constraint - match doesn't exist
|
||||
await expectLater(
|
||||
database.playerMatchDao.updatePlayersFromMatch(
|
||||
matchId: 'non-existent-match-id',
|
||||
newPlayer: [testPlayer1, testPlayer2],
|
||||
),
|
||||
throwsA(anything),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that a player can be in a match without being assigned to a team.
|
||||
test('Player can exist in match without team assignment', () async {
|
||||
|
||||
@@ -2,11 +2,11 @@ import 'package:clock/clock.dart';
|
||||
import 'package:drift/drift.dart' hide isNull, isNotNull;
|
||||
import 'package:drift/native.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/data/dto/match.dart';
|
||||
import 'package:tallee/data/dto/player.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
|
||||
void main() {
|
||||
late AppDatabase database;
|
||||
@@ -32,7 +32,12 @@ void main() {
|
||||
testPlayer1 = Player(name: 'Alice', description: '');
|
||||
testPlayer2 = Player(name: 'Bob', description: '');
|
||||
testPlayer3 = Player(name: 'Charlie', description: '');
|
||||
testGame = Game(name: 'Test Game', ruleset: Ruleset.singleWinner, description: 'A test game', color: GameColor.blue, icon: '');
|
||||
testGame = Game(
|
||||
name: 'Test Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'A test game',
|
||||
color: GameColor.blue,
|
||||
);
|
||||
testMatch1 = Match(
|
||||
name: 'Test Match 1',
|
||||
game: testGame,
|
||||
@@ -60,7 +65,6 @@ void main() {
|
||||
});
|
||||
|
||||
group('Score Tests', () {
|
||||
|
||||
// Verifies that a score can be added and retrieved with all fields intact.
|
||||
test('Adding and fetching a score works correctly', () async {
|
||||
await database.scoreDao.addScore(
|
||||
@@ -431,13 +435,16 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that getScoresForMatch returns empty list for match with no scores.
|
||||
test('Getting scores for match with no scores returns empty list', () async {
|
||||
final scores = await database.scoreDao.getScoresForMatch(
|
||||
matchId: testMatch1.id,
|
||||
);
|
||||
test(
|
||||
'Getting scores for match with no scores returns empty list',
|
||||
() async {
|
||||
final scores = await database.scoreDao.getScoresForMatch(
|
||||
matchId: testMatch1.id,
|
||||
);
|
||||
|
||||
expect(scores.isEmpty, true);
|
||||
});
|
||||
expect(scores.isEmpty, true);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that getPlayerScoresInMatch returns empty list when player has no scores.
|
||||
test('Getting player scores with no scores returns empty list', () async {
|
||||
@@ -666,46 +673,58 @@ void main() {
|
||||
});
|
||||
|
||||
// Verifies that updating one player's score doesn't affect another player's score in same round.
|
||||
test('Updating one player score does not affect other players in same round', () async {
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer1.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 10,
|
||||
change: 10,
|
||||
);
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer2.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 20,
|
||||
change: 20,
|
||||
);
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer3.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 30,
|
||||
change: 30,
|
||||
);
|
||||
test(
|
||||
'Updating one player score does not affect other players in same round',
|
||||
() async {
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer1.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 10,
|
||||
change: 10,
|
||||
);
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer2.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 20,
|
||||
change: 20,
|
||||
);
|
||||
await database.scoreDao.addScore(
|
||||
playerId: testPlayer3.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
score: 30,
|
||||
change: 30,
|
||||
);
|
||||
|
||||
await database.scoreDao.updateScore(
|
||||
playerId: testPlayer2.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
newScore: 99,
|
||||
newChange: 89,
|
||||
);
|
||||
await database.scoreDao.updateScore(
|
||||
playerId: testPlayer2.id,
|
||||
matchId: testMatch1.id,
|
||||
roundNumber: 1,
|
||||
newScore: 99,
|
||||
newChange: 89,
|
||||
);
|
||||
|
||||
final scores = await database.scoreDao.getScoresForMatch(
|
||||
matchId: testMatch1.id,
|
||||
);
|
||||
final scores = await database.scoreDao.getScoresForMatch(
|
||||
matchId: testMatch1.id,
|
||||
);
|
||||
|
||||
expect(scores.length, 3);
|
||||
expect(scores.where((s) => s.playerId == testPlayer1.id).first.score, 10);
|
||||
expect(scores.where((s) => s.playerId == testPlayer2.id).first.score, 99);
|
||||
expect(scores.where((s) => s.playerId == testPlayer3.id).first.score, 30);
|
||||
});
|
||||
expect(scores.length, 3);
|
||||
expect(
|
||||
scores.where((s) => s.playerId == testPlayer1.id).first.score,
|
||||
10,
|
||||
);
|
||||
expect(
|
||||
scores.where((s) => s.playerId == testPlayer2.id).first.score,
|
||||
99,
|
||||
);
|
||||
expect(
|
||||
scores.where((s) => s.playerId == testPlayer3.id).first.score,
|
||||
30,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
// Verifies that deleting a player's scores only affects that specific player.
|
||||
test('Deleting player scores only affects target player', () async {
|
||||
@@ -724,9 +743,7 @@ void main() {
|
||||
change: 20,
|
||||
);
|
||||
|
||||
await database.scoreDao.deleteScoresForPlayer(
|
||||
playerId: testPlayer1.id,
|
||||
);
|
||||
await database.scoreDao.deleteScoresForPlayer(playerId: testPlayer1.id);
|
||||
|
||||
final match1Scores = await database.scoreDao.getScoresForMatch(
|
||||
matchId: testMatch1.id,
|
||||
|
||||
Reference in New Issue
Block a user