Merge remote-tracking branch 'origin/development' into bug/195-datenbank-onDelete-ueberpruefen
# Conflicts: # assets/schema.json # lib/data/db/tables/player_match_table.dart # lib/data/models/game.dart
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttericon/rpg_awesome_icons.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
@@ -18,11 +19,78 @@ String translateRulesetToString(Ruleset ruleset, BuildContext context) {
|
||||
return loc.single_loser;
|
||||
case Ruleset.multipleWinners:
|
||||
return loc.multiple_winners;
|
||||
case Ruleset.placement:
|
||||
return loc.placement;
|
||||
}
|
||||
}
|
||||
|
||||
/// 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
|
||||
/// 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 const Color(0xFFF7CA28);
|
||||
case GameColor.purple:
|
||||
return Colors.purple;
|
||||
case GameColor.orange:
|
||||
return const Color(0xFFef681f);
|
||||
case GameColor.pink:
|
||||
return Colors.pink;
|
||||
case GameColor.teal:
|
||||
return Colors.teal;
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns [IconData] corresponding to a [Ruleset] enum value.
|
||||
IconData getRulesetIcon(Ruleset ruleset) {
|
||||
switch (ruleset) {
|
||||
case Ruleset.highestScore:
|
||||
return Icons.arrow_upward;
|
||||
case Ruleset.lowestScore:
|
||||
return Icons.arrow_downward;
|
||||
case Ruleset.singleWinner:
|
||||
return Icons.emoji_events;
|
||||
case Ruleset.singleLoser:
|
||||
return Icons.sentiment_dissatisfied;
|
||||
case Ruleset.multipleWinners:
|
||||
return Icons.group;
|
||||
case Ruleset.placement:
|
||||
return RpgAwesome.podium;
|
||||
}
|
||||
}
|
||||
|
||||
/// Counts how many players in the [match] are not part of the group
|
||||
///
|
||||
/// Returns the text you append after the group name, e.g. " + 5" or an empty
|
||||
/// string if there are no extra players
|
||||
String getExtraPlayerCount(Match match) {
|
||||
int count = 0;
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -63,9 +63,8 @@ class CustomTheme {
|
||||
|
||||
static BoxDecoration highlightedBoxDecoration = BoxDecoration(
|
||||
color: boxColor,
|
||||
border: Border.all(color: primaryColor),
|
||||
border: Border.all(color: textColor, width: 2),
|
||||
borderRadius: standardBorderRadiusAll,
|
||||
boxShadow: [BoxShadow(color: primaryColor.withAlpha(120), blurRadius: 12)],
|
||||
);
|
||||
|
||||
// ==================== Component Themes ====================
|
||||
|
||||
@@ -32,21 +32,15 @@ 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.
|
||||
/// - [Ruleset.placement]: The player with the highest placement wins.
|
||||
enum Ruleset {
|
||||
singleWinner,
|
||||
multipleWinners,
|
||||
highestScore,
|
||||
lowestScore,
|
||||
singleWinner,
|
||||
placement,
|
||||
singleLoser,
|
||||
multipleWinners,
|
||||
}
|
||||
|
||||
/// Different colors available for games
|
||||
/// - [GameColor.red]: Red color
|
||||
/// - [GameColor.blue]: Blue color
|
||||
/// - [GameColor.green]: Green color
|
||||
/// - [GameColor.yellow]: Yellow color
|
||||
/// - [GameColor.purple]: Purple color
|
||||
/// - [GameColor.orange]: Orange color
|
||||
/// - [GameColor.pink]: Pink color
|
||||
/// - [GameColor.teal]: Teal color
|
||||
enum GameColor { red, blue, green, yellow, purple, orange, pink, teal }
|
||||
/// Different colors for highlighting games
|
||||
enum GameColor { red, orange, yellow, green, teal, blue, purple, pink }
|
||||
|
||||
@@ -10,39 +10,7 @@ part 'game_dao.g.dart';
|
||||
class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
GameDao(super.db);
|
||||
|
||||
/// Retrieves all games from the database.
|
||||
Future<List<Game>> getAllGames() async {
|
||||
final query = select(gameTable);
|
||||
final result = await query.get();
|
||||
return result
|
||||
.map(
|
||||
(row) => Game(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
ruleset: Ruleset.values.firstWhere((e) => e.name == row.ruleset),
|
||||
description: row.description,
|
||||
color: GameColor.values.firstWhere((e) => e.name == row.color),
|
||||
icon: row.icon,
|
||||
createdAt: row.createdAt,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Retrieves a [Game] by its [gameId].
|
||||
Future<Game> getGameById({required String gameId}) async {
|
||||
final query = select(gameTable)..where((g) => g.id.equals(gameId));
|
||||
final result = await query.getSingle();
|
||||
return Game(
|
||||
id: result.id,
|
||||
name: result.name,
|
||||
ruleset: Ruleset.values.firstWhere((e) => e.name == result.ruleset),
|
||||
description: result.description,
|
||||
color: GameColor.values.firstWhere((e) => e.name == result.color),
|
||||
icon: result.icon,
|
||||
createdAt: result.createdAt,
|
||||
);
|
||||
}
|
||||
/* Create */
|
||||
|
||||
/// Adds a new [game] to the database.
|
||||
/// If a game with the same ID already exists, no action is taken.
|
||||
@@ -94,71 +62,7 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Deletes the game with the given [gameId] from the database.
|
||||
/// Returns `true` if the game was deleted, `false` if the game did not exist.
|
||||
Future<bool> deleteGame({required String gameId}) async {
|
||||
final query = delete(gameTable)..where((g) => g.id.equals(gameId));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Checks if a game with the given [gameId] exists in the database.
|
||||
/// Returns `true` if the game exists, `false` otherwise.
|
||||
Future<bool> gameExists({required String gameId}) async {
|
||||
final query = select(gameTable)..where((g) => g.id.equals(gameId));
|
||||
final result = await query.getSingleOrNull();
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/// Updates the name of the game with the given [gameId] to [newName].
|
||||
Future<void> updateGameName({
|
||||
required String gameId,
|
||||
required String newName,
|
||||
}) async {
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(name: Value(newName)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Updates the ruleset of the game with the given [gameId].
|
||||
Future<void> updateGameRuleset({
|
||||
required String gameId,
|
||||
required Ruleset newRuleset,
|
||||
}) async {
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(ruleset: Value(newRuleset.name)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Updates the description of the game with the given [gameId].
|
||||
Future<void> updateGameDescription({
|
||||
required String gameId,
|
||||
required String newDescription,
|
||||
}) async {
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(description: Value(newDescription)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Updates the color of the game with the given [gameId].
|
||||
Future<void> updateGameColor({
|
||||
required String gameId,
|
||||
required GameColor newColor,
|
||||
}) async {
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(color: Value(newColor.name)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Updates the icon of the game with the given [gameId].
|
||||
Future<void> updateGameIcon({
|
||||
required String gameId,
|
||||
required String newIcon,
|
||||
}) async {
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(icon: Value(newIcon)),
|
||||
);
|
||||
}
|
||||
/* Read */
|
||||
|
||||
/// Retrieves the total count of games in the database.
|
||||
Future<int> getGameCount() async {
|
||||
@@ -169,6 +73,120 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
return count ?? 0;
|
||||
}
|
||||
|
||||
/// Checks if a game with the given [gameId] exists in the database.
|
||||
/// Returns `true` if the game exists, `false` otherwise.
|
||||
Future<bool> gameExists({required String gameId}) async {
|
||||
final query = select(gameTable)..where((g) => g.id.equals(gameId));
|
||||
final result = await query.getSingleOrNull();
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/// Retrieves all games from the database.
|
||||
Future<List<Game>> getAllGames() async {
|
||||
final query = select(gameTable);
|
||||
final result = await query.get();
|
||||
return result
|
||||
.map(
|
||||
(row) => Game(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
ruleset: Ruleset.values.firstWhere((e) => e.name == row.ruleset),
|
||||
description: row.description,
|
||||
color: GameColor.values.firstWhere((e) => e.name == row.color),
|
||||
icon: row.icon,
|
||||
createdAt: row.createdAt,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Retrieves a [Game] by its [gameId].
|
||||
Future<Game> getGameById({required String gameId}) async {
|
||||
final query = select(gameTable)..where((g) => g.id.equals(gameId));
|
||||
final result = await query.getSingle();
|
||||
return Game(
|
||||
id: result.id,
|
||||
name: result.name,
|
||||
ruleset: Ruleset.values.firstWhere((e) => e.name == result.ruleset),
|
||||
description: result.description,
|
||||
color: GameColor.values.firstWhere((e) => e.name == result.color),
|
||||
icon: result.icon,
|
||||
createdAt: result.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
/* Update */
|
||||
|
||||
/// Updates the name of the game with the given [gameId] to [name].
|
||||
Future<bool> updateGameName({
|
||||
required String gameId,
|
||||
required String name,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(name: Value(name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the ruleset of the game with the given [gameId].
|
||||
Future<bool> updateGameRuleset({
|
||||
required String gameId,
|
||||
required Ruleset ruleset,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(ruleset: Value(ruleset.name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the description of the game with the given [gameId].
|
||||
Future<bool> updateGameDescription({
|
||||
required String gameId,
|
||||
required String description,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(description: Value(description)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the color of the game with the given [gameId].
|
||||
Future<bool> updateGameColor({
|
||||
required String gameId,
|
||||
required GameColor color,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(color: Value(color.name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the icon of the game with the given [gameId].
|
||||
Future<bool> updateGameIcon({
|
||||
required String gameId,
|
||||
required String icon,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(gameTable)..where((g) => g.id.equals(gameId))).write(
|
||||
GameTableCompanion(icon: Value(icon)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
|
||||
/// Deletes the game with the given [gameId] from the database.
|
||||
/// Returns `true` if the game was deleted, `false` if the game did not exist.
|
||||
Future<bool> deleteGame({required String gameId}) async {
|
||||
final query = delete(gameTable)..where((g) => g.id.equals(gameId));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Deletes all games from the database.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> deleteAllGames() async {
|
||||
@@ -176,4 +194,25 @@ class GameDao extends DatabaseAccessor<AppDatabase> with _$GameDaoMixin {
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Retrieves all games with their respective match counts.
|
||||
/// Returns a list of tuples (Game, matchCount).
|
||||
Future<List<(Game, int)>> getGameUsage() async {
|
||||
final games = await getAllGames();
|
||||
|
||||
final results = <(Game, int)>[];
|
||||
|
||||
for (final game in games) {
|
||||
final matchCount =
|
||||
await (selectOnly(db.matchTable)
|
||||
..where(db.matchTable.gameId.equals(game.id))
|
||||
..addColumns([db.matchTable.id.count()]))
|
||||
.map((row) => row.read(db.matchTable.id.count()))
|
||||
.getSingle();
|
||||
|
||||
results.add((game, matchCount ?? 0));
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,43 +12,7 @@ part 'group_dao.g.dart';
|
||||
class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
GroupDao(super.db);
|
||||
|
||||
/// Retrieves all groups from the database.
|
||||
Future<List<Group>> getAllGroups() async {
|
||||
final query = select(groupTable);
|
||||
final result = await query.get();
|
||||
return Future.wait(
|
||||
result.map((groupData) async {
|
||||
final members = await db.playerGroupDao.getPlayersOfGroup(
|
||||
groupId: groupData.id,
|
||||
);
|
||||
return Group(
|
||||
id: groupData.id,
|
||||
name: groupData.name,
|
||||
description: groupData.description,
|
||||
members: members,
|
||||
createdAt: groupData.createdAt,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/// Retrieves a [Group] by its [groupId], including its members.
|
||||
Future<Group> getGroupById({required String groupId}) async {
|
||||
final query = select(groupTable)..where((g) => g.id.equals(groupId));
|
||||
final result = await query.getSingle();
|
||||
|
||||
List<Player> members = await db.playerGroupDao.getPlayersOfGroup(
|
||||
groupId: groupId,
|
||||
);
|
||||
|
||||
return Group(
|
||||
id: result.id,
|
||||
name: result.name,
|
||||
description: result.description,
|
||||
members: members,
|
||||
createdAt: result.createdAt,
|
||||
);
|
||||
}
|
||||
/* Create */
|
||||
|
||||
/// Adds a new group with the given [id] and [name] to the database.
|
||||
/// This method also adds the group's members to the [PlayerGroupTable].
|
||||
@@ -172,38 +136,44 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
});
|
||||
}
|
||||
|
||||
/// Deletes the group with the given [id] from the database.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> deleteGroup({required String groupId}) async {
|
||||
final query = (delete(groupTable)..where((g) => g.id.equals(groupId)));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
/* Read */
|
||||
|
||||
/// Retrieves all groups from the database.
|
||||
Future<List<Group>> getAllGroups() async {
|
||||
final query = select(groupTable);
|
||||
final result = await query.get();
|
||||
return Future.wait(
|
||||
result.map((groupData) async {
|
||||
final members = await db.playerGroupDao.getPlayersOfGroup(
|
||||
groupId: groupData.id,
|
||||
);
|
||||
return Group(
|
||||
id: groupData.id,
|
||||
name: groupData.name,
|
||||
description: groupData.description,
|
||||
members: members,
|
||||
createdAt: groupData.createdAt,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/// Updates the name of the group with the given [id] to [newName].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateGroupName({
|
||||
required String groupId,
|
||||
required String newName,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(groupTable)..where((g) => g.id.equals(groupId))).write(
|
||||
GroupTableCompanion(name: Value(newName)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
/// Retrieves a [Group] by its [groupId], including its members.
|
||||
Future<Group> getGroupById({required String groupId}) async {
|
||||
final query = select(groupTable)..where((g) => g.id.equals(groupId));
|
||||
final result = await query.getSingle();
|
||||
|
||||
/// Updates the description of the group with the given [groupId] to [newDescription].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateGroupDescription({
|
||||
required String groupId,
|
||||
required String newDescription,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(groupTable)..where((g) => g.id.equals(groupId))).write(
|
||||
GroupTableCompanion(description: Value(newDescription)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
List<Player> members = await db.playerGroupDao.getPlayersOfGroup(
|
||||
groupId: groupId,
|
||||
);
|
||||
|
||||
return Group(
|
||||
id: result.id,
|
||||
name: result.name,
|
||||
description: result.description,
|
||||
members: members,
|
||||
createdAt: result.createdAt,
|
||||
);
|
||||
}
|
||||
|
||||
/// Retrieves the number of groups in the database.
|
||||
@@ -223,6 +193,16 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
|
||||
/// Deletes the group with the given [id] from the database.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> deleteGroup({required String groupId}) async {
|
||||
final query = (delete(groupTable)..where((g) => g.id.equals(groupId)));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Deletes all groups from the database.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> deleteAllGroups() async {
|
||||
@@ -231,47 +211,31 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Replaces all players in a group with the provided list of players.
|
||||
/// Removes all existing players from the group and adds the new players.
|
||||
/// Also adds any new players to the player table if they don't exist.
|
||||
/// Returns `true` if the group exists and players were replaced, `false` otherwise.
|
||||
Future<bool> replaceGroupPlayers({
|
||||
/* Update */
|
||||
|
||||
/// Updates the name of the group with the given [id] to [name].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateGroupName({
|
||||
required String groupId,
|
||||
required List<Player> newPlayers,
|
||||
required String name,
|
||||
}) async {
|
||||
if (!await groupExists(groupId: groupId)) return false;
|
||||
final rowsAffected =
|
||||
await (update(groupTable)..where((g) => g.id.equals(groupId))).write(
|
||||
GroupTableCompanion(name: Value(name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
await db.transaction(() async {
|
||||
// Remove all existing players from the group
|
||||
final deleteQuery = delete(db.playerGroupTable)
|
||||
..where((p) => p.groupId.equals(groupId));
|
||||
await deleteQuery.go();
|
||||
|
||||
// Add new players to the player table if they don't exist
|
||||
await Future.wait(
|
||||
newPlayers.map((player) async {
|
||||
if (!await db.playerDao.playerExists(playerId: player.id)) {
|
||||
await db.playerDao.addPlayer(player: player);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
// Add the new players to the group
|
||||
await db.batch(
|
||||
(b) => b.insertAll(
|
||||
db.playerGroupTable,
|
||||
newPlayers
|
||||
.map(
|
||||
(player) => PlayerGroupTableCompanion.insert(
|
||||
playerId: player.id,
|
||||
groupId: groupId,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
);
|
||||
});
|
||||
return true;
|
||||
/// Updates the description of the group with the given [groupId] to [description].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateGroupDescription({
|
||||
required String groupId,
|
||||
required String description,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(groupTable)..where((g) => g.id.equals(groupId))).write(
|
||||
GroupTableCompanion(description: Value(description)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/data/models/team.dart';
|
||||
|
||||
part 'match_dao.g.dart';
|
||||
|
||||
@@ -15,74 +16,13 @@ part 'match_dao.g.dart';
|
||||
class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
MatchDao(super.db);
|
||||
|
||||
/// Retrieves all matches from the database.
|
||||
Future<List<Match>> getAllMatches() async {
|
||||
final query = select(matchTable);
|
||||
final result = await query.get();
|
||||
/* Create */
|
||||
|
||||
return Future.wait(
|
||||
result.map((row) async {
|
||||
final game = await db.gameDao.getGameById(gameId: row.gameId);
|
||||
Group? group;
|
||||
if (row.groupId != null) {
|
||||
group = await db.groupDao.getGroupById(groupId: row.groupId!);
|
||||
}
|
||||
final players =
|
||||
await db.playerMatchDao.getPlayersOfMatch(matchId: row.id) ?? [];
|
||||
|
||||
final scores = await db.scoreEntryDao.getAllMatchScores(
|
||||
matchId: row.id,
|
||||
);
|
||||
|
||||
return Match(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
game: game,
|
||||
group: group,
|
||||
players: players,
|
||||
notes: row.notes ?? '',
|
||||
createdAt: row.createdAt,
|
||||
endedAt: row.endedAt,
|
||||
scores: scores,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/// Retrieves a [Match] by its [matchId].
|
||||
Future<Match> getMatchById({required String matchId}) async {
|
||||
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final result = await query.getSingle();
|
||||
|
||||
final game = await db.gameDao.getGameById(gameId: result.gameId);
|
||||
|
||||
Group? group;
|
||||
if (result.groupId != null) {
|
||||
group = await db.groupDao.getGroupById(groupId: result.groupId!);
|
||||
}
|
||||
|
||||
final players =
|
||||
await db.playerMatchDao.getPlayersOfMatch(matchId: matchId) ?? [];
|
||||
|
||||
final scores = await db.scoreEntryDao.getAllMatchScores(matchId: matchId);
|
||||
|
||||
return Match(
|
||||
id: result.id,
|
||||
name: result.name,
|
||||
game: game,
|
||||
group: group,
|
||||
players: players,
|
||||
notes: result.notes ?? '',
|
||||
createdAt: result.createdAt,
|
||||
endedAt: result.endedAt,
|
||||
scores: scores,
|
||||
);
|
||||
}
|
||||
|
||||
/// Adds a new [Match] to the database. Also adds players associations.
|
||||
/// Adds a new [Match] to the database. Also adds players associations and teams.
|
||||
/// This method assumes that the game and group (if any) are already present
|
||||
/// in the database.
|
||||
Future<void> addMatch({required Match match}) async {
|
||||
Future<bool> addMatch({required Match match}) async {
|
||||
if (await matchExists(matchId: match.id)) return false;
|
||||
await db.transaction(() async {
|
||||
await into(matchTable).insert(
|
||||
MatchTableCompanion.insert(
|
||||
@@ -90,18 +30,36 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
gameId: match.game.id,
|
||||
groupId: Value(match.group?.id),
|
||||
name: match.name,
|
||||
notes: Value(match.notes),
|
||||
notes: match.notes,
|
||||
createdAt: match.createdAt,
|
||||
endedAt: Value(match.endedAt),
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
|
||||
// Add teams
|
||||
if (match.teams != null && match.teams!.isNotEmpty) {
|
||||
await db.teamDao.addTeamsAsList(teams: match.teams!, matchId: match.id);
|
||||
}
|
||||
|
||||
// Collect all player IDs that are already in teams
|
||||
final playersInTeams = <String>{};
|
||||
if (match.teams != null) {
|
||||
for (final team in match.teams!) {
|
||||
for (final member in team.members) {
|
||||
playersInTeams.add(member.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add players that are not in teams
|
||||
for (final p in match.players) {
|
||||
await db.playerMatchDao.addPlayerToMatch(
|
||||
matchId: match.id,
|
||||
playerId: p.id,
|
||||
);
|
||||
if (!playersInTeams.contains(p.id)) {
|
||||
await db.playerMatchDao.addPlayerToMatch(
|
||||
matchId: match.id,
|
||||
playerId: p.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (final pid in match.scores.keys) {
|
||||
@@ -115,14 +73,15 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Adds multiple [Match]es to the database in a batch operation.
|
||||
/// Also adds associated players and groups if they exist.
|
||||
/// If the [matches] list is empty, the method returns immediately.
|
||||
/// This method should only be used to import matches from a different device.
|
||||
Future<void> addMatchAsList({required List<Match> matches}) async {
|
||||
if (matches.isEmpty) return;
|
||||
Future<bool> addMatchesAsList({required List<Match> matches}) async {
|
||||
if (matches.isEmpty) return false;
|
||||
await db.transaction(() async {
|
||||
// Add all games first (deduplicated)
|
||||
final uniqueGames = <String, Game>{};
|
||||
@@ -183,7 +142,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
gameId: match.game.id,
|
||||
groupId: Value(match.group?.id),
|
||||
name: match.name,
|
||||
notes: Value(match.notes),
|
||||
notes: match.notes,
|
||||
createdAt: match.createdAt,
|
||||
endedAt: Value(match.endedAt),
|
||||
),
|
||||
@@ -279,15 +238,28 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Add teams for matches
|
||||
for (final match in matches) {
|
||||
if (match.teams != null && match.teams!.isNotEmpty) {
|
||||
await db.teamDao.addTeamsAsList(
|
||||
teams: match.teams!,
|
||||
matchId: match.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Deletes the match with the given [matchId] from the database.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> deleteMatch({required String matchId}) async {
|
||||
final query = delete(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
/* Read */
|
||||
|
||||
/// Checks if a match with the given [matchId] exists in the database.
|
||||
/// Returns `true` if the match exists, otherwise `false`.
|
||||
Future<bool> matchExists({required String matchId}) async {
|
||||
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final result = await query.getSingleOrNull();
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/// Retrieves the number of matches in the database.
|
||||
@@ -299,9 +271,90 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
return count ?? 0;
|
||||
}
|
||||
|
||||
/// Retrieves all matches from the database.
|
||||
Future<List<Match>> getAllMatches() async {
|
||||
final query = select(matchTable);
|
||||
final result = await query.get();
|
||||
|
||||
return Future.wait(
|
||||
result.map((row) async {
|
||||
final game = await db.gameDao.getGameById(gameId: row.gameId);
|
||||
Group? group;
|
||||
if (row.groupId != null) {
|
||||
group = await db.groupDao.getGroupById(groupId: row.groupId!);
|
||||
}
|
||||
final players = await db.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: row.id,
|
||||
);
|
||||
|
||||
final scores = await db.scoreEntryDao.getAllMatchScores(
|
||||
matchId: row.id,
|
||||
);
|
||||
|
||||
final teams = await _getMatchTeams(matchId: row.id);
|
||||
|
||||
return Match(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
game: game,
|
||||
group: group,
|
||||
players: players,
|
||||
teams: teams.isEmpty ? null : teams,
|
||||
notes: row.notes,
|
||||
createdAt: row.createdAt,
|
||||
endedAt: row.endedAt,
|
||||
scores: scores,
|
||||
);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
/// Retrieves a [Match] by its [matchId].
|
||||
Future<Match> getMatchById({required String matchId}) async {
|
||||
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final result = await query.getSingle();
|
||||
|
||||
final game = await db.gameDao.getGameById(gameId: result.gameId);
|
||||
|
||||
Group? group;
|
||||
if (result.groupId != null) {
|
||||
group = await db.groupDao.getGroupById(groupId: result.groupId!);
|
||||
}
|
||||
|
||||
final players = await db.playerMatchDao.getPlayersOfMatch(matchId: matchId);
|
||||
|
||||
final scores = await db.scoreEntryDao.getAllMatchScores(matchId: matchId);
|
||||
|
||||
final teams = await _getMatchTeams(matchId: matchId);
|
||||
|
||||
return Match(
|
||||
id: result.id,
|
||||
name: result.name,
|
||||
game: game,
|
||||
group: group,
|
||||
players: players,
|
||||
teams: teams.isEmpty ? null : teams,
|
||||
notes: result.notes,
|
||||
createdAt: result.createdAt,
|
||||
endedAt: result.endedAt,
|
||||
scores: scores,
|
||||
);
|
||||
}
|
||||
|
||||
/// Retrieves the number of matches associated with a specific game.
|
||||
Future<int> getMatchCountByGame({required String gameId}) async {
|
||||
final count =
|
||||
await (selectOnly(matchTable)
|
||||
..where(matchTable.gameId.equals(gameId))
|
||||
..addColumns([matchTable.id.count()]))
|
||||
.map((row) => row.read(matchTable.id.count()))
|
||||
.getSingle();
|
||||
return count ?? 0;
|
||||
}
|
||||
|
||||
/// Retrieves all matches associated with the given [groupId].
|
||||
/// Queries the database directly, filtering by [groupId].
|
||||
Future<List<Match>> getGroupMatches({required String groupId}) async {
|
||||
Future<List<Match>> getMatchesByGroup({required String groupId}) async {
|
||||
final query = select(matchTable)..where((m) => m.groupId.equals(groupId));
|
||||
final rows = await query.get();
|
||||
|
||||
@@ -309,15 +362,18 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
rows.map((row) async {
|
||||
final game = await db.gameDao.getGameById(gameId: row.gameId);
|
||||
final group = await db.groupDao.getGroupById(groupId: groupId);
|
||||
final players =
|
||||
await db.playerMatchDao.getPlayersOfMatch(matchId: row.id) ?? [];
|
||||
final players = await db.playerMatchDao.getPlayersOfMatch(
|
||||
matchId: row.id,
|
||||
);
|
||||
final teams = await _getMatchTeams(matchId: row.id);
|
||||
return Match(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
game: game,
|
||||
group: group,
|
||||
players: players,
|
||||
notes: row.notes ?? '',
|
||||
teams: teams.isEmpty ? null : teams,
|
||||
notes: row.notes,
|
||||
createdAt: row.createdAt,
|
||||
endedAt: row.endedAt,
|
||||
);
|
||||
@@ -325,19 +381,56 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
);
|
||||
}
|
||||
|
||||
/// Checks if a match with the given [matchId] exists in the database.
|
||||
/// Returns `true` if the match exists, otherwise `false`.
|
||||
Future<bool> matchExists({required String matchId}) async {
|
||||
final query = select(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final result = await query.getSingleOrNull();
|
||||
return result != null;
|
||||
/// Helper method to retrieve teams for a specific match
|
||||
Future<List<Team>> _getMatchTeams({required String matchId}) async {
|
||||
// Get all unique team IDs from PlayerMatchTable for this match
|
||||
final playerMatchQuery = select(db.playerMatchTable)
|
||||
..where((pm) => pm.matchId.equals(matchId) & pm.teamId.isNotNull());
|
||||
final playerMatches = await playerMatchQuery.get();
|
||||
|
||||
if (playerMatches.isEmpty) return [];
|
||||
|
||||
final teamIds = playerMatches
|
||||
.map((pm) => pm.teamId)
|
||||
.whereType<String>()
|
||||
.toSet()
|
||||
.toList();
|
||||
|
||||
// Fetch all teams
|
||||
final teams = await Future.wait(
|
||||
teamIds.map((teamId) => db.teamDao.getTeamById(teamId: teamId)),
|
||||
);
|
||||
|
||||
return teams;
|
||||
}
|
||||
|
||||
/// Deletes all matches from the database.
|
||||
/* Update */
|
||||
|
||||
/// Changes the name of the match with the given [matchId] to [name].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> deleteAllMatches() async {
|
||||
final query = delete(matchTable);
|
||||
final rowsAffected = await query.go();
|
||||
Future<bool> updateMatchName({
|
||||
required String matchId,
|
||||
required String name,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
MatchTableCompanion(name: Value(name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the group of the match with the given [matchId].
|
||||
/// Replaces the existing group association with the new group specified by [groupId].
|
||||
/// 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,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
MatchTableCompanion(groupId: Value(groupId)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
@@ -345,7 +438,7 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateMatchNotes({
|
||||
required String matchId,
|
||||
required String? notes,
|
||||
required String notes,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
@@ -354,47 +447,6 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Changes the name of the match with the given [matchId] to [newName].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateMatchName({
|
||||
required String matchId,
|
||||
required String newName,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
MatchTableCompanion(name: Value(newName)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the game of the match with the given [matchId].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateMatchGame({
|
||||
required String matchId,
|
||||
required String gameId,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
MatchTableCompanion(gameId: Value(gameId)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// 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? newGroupId,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
MatchTableCompanion(groupId: Value(newGroupId)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Removes the group association of the match with the given [matchId].
|
||||
/// Sets the groupId to null.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
@@ -406,25 +458,12 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the createdAt timestamp of the match with the given [matchId].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateMatchCreatedAt({
|
||||
required String matchId,
|
||||
required DateTime createdAt,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
MatchTableCompanion(createdAt: Value(createdAt)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the endedAt timestamp of the match with the given [matchId].
|
||||
/// Pass null to remove the ended time (mark match as ongoing).
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updateMatchEndedAt({
|
||||
required String matchId,
|
||||
required DateTime? endedAt,
|
||||
required DateTime endedAt,
|
||||
}) async {
|
||||
final query = update(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.write(
|
||||
@@ -433,37 +472,29 @@ class MatchDao extends DatabaseAccessor<AppDatabase> with _$MatchDaoMixin {
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Replaces all players in a match with the provided list of players.
|
||||
/// Removes all existing players from the match and adds the new players.
|
||||
/// Also adds any new players to the player table if they don't exist.
|
||||
Future<void> replaceMatchPlayers({
|
||||
required String matchId,
|
||||
required List<Player> newPlayers,
|
||||
}) async {
|
||||
await db.transaction(() async {
|
||||
// Remove all existing players from the match
|
||||
final deleteQuery = delete(db.playerMatchTable)
|
||||
..where((p) => p.matchId.equals(matchId));
|
||||
await deleteQuery.go();
|
||||
/* Delete */
|
||||
|
||||
// Add new players to the player table if they don't exist
|
||||
await Future.wait(
|
||||
newPlayers.map((player) async {
|
||||
if (!await db.playerDao.playerExists(playerId: player.id)) {
|
||||
await db.playerDao.addPlayer(player: player);
|
||||
}
|
||||
}),
|
||||
);
|
||||
/// Deletes the match with the given [matchId] from the database.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> deleteMatch({required String matchId}) async {
|
||||
final query = delete(matchTable)..where((g) => g.id.equals(matchId));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
// Add the new players to the match
|
||||
await Future.wait(
|
||||
newPlayers.map(
|
||||
(player) => db.playerMatchDao.addPlayerToMatch(
|
||||
matchId: matchId,
|
||||
playerId: player.id,
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
/// Deletes all matches from the database.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> deleteAllMatches() async {
|
||||
final query = delete(matchTable);
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Deletes all matches associated with a specific game.
|
||||
/// Returns the number of matches deleted.
|
||||
Future<int> deleteMatchesByGame({required String gameId}) async {
|
||||
final query = delete(matchTable)..where((m) => m.gameId.equals(gameId));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,35 +10,7 @@ part 'player_dao.g.dart';
|
||||
class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
||||
PlayerDao(super.db);
|
||||
|
||||
/// Retrieves all players from the database.
|
||||
Future<List<Player>> getAllPlayers() async {
|
||||
final query = select(playerTable);
|
||||
final result = await query.get();
|
||||
return result
|
||||
.map(
|
||||
(row) => Player(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
createdAt: row.createdAt,
|
||||
nameCount: row.nameCount,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Retrieves a [Player] by their [id].
|
||||
Future<Player> getPlayerById({required String playerId}) async {
|
||||
final query = select(playerTable)..where((p) => p.id.equals(playerId));
|
||||
final result = await query.getSingle();
|
||||
return Player(
|
||||
id: result.id,
|
||||
name: result.name,
|
||||
description: result.description,
|
||||
createdAt: result.createdAt,
|
||||
nameCount: result.nameCount,
|
||||
);
|
||||
}
|
||||
/* Create */
|
||||
|
||||
/// Adds a new [player] to the database.
|
||||
/// If a player with the same ID already exists, updates their name to
|
||||
@@ -135,12 +107,15 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Deletes the player with the given [id] from the database.
|
||||
/// Returns `true` if the player was deleted, `false` if the player did not exist.
|
||||
Future<bool> deletePlayer({required String playerId}) async {
|
||||
final query = delete(playerTable)..where((p) => p.id.equals(playerId));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
/* Read */
|
||||
|
||||
/// Retrieves the total count of players in the database.
|
||||
Future<int> getPlayerCount() async {
|
||||
final count =
|
||||
await (selectOnly(playerTable)..addColumns([playerTable.id.count()]))
|
||||
.map((row) => row.read(playerTable.id.count()))
|
||||
.getSingle();
|
||||
return count ?? 0;
|
||||
}
|
||||
|
||||
/// Checks if a player with the given [playerId] exists in the database.
|
||||
@@ -151,10 +126,42 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/// Updates the name of the player with the given [playerId] to [newName].
|
||||
Future<void> updatePlayerName({
|
||||
/// Retrieves all players from the database.
|
||||
Future<List<Player>> getAllPlayers() async {
|
||||
final query = select(playerTable);
|
||||
final result = await query.get();
|
||||
return result
|
||||
.map(
|
||||
(row) => Player(
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
description: row.description,
|
||||
createdAt: row.createdAt,
|
||||
nameCount: row.nameCount,
|
||||
),
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
/// Retrieves a [Player] by their [id].
|
||||
Future<Player> getPlayerById({required String playerId}) async {
|
||||
final query = select(playerTable)..where((p) => p.id.equals(playerId));
|
||||
final result = await query.getSingle();
|
||||
return Player(
|
||||
id: result.id,
|
||||
name: result.name,
|
||||
description: result.description,
|
||||
createdAt: result.createdAt,
|
||||
nameCount: result.nameCount,
|
||||
);
|
||||
}
|
||||
|
||||
/* Update */
|
||||
|
||||
/// Updates the name of the player with the given [playerId] to [name].
|
||||
Future<bool> updatePlayerName({
|
||||
required String playerId,
|
||||
required String newName,
|
||||
required String name,
|
||||
}) async {
|
||||
// Get previous name and name count for the player before updating
|
||||
final previousPlayerName =
|
||||
@@ -164,14 +171,15 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
||||
'';
|
||||
final previousNameCount = await getNameCount(name: previousPlayerName);
|
||||
|
||||
await (update(playerTable)..where((p) => p.id.equals(playerId))).write(
|
||||
PlayerTableCompanion(name: Value(newName)),
|
||||
);
|
||||
final rowsAffected =
|
||||
await (update(playerTable)..where((p) => p.id.equals(playerId))).write(
|
||||
PlayerTableCompanion(name: Value(name)),
|
||||
);
|
||||
|
||||
// Update name count for the new name
|
||||
final count = await calculateNameCount(name: newName);
|
||||
final count = await calculateNameCount(name: name);
|
||||
if (count > 0) {
|
||||
await (update(playerTable)..where((p) => p.name.equals(newName))).write(
|
||||
await (update(playerTable)..where((p) => p.name.equals(name))).write(
|
||||
PlayerTableCompanion(nameCount: Value(count)),
|
||||
);
|
||||
}
|
||||
@@ -188,17 +196,35 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
|
||||
);
|
||||
}
|
||||
}
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Retrieves the total count of players in the database.
|
||||
Future<int> getPlayerCount() async {
|
||||
final count =
|
||||
await (selectOnly(playerTable)..addColumns([playerTable.id.count()]))
|
||||
.map((row) => row.read(playerTable.id.count()))
|
||||
.getSingle();
|
||||
return count ?? 0;
|
||||
/// Updates the description of the player with the given [playerId] to
|
||||
/// [description].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> updatePlayerDescription({
|
||||
required String playerId,
|
||||
required String description,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(playerTable)..where((g) => g.id.equals(playerId))).write(
|
||||
PlayerTableCompanion(description: Value(description)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
|
||||
/// Deletes the player with the given [id] from the database.
|
||||
/// Returns `true` if the player was deleted, `false` if the player did not exist.
|
||||
Future<bool> deletePlayer({required String playerId}) async {
|
||||
final query = delete(playerTable)..where((p) => p.id.equals(playerId));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/* Name count management */
|
||||
|
||||
/// Retrieves the count of players with the given [name].
|
||||
Future<int> getNameCount({required String name}) async {
|
||||
final query = select(playerTable)..where((p) => p.name.equals(name));
|
||||
|
||||
@@ -11,8 +11,7 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
|
||||
with _$PlayerGroupDaoMixin {
|
||||
PlayerGroupDao(super.db);
|
||||
|
||||
/// No need for a groupHasPlayers method since the members attribute is
|
||||
/// not nullable
|
||||
/* Create */
|
||||
|
||||
/// Adds a [player] to a group with the given [groupId].
|
||||
/// If the player is already in the group, no action is taken.
|
||||
@@ -33,10 +32,11 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
|
||||
await into(playerGroupTable).insert(
|
||||
PlayerGroupTableCompanion.insert(playerId: player.id, groupId: groupId),
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Read */
|
||||
|
||||
/// Retrieves all players belonging to a specific group by [groupId].
|
||||
Future<List<Player>> getPlayersOfGroup({required String groupId}) async {
|
||||
final query = select(playerGroupTable)
|
||||
@@ -53,18 +53,6 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
|
||||
return groupMembers;
|
||||
}
|
||||
|
||||
/// Removes a player from a group based on [playerId] and [groupId].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> removePlayerFromGroup({
|
||||
required String playerId,
|
||||
required String groupId,
|
||||
}) async {
|
||||
final query = delete(playerGroupTable)
|
||||
..where((p) => p.playerId.equals(playerId) & p.groupId.equals(groupId));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Checks if a player with [playerId] is in the group with [groupId].
|
||||
/// Returns `true` if the player is in the group, otherwise `false`.
|
||||
Future<bool> isPlayerInGroup({
|
||||
@@ -76,4 +64,65 @@ class PlayerGroupDao extends DatabaseAccessor<AppDatabase>
|
||||
final result = await query.getSingleOrNull();
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/* Update */
|
||||
|
||||
/// Replaces all players in a group with the provided list of players.
|
||||
/// Removes all existing players from the group and adds the new players.
|
||||
/// Also adds any new players to the player table if they don't exist.
|
||||
/// Returns `true` if the group exists and players were replaced, `false` otherwise.
|
||||
Future<bool> replaceGroupPlayers({
|
||||
required String groupId,
|
||||
required List<Player> newPlayers,
|
||||
}) async {
|
||||
if (!await db.groupDao.groupExists(groupId: groupId)) return false;
|
||||
if (newPlayers.isEmpty) return false;
|
||||
|
||||
await db.transaction(() async {
|
||||
// Remove all existing players from the group
|
||||
final deleteQuery = delete(db.playerGroupTable)
|
||||
..where((p) => p.groupId.equals(groupId));
|
||||
await deleteQuery.go();
|
||||
|
||||
// Add new players to the player table if they don't exist
|
||||
await Future.wait(
|
||||
newPlayers.map((player) async {
|
||||
if (!await db.playerDao.playerExists(playerId: player.id)) {
|
||||
await db.playerDao.addPlayer(player: player);
|
||||
}
|
||||
}),
|
||||
);
|
||||
|
||||
// Add the new players to the group
|
||||
await db.batch(
|
||||
(b) => b.insertAll(
|
||||
db.playerGroupTable,
|
||||
newPlayers
|
||||
.map(
|
||||
(player) => PlayerGroupTableCompanion.insert(
|
||||
playerId: player.id,
|
||||
groupId: groupId,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
),
|
||||
);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
|
||||
/// Removes a player from a group based on [playerId] and [groupId].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> removePlayerFromGroup({
|
||||
required String playerId,
|
||||
required String groupId,
|
||||
}) async {
|
||||
final query = delete(playerGroupTable)
|
||||
..where((p) => p.playerId.equals(playerId) & p.groupId.equals(groupId));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,14 +11,16 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
with _$PlayerMatchDaoMixin {
|
||||
PlayerMatchDao(super.db);
|
||||
|
||||
/* Create */
|
||||
|
||||
/// Associates a player with a match by inserting a record into the
|
||||
/// [PlayerMatchTable]. Optionally associates with a team and sets initial score.
|
||||
Future<void> addPlayerToMatch({
|
||||
Future<bool> addPlayerToMatch({
|
||||
required String matchId,
|
||||
required String playerId,
|
||||
String? teamId,
|
||||
}) async {
|
||||
await into(playerMatchTable).insert(
|
||||
final rowsAffected = await into(playerMatchTable).insert(
|
||||
PlayerMatchTableCompanion.insert(
|
||||
playerId: playerId,
|
||||
matchId: matchId,
|
||||
@@ -26,42 +28,14 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
}
|
||||
|
||||
/// Retrieves a list of [Player]s associated with the given [matchId].
|
||||
/// Returns null if no players are found.
|
||||
Future<List<Player>?> getPlayersOfMatch({required String matchId}) async {
|
||||
final result = await (select(
|
||||
playerMatchTable,
|
||||
)..where((p) => p.matchId.equals(matchId))).get();
|
||||
|
||||
if (result.isEmpty) return null;
|
||||
|
||||
final futures = result.map(
|
||||
(row) => db.playerDao.getPlayerById(playerId: row.playerId),
|
||||
);
|
||||
final players = await Future.wait(futures);
|
||||
return players;
|
||||
}
|
||||
|
||||
/// Updates the team for a player in a match.
|
||||
/// Returns `true` if the update was successful, otherwise `false`.
|
||||
Future<bool> updatePlayerTeam({
|
||||
required String matchId,
|
||||
required String playerId,
|
||||
required String? teamId,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(playerMatchTable)..where(
|
||||
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
||||
))
|
||||
.write(PlayerMatchTableCompanion(teamId: Value(teamId)));
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/* Read */
|
||||
|
||||
/// Checks if there are any players associated with the given [matchId].
|
||||
/// Returns `true` if there are players, otherwise `false`.
|
||||
Future<bool> matchHasPlayers({required String matchId}) async {
|
||||
Future<bool> hasMatchPlayers({required String matchId}) async {
|
||||
final count =
|
||||
await (selectOnly(playerMatchTable)
|
||||
..where(playerMatchTable.matchId.equals(matchId))
|
||||
@@ -87,31 +61,79 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
return (count ?? 0) > 0;
|
||||
}
|
||||
|
||||
/// Removes the association of a player with a match by deleting the record
|
||||
/// from the [PlayerMatchTable].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> removePlayerFromMatch({
|
||||
/// Retrieves a list of [Player]s associated with the given [matchId].
|
||||
/// Returns empty list if no players are found.
|
||||
Future<List<Player>> getPlayersOfMatch({required String matchId}) async {
|
||||
final result = await (select(
|
||||
playerMatchTable,
|
||||
)..where((p) => p.matchId.equals(matchId))).get();
|
||||
|
||||
if (result.isEmpty) return [];
|
||||
|
||||
final futures = result.map(
|
||||
(row) => db.playerDao.getPlayerById(playerId: row.playerId),
|
||||
);
|
||||
final players = await Future.wait(futures);
|
||||
return players;
|
||||
}
|
||||
|
||||
/// Retrieves a list of [Player]s associated with a specific team in a match.
|
||||
/// Returns empty list if no players are found for the team in the match.
|
||||
Future<List<Player>> getPlayersOfTeamInMatch({
|
||||
required String matchId,
|
||||
required String teamId,
|
||||
}) async {
|
||||
final result =
|
||||
await (select(playerMatchTable)
|
||||
..where((p) => p.matchId.equals(matchId))
|
||||
..where((p) => p.teamId.equals(teamId)))
|
||||
.get();
|
||||
|
||||
if (result.isEmpty) return [];
|
||||
|
||||
final futures = result.map(
|
||||
(row) => db.playerDao.getPlayerById(playerId: row.playerId),
|
||||
);
|
||||
final players = await Future.wait(futures);
|
||||
return players;
|
||||
}
|
||||
|
||||
/* Updated */
|
||||
|
||||
/// Updates the team for a player in a match.
|
||||
/// Returns `true` if the update was successful, otherwise `false`.
|
||||
Future<bool> updatePlayersTeam({
|
||||
required String matchId,
|
||||
required String playerId,
|
||||
required String? teamId,
|
||||
}) async {
|
||||
final query = delete(playerMatchTable)
|
||||
..where((pg) => pg.matchId.equals(matchId))
|
||||
..where((pg) => pg.playerId.equals(playerId));
|
||||
final rowsAffected = await query.go();
|
||||
final rowsAffected =
|
||||
await (update(playerMatchTable)..where(
|
||||
(p) => p.matchId.equals(matchId) & p.playerId.equals(playerId),
|
||||
))
|
||||
.write(PlayerMatchTableCompanion(teamId: Value(teamId)));
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Updates the players associated with a match based on the provided
|
||||
/// [newPlayer] list. It adds new players and removes players that are no
|
||||
/// [player] list. It adds new players and removes players that are no
|
||||
/// longer associated with the match.
|
||||
Future<void> updatePlayersFromMatch({
|
||||
Future<bool> updateMatchPlayers({
|
||||
required String matchId,
|
||||
required List<Player> newPlayer,
|
||||
required List<Player> player,
|
||||
}) async {
|
||||
if (player.isEmpty) return false;
|
||||
|
||||
final currentPlayers = await getPlayersOfMatch(matchId: matchId);
|
||||
// Create sets of player IDs for easy comparison
|
||||
final currentPlayerIds = currentPlayers?.map((p) => p.id).toSet() ?? {};
|
||||
final newPlayerIdsSet = newPlayer.map((p) => p.id).toSet();
|
||||
final currentPlayerIds = currentPlayers.map((p) => p.id).toSet();
|
||||
final newPlayerIdsSet = player.map((p) => p.id).toSet();
|
||||
|
||||
// Are the current and new player identical?
|
||||
if (currentPlayerIds.containsAll(newPlayerIdsSet) &&
|
||||
newPlayerIdsSet.containsAll(currentPlayerIds)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Determine players to add and remove
|
||||
final playersToAdd = newPlayerIdsSet.difference(currentPlayerIds);
|
||||
@@ -147,22 +169,22 @@ class PlayerMatchDao extends DatabaseAccessor<AppDatabase>
|
||||
);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Retrieves all players in a specific team for a match.
|
||||
Future<List<Player>> getPlayersInTeam({
|
||||
/* Delete */
|
||||
|
||||
/// Removes the association of a player with a match by deleting the record
|
||||
/// from the [PlayerMatchTable].
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> removePlayerFromMatch({
|
||||
required String matchId,
|
||||
required String teamId,
|
||||
required String playerId,
|
||||
}) async {
|
||||
final result = await (select(
|
||||
playerMatchTable,
|
||||
)..where((p) => p.matchId.equals(matchId) & p.teamId.equals(teamId))).get();
|
||||
|
||||
if (result.isEmpty) return [];
|
||||
|
||||
final futures = result.map(
|
||||
(row) => db.playerDao.getPlayerById(playerId: row.playerId),
|
||||
);
|
||||
return Future.wait(futures);
|
||||
final query = delete(playerMatchTable)
|
||||
..where((pg) => pg.matchId.equals(matchId))
|
||||
..where((pg) => pg.playerId.equals(playerId));
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
with _$ScoreEntryDaoMixin {
|
||||
ScoreEntryDao(super.db);
|
||||
|
||||
/* Create */
|
||||
|
||||
/// Adds a score entry to the database.
|
||||
Future<void> addScore({
|
||||
required String playerId,
|
||||
@@ -58,6 +60,8 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
});
|
||||
}
|
||||
|
||||
/* Read */
|
||||
|
||||
/// Retrieves the score for a specific round.
|
||||
Future<ScoreEntry?> getScore({
|
||||
required String playerId,
|
||||
@@ -126,28 +130,58 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
);
|
||||
}
|
||||
|
||||
/// Gets the highest (latest) round number for a match.
|
||||
/// Returns `null` if there are no scores for the match.
|
||||
Future<int?> getLatestRoundNumber({required String matchId}) async {
|
||||
final query = selectOnly(scoreEntryTable)
|
||||
..where(scoreEntryTable.matchId.equals(matchId))
|
||||
..addColumns([scoreEntryTable.roundNumber.max()]);
|
||||
final result = await query.getSingle();
|
||||
return result.read(scoreEntryTable.roundNumber.max());
|
||||
}
|
||||
|
||||
/// Aggregates the total score for a player in a match by summing all their
|
||||
/// score entry changes. Returns `0` if there are no scores for the player
|
||||
/// in the match.
|
||||
Future<int> getTotalScoreForPlayer({
|
||||
required String playerId,
|
||||
required String matchId,
|
||||
}) async {
|
||||
final scores = await getAllPlayerScoresInMatch(
|
||||
playerId: playerId,
|
||||
matchId: matchId,
|
||||
);
|
||||
if (scores.isEmpty) return 0;
|
||||
// Return the sum of all score changes
|
||||
return scores.fold<int>(0, (sum, element) => sum + element.change);
|
||||
}
|
||||
|
||||
/* Update */
|
||||
|
||||
/// Updates a score entry.
|
||||
Future<bool> updateScore({
|
||||
required String playerId,
|
||||
required String matchId,
|
||||
required ScoreEntry newEntry,
|
||||
required ScoreEntry entry,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(scoreEntryTable)..where(
|
||||
(s) =>
|
||||
s.playerId.equals(playerId) &
|
||||
s.matchId.equals(matchId) &
|
||||
s.roundNumber.equals(newEntry.roundNumber),
|
||||
s.roundNumber.equals(entry.roundNumber),
|
||||
))
|
||||
.write(
|
||||
ScoreEntryTableCompanion(
|
||||
score: Value(newEntry.score),
|
||||
change: Value(newEntry.change),
|
||||
score: Value(entry.score),
|
||||
change: Value(entry.change),
|
||||
),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/* Delete */
|
||||
|
||||
/// Deletes a score entry.
|
||||
Future<bool> deleteScore({
|
||||
required String playerId,
|
||||
@@ -182,31 +216,7 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Gets the highest (latest) round number for a match.
|
||||
/// Returns `null` if there are no scores for the match.
|
||||
Future<int?> getLatestRoundNumber({required String matchId}) async {
|
||||
final query = selectOnly(scoreEntryTable)
|
||||
..where(scoreEntryTable.matchId.equals(matchId))
|
||||
..addColumns([scoreEntryTable.roundNumber.max()]);
|
||||
final result = await query.getSingle();
|
||||
return result.read(scoreEntryTable.roundNumber.max());
|
||||
}
|
||||
|
||||
/// Aggregates the total score for a player in a match by summing all their
|
||||
/// score entry changes. Returns `0` if there are no scores for the player
|
||||
/// in the match.
|
||||
Future<int> getTotalScoreForPlayer({
|
||||
required String playerId,
|
||||
required String matchId,
|
||||
}) async {
|
||||
final scores = await getAllPlayerScoresInMatch(
|
||||
playerId: playerId,
|
||||
matchId: matchId,
|
||||
);
|
||||
if (scores.isEmpty) return 0;
|
||||
// Return the sum of all score changes
|
||||
return scores.fold<int>(0, (sum, element) => sum + element.change);
|
||||
}
|
||||
/* Winner handling */
|
||||
|
||||
Future<bool> hasWinner({required String matchId}) async {
|
||||
return await getWinner(matchId: matchId) != null;
|
||||
@@ -218,7 +228,7 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
required String playerId,
|
||||
}) async {
|
||||
// Clear previous winner if exists
|
||||
deleteAllScoresForMatch(matchId: matchId);
|
||||
await deleteAllScoresForMatch(matchId: matchId);
|
||||
|
||||
// Set the winner's score to 1
|
||||
final rowsAffected = await into(scoreEntryTable).insert(
|
||||
@@ -235,7 +245,7 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
// Retrieves the winner of a match by looking for a score entry where score
|
||||
/// Retrieves the winner of a match by looking for a score entry where score
|
||||
/// is 1. Returns `null` if no player found, else the first with the score.
|
||||
Future<Player?> getWinner({required String matchId}) async {
|
||||
final query =
|
||||
@@ -266,21 +276,52 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
/// Returns `true` if the winner was removed, `false` if there are multiple
|
||||
/// scores or if the winner cannot be removed.
|
||||
Future<bool> removeWinner({required String matchId}) async {
|
||||
final scores = await getAllMatchScores(matchId: matchId);
|
||||
|
||||
if (scores.length > 1) {
|
||||
return false;
|
||||
} else {
|
||||
return await deleteAllScoresForMatch(matchId: matchId);
|
||||
}
|
||||
return await deleteAllScoresForMatch(matchId: matchId);
|
||||
}
|
||||
|
||||
Future<bool> hasLooser({required String matchId}) async {
|
||||
return await getLooser(matchId: matchId) != null;
|
||||
/* multiple winners handling */
|
||||
|
||||
/// Sets the winners for a match.
|
||||
///
|
||||
/// Returns `true` if more than 0 rows were affected
|
||||
Future<bool> setWinners({
|
||||
required List<Player> winners,
|
||||
required String matchId,
|
||||
}) async {
|
||||
// Clear previous winners if exists
|
||||
await deleteAllScoresForMatch(matchId: matchId);
|
||||
|
||||
if (winners.isEmpty) return false;
|
||||
|
||||
await batch((batch) {
|
||||
batch.insertAll(
|
||||
scoreEntryTable,
|
||||
winners
|
||||
.map(
|
||||
(player) => ScoreEntryTableCompanion.insert(
|
||||
playerId: player.id,
|
||||
matchId: matchId,
|
||||
roundNumber: 0,
|
||||
score: 1,
|
||||
change: 0,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Loser handling */
|
||||
|
||||
Future<bool> hasLoser({required String matchId}) async {
|
||||
return await getLoser(matchId: matchId) != null;
|
||||
}
|
||||
|
||||
// Setting the looser for a game and clearing previous looser if exists.
|
||||
Future<bool> setLooser({
|
||||
Future<bool> setLoser({
|
||||
required String matchId,
|
||||
required String playerId,
|
||||
}) async {
|
||||
@@ -304,7 +345,7 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
|
||||
/// Retrieves the looser of a match by looking for a score entry where score
|
||||
/// is 0. Returns `null` if no player found, else the first with the score.
|
||||
Future<Player?> getLooser({required String matchId}) async {
|
||||
Future<Player?> getLoser({required String matchId}) async {
|
||||
final query =
|
||||
select(scoreEntryTable).join([
|
||||
innerJoin(
|
||||
@@ -332,7 +373,7 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
///
|
||||
/// Returns `true` if the looser was removed, `false` if there are multiple
|
||||
/// scores or if the looser cannot be removed.
|
||||
Future<bool> removeLooser({required String matchId}) async {
|
||||
Future<bool> removeLoser({required String matchId}) async {
|
||||
final scores = await getAllMatchScores(matchId: matchId);
|
||||
|
||||
if (scores.length > 1) {
|
||||
@@ -341,4 +382,21 @@ class ScoreEntryDao extends DatabaseAccessor<AppDatabase>
|
||||
return await deleteAllScoresForMatch(matchId: matchId);
|
||||
}
|
||||
}
|
||||
|
||||
/* placement handling */
|
||||
|
||||
/// Sets the placement for each player in a match.
|
||||
/// The highest score is assigned to the first player, the second highest to the second player, and so on.
|
||||
Future<void> setPlacements({
|
||||
required String matchId,
|
||||
required List<Player> players,
|
||||
}) async {
|
||||
for (int i = 0; i < players.length; i++) {
|
||||
await db.scoreEntryDao.addScore(
|
||||
matchId: matchId,
|
||||
playerId: players[i].id,
|
||||
entry: ScoreEntry(roundNumber: 0, score: players.length - i, change: 0),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,105 @@
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/db/tables/player_match_table.dart';
|
||||
import 'package:tallee/data/db/tables/team_table.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/data/models/team.dart';
|
||||
|
||||
part 'team_dao.g.dart';
|
||||
|
||||
@DriftAccessor(tables: [TeamTable])
|
||||
@DriftAccessor(tables: [TeamTable, PlayerMatchTable])
|
||||
class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
|
||||
TeamDao(super.db);
|
||||
|
||||
/* Create */
|
||||
|
||||
/// Adds a new [team] to the database.
|
||||
/// Returns `true` if the team was added, `false` otherwise.
|
||||
Future<bool> addTeam({required Team team, required String matchId}) async {
|
||||
if (await teamExists(teamId: team.id)) return false;
|
||||
await into(teamTable).insert(
|
||||
TeamTableCompanion.insert(
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
createdAt: team.createdAt,
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
await db.batch((batch) async {
|
||||
for (final player in team.members) {
|
||||
await into(playerMatchTable).insert(
|
||||
PlayerMatchTableCompanion.insert(
|
||||
playerId: player.id,
|
||||
matchId: matchId,
|
||||
teamId: Value(team.id),
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Adds multiple [teams] to the database in a batch operation.
|
||||
Future<bool> addTeamsAsList({
|
||||
required List<Team> teams,
|
||||
required String matchId,
|
||||
}) async {
|
||||
if (teams.isEmpty) return false;
|
||||
|
||||
await db.batch(
|
||||
(b) => b.insertAll(
|
||||
teamTable,
|
||||
teams
|
||||
.map(
|
||||
(team) => TeamTableCompanion.insert(
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
createdAt: team.createdAt,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrIgnore,
|
||||
),
|
||||
);
|
||||
|
||||
for (final team in teams) {
|
||||
await db.batch((batch) async {
|
||||
for (final player in team.members) {
|
||||
await into(db.playerMatchTable).insert(
|
||||
PlayerMatchTableCompanion.insert(
|
||||
playerId: player.id,
|
||||
matchId: matchId,
|
||||
teamId: Value(team.id),
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Read */
|
||||
|
||||
/// Retrieves the total count of teams in the database.
|
||||
Future<int> getTeamCount() async {
|
||||
final count =
|
||||
await (selectOnly(teamTable)..addColumns([teamTable.id.count()]))
|
||||
.map((row) => row.read(teamTable.id.count()))
|
||||
.getSingle();
|
||||
return count ?? 0;
|
||||
}
|
||||
|
||||
/// Checks if a team with the given [teamId] exists in the database.
|
||||
/// Returns `true` if the team exists, `false` otherwise.
|
||||
Future<bool> teamExists({required String teamId}) async {
|
||||
final query = select(teamTable)..where((t) => t.id.equals(teamId));
|
||||
final result = await query.getSingleOrNull();
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/// Retrieves all teams from the database.
|
||||
/// Note: This returns teams without their members. Use getTeamById for full team data.
|
||||
Future<List<Team>> getAllTeams() async {
|
||||
final query = select(teamTable);
|
||||
final result = await query.get();
|
||||
@@ -41,8 +129,7 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
|
||||
);
|
||||
}
|
||||
|
||||
/// Helper method to get team members from player_match_table.
|
||||
/// This assumes team members are tracked via the player_match_table.
|
||||
/// Helper method to get team members from PlayerMatchTable.
|
||||
Future<List<Player>> _getTeamMembers({required String teamId}) async {
|
||||
// Get all player_match entries with this teamId
|
||||
final playerMatchQuery = select(db.playerMatchTable)
|
||||
@@ -61,44 +148,28 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
|
||||
return players;
|
||||
}
|
||||
|
||||
/// Adds a new [team] to the database.
|
||||
/// Returns `true` if the team was added, `false` otherwise.
|
||||
Future<bool> addTeam({required Team team}) async {
|
||||
if (!await teamExists(teamId: team.id)) {
|
||||
await into(teamTable).insert(
|
||||
TeamTableCompanion.insert(
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
createdAt: team.createdAt,
|
||||
),
|
||||
mode: InsertMode.insertOrReplace,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
/* Update */
|
||||
|
||||
/// Updates the name of the team with the given [teamId].
|
||||
Future<bool> updateTeamName({
|
||||
required String teamId,
|
||||
required String name,
|
||||
}) async {
|
||||
final rowsAffected =
|
||||
await (update(teamTable)..where((t) => t.id.equals(teamId))).write(
|
||||
TeamTableCompanion(name: Value(name)),
|
||||
);
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Adds multiple [teams] to the database in a batch operation.
|
||||
Future<bool> addTeamsAsList({required List<Team> teams}) async {
|
||||
if (teams.isEmpty) return false;
|
||||
/* Delete */
|
||||
|
||||
await db.batch(
|
||||
(b) => b.insertAll(
|
||||
teamTable,
|
||||
teams
|
||||
.map(
|
||||
(team) => TeamTableCompanion.insert(
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
createdAt: team.createdAt,
|
||||
),
|
||||
)
|
||||
.toList(),
|
||||
mode: InsertMode.insertOrIgnore,
|
||||
),
|
||||
);
|
||||
|
||||
return true;
|
||||
/// Deletes all teams from the database.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> deleteAllTeams() async {
|
||||
final query = delete(teamTable);
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Deletes the team with the given [teamId] from the database.
|
||||
@@ -108,39 +179,4 @@ class TeamDao extends DatabaseAccessor<AppDatabase> with _$TeamDaoMixin {
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
/// Checks if a team with the given [teamId] exists in the database.
|
||||
/// Returns `true` if the team exists, `false` otherwise.
|
||||
Future<bool> teamExists({required String teamId}) async {
|
||||
final query = select(teamTable)..where((t) => t.id.equals(teamId));
|
||||
final result = await query.getSingleOrNull();
|
||||
return result != null;
|
||||
}
|
||||
|
||||
/// Updates the name of the team with the given [teamId].
|
||||
Future<void> updateTeamName({
|
||||
required String teamId,
|
||||
required String newName,
|
||||
}) async {
|
||||
await (update(teamTable)..where((t) => t.id.equals(teamId))).write(
|
||||
TeamTableCompanion(name: Value(newName)),
|
||||
);
|
||||
}
|
||||
|
||||
/// Retrieves the total count of teams in the database.
|
||||
Future<int> getTeamCount() async {
|
||||
final count =
|
||||
await (selectOnly(teamTable)..addColumns([teamTable.id.count()]))
|
||||
.map((row) => row.read(teamTable.id.count()))
|
||||
.getSingle();
|
||||
return count ?? 0;
|
||||
}
|
||||
|
||||
/// Deletes all teams from the database.
|
||||
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
|
||||
Future<bool> deleteAllTeams() async {
|
||||
final query = delete(teamTable);
|
||||
final rowsAffected = await query.go();
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,12 @@ part of 'team_dao.dart';
|
||||
// ignore_for_file: type=lint
|
||||
mixin _$TeamDaoMixin on DatabaseAccessor<AppDatabase> {
|
||||
$TeamTableTable get teamTable => attachedDatabase.teamTable;
|
||||
$PlayerTableTable get playerTable => attachedDatabase.playerTable;
|
||||
$GameTableTable get gameTable => attachedDatabase.gameTable;
|
||||
$GroupTableTable get groupTable => attachedDatabase.groupTable;
|
||||
$MatchTableTable get matchTable => attachedDatabase.matchTable;
|
||||
$PlayerMatchTableTable get playerMatchTable =>
|
||||
attachedDatabase.playerMatchTable;
|
||||
TeamDaoManager get managers => TeamDaoManager(this);
|
||||
}
|
||||
|
||||
@@ -13,4 +19,17 @@ class TeamDaoManager {
|
||||
TeamDaoManager(this._db);
|
||||
$$TeamTableTableTableManager get teamTable =>
|
||||
$$TeamTableTableTableManager(_db.attachedDatabase, _db.teamTable);
|
||||
$$PlayerTableTableTableManager get playerTable =>
|
||||
$$PlayerTableTableTableManager(_db.attachedDatabase, _db.playerTable);
|
||||
$$GameTableTableTableManager get gameTable =>
|
||||
$$GameTableTableTableManager(_db.attachedDatabase, _db.gameTable);
|
||||
$$GroupTableTableTableManager get groupTable =>
|
||||
$$GroupTableTableTableManager(_db.attachedDatabase, _db.groupTable);
|
||||
$$MatchTableTableTableManager get matchTable =>
|
||||
$$MatchTableTableTableManager(_db.attachedDatabase, _db.matchTable);
|
||||
$$PlayerMatchTableTableTableManager get playerMatchTable =>
|
||||
$$PlayerMatchTableTableTableManager(
|
||||
_db.attachedDatabase,
|
||||
_db.playerMatchTable,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1190,9 +1190,9 @@ class $MatchTableTable extends MatchTable
|
||||
late final GeneratedColumn<String> notes = GeneratedColumn<String>(
|
||||
'notes',
|
||||
aliasedName,
|
||||
true,
|
||||
false,
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
requiredDuringInsert: true,
|
||||
);
|
||||
static const VerificationMeta _createdAtMeta = const VerificationMeta(
|
||||
'createdAt',
|
||||
@@ -1270,6 +1270,8 @@ class $MatchTableTable extends MatchTable
|
||||
_notesMeta,
|
||||
notes.isAcceptableOrUnknown(data['notes']!, _notesMeta),
|
||||
);
|
||||
} else if (isInserting) {
|
||||
context.missing(_notesMeta);
|
||||
}
|
||||
if (data.containsKey('created_at')) {
|
||||
context.handle(
|
||||
@@ -1313,7 +1315,7 @@ class $MatchTableTable extends MatchTable
|
||||
notes: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.string,
|
||||
data['${effectivePrefix}notes'],
|
||||
),
|
||||
)!,
|
||||
createdAt: attachedDatabase.typeMapping.read(
|
||||
DriftSqlType.dateTime,
|
||||
data['${effectivePrefix}created_at'],
|
||||
@@ -1336,7 +1338,7 @@ class MatchTableData extends DataClass implements Insertable<MatchTableData> {
|
||||
final String gameId;
|
||||
final String? groupId;
|
||||
final String name;
|
||||
final String? notes;
|
||||
final String notes;
|
||||
final DateTime createdAt;
|
||||
final DateTime? endedAt;
|
||||
const MatchTableData({
|
||||
@@ -1344,7 +1346,7 @@ class MatchTableData extends DataClass implements Insertable<MatchTableData> {
|
||||
required this.gameId,
|
||||
this.groupId,
|
||||
required this.name,
|
||||
this.notes,
|
||||
required this.notes,
|
||||
required this.createdAt,
|
||||
this.endedAt,
|
||||
});
|
||||
@@ -1357,9 +1359,7 @@ class MatchTableData extends DataClass implements Insertable<MatchTableData> {
|
||||
map['group_id'] = Variable<String>(groupId);
|
||||
}
|
||||
map['name'] = Variable<String>(name);
|
||||
if (!nullToAbsent || notes != null) {
|
||||
map['notes'] = Variable<String>(notes);
|
||||
}
|
||||
map['notes'] = Variable<String>(notes);
|
||||
map['created_at'] = Variable<DateTime>(createdAt);
|
||||
if (!nullToAbsent || endedAt != null) {
|
||||
map['ended_at'] = Variable<DateTime>(endedAt);
|
||||
@@ -1375,9 +1375,7 @@ class MatchTableData extends DataClass implements Insertable<MatchTableData> {
|
||||
? const Value.absent()
|
||||
: Value(groupId),
|
||||
name: Value(name),
|
||||
notes: notes == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
: Value(notes),
|
||||
notes: Value(notes),
|
||||
createdAt: Value(createdAt),
|
||||
endedAt: endedAt == null && nullToAbsent
|
||||
? const Value.absent()
|
||||
@@ -1395,7 +1393,7 @@ class MatchTableData extends DataClass implements Insertable<MatchTableData> {
|
||||
gameId: serializer.fromJson<String>(json['gameId']),
|
||||
groupId: serializer.fromJson<String?>(json['groupId']),
|
||||
name: serializer.fromJson<String>(json['name']),
|
||||
notes: serializer.fromJson<String?>(json['notes']),
|
||||
notes: serializer.fromJson<String>(json['notes']),
|
||||
createdAt: serializer.fromJson<DateTime>(json['createdAt']),
|
||||
endedAt: serializer.fromJson<DateTime?>(json['endedAt']),
|
||||
);
|
||||
@@ -1408,7 +1406,7 @@ class MatchTableData extends DataClass implements Insertable<MatchTableData> {
|
||||
'gameId': serializer.toJson<String>(gameId),
|
||||
'groupId': serializer.toJson<String?>(groupId),
|
||||
'name': serializer.toJson<String>(name),
|
||||
'notes': serializer.toJson<String?>(notes),
|
||||
'notes': serializer.toJson<String>(notes),
|
||||
'createdAt': serializer.toJson<DateTime>(createdAt),
|
||||
'endedAt': serializer.toJson<DateTime?>(endedAt),
|
||||
};
|
||||
@@ -1419,7 +1417,7 @@ class MatchTableData extends DataClass implements Insertable<MatchTableData> {
|
||||
String? gameId,
|
||||
Value<String?> groupId = const Value.absent(),
|
||||
String? name,
|
||||
Value<String?> notes = const Value.absent(),
|
||||
String? notes,
|
||||
DateTime? createdAt,
|
||||
Value<DateTime?> endedAt = const Value.absent(),
|
||||
}) => MatchTableData(
|
||||
@@ -1427,7 +1425,7 @@ class MatchTableData extends DataClass implements Insertable<MatchTableData> {
|
||||
gameId: gameId ?? this.gameId,
|
||||
groupId: groupId.present ? groupId.value : this.groupId,
|
||||
name: name ?? this.name,
|
||||
notes: notes.present ? notes.value : this.notes,
|
||||
notes: notes ?? this.notes,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
endedAt: endedAt.present ? endedAt.value : this.endedAt,
|
||||
);
|
||||
@@ -1478,7 +1476,7 @@ class MatchTableCompanion extends UpdateCompanion<MatchTableData> {
|
||||
final Value<String> gameId;
|
||||
final Value<String?> groupId;
|
||||
final Value<String> name;
|
||||
final Value<String?> notes;
|
||||
final Value<String> notes;
|
||||
final Value<DateTime> createdAt;
|
||||
final Value<DateTime?> endedAt;
|
||||
final Value<int> rowid;
|
||||
@@ -1497,13 +1495,14 @@ class MatchTableCompanion extends UpdateCompanion<MatchTableData> {
|
||||
required String gameId,
|
||||
this.groupId = const Value.absent(),
|
||||
required String name,
|
||||
this.notes = const Value.absent(),
|
||||
required String notes,
|
||||
required DateTime createdAt,
|
||||
this.endedAt = const Value.absent(),
|
||||
this.rowid = const Value.absent(),
|
||||
}) : id = Value(id),
|
||||
gameId = Value(gameId),
|
||||
name = Value(name),
|
||||
notes = Value(notes),
|
||||
createdAt = Value(createdAt);
|
||||
static Insertable<MatchTableData> custom({
|
||||
Expression<String>? id,
|
||||
@@ -1532,7 +1531,7 @@ class MatchTableCompanion extends UpdateCompanion<MatchTableData> {
|
||||
Value<String>? gameId,
|
||||
Value<String?>? groupId,
|
||||
Value<String>? name,
|
||||
Value<String?>? notes,
|
||||
Value<String>? notes,
|
||||
Value<DateTime>? createdAt,
|
||||
Value<DateTime?>? endedAt,
|
||||
Value<int>? rowid,
|
||||
@@ -2122,7 +2121,7 @@ class $PlayerMatchTableTable extends PlayerMatchTable
|
||||
type: DriftSqlType.string,
|
||||
requiredDuringInsert: false,
|
||||
defaultConstraints: GeneratedColumn.constraintIsAlways(
|
||||
'REFERENCES team_table (id)',
|
||||
'REFERENCES team_table (id) ON DELETE SET NULL',
|
||||
),
|
||||
);
|
||||
@override
|
||||
@@ -2820,6 +2819,13 @@ abstract class _$AppDatabase extends GeneratedDatabase {
|
||||
),
|
||||
result: [TableUpdate('player_match_table', kind: UpdateKind.delete)],
|
||||
),
|
||||
WritePropagation(
|
||||
on: TableUpdateQuery.onTableName(
|
||||
'team_table',
|
||||
limitUpdateKind: UpdateKind.delete,
|
||||
),
|
||||
result: [TableUpdate('player_match_table', kind: UpdateKind.update)],
|
||||
),
|
||||
WritePropagation(
|
||||
on: TableUpdateQuery.onTableName(
|
||||
'player_table',
|
||||
@@ -4086,7 +4092,7 @@ typedef $$MatchTableTableCreateCompanionBuilder =
|
||||
required String gameId,
|
||||
Value<String?> groupId,
|
||||
required String name,
|
||||
Value<String?> notes,
|
||||
required String notes,
|
||||
required DateTime createdAt,
|
||||
Value<DateTime?> endedAt,
|
||||
Value<int> rowid,
|
||||
@@ -4097,7 +4103,7 @@ typedef $$MatchTableTableUpdateCompanionBuilder =
|
||||
Value<String> gameId,
|
||||
Value<String?> groupId,
|
||||
Value<String> name,
|
||||
Value<String?> notes,
|
||||
Value<String> notes,
|
||||
Value<DateTime> createdAt,
|
||||
Value<DateTime?> endedAt,
|
||||
Value<int> rowid,
|
||||
@@ -4560,7 +4566,7 @@ class $$MatchTableTableTableManager
|
||||
Value<String> gameId = const Value.absent(),
|
||||
Value<String?> groupId = const Value.absent(),
|
||||
Value<String> name = const Value.absent(),
|
||||
Value<String?> notes = const Value.absent(),
|
||||
Value<String> notes = const Value.absent(),
|
||||
Value<DateTime> createdAt = const Value.absent(),
|
||||
Value<DateTime?> endedAt = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
@@ -4580,7 +4586,7 @@ class $$MatchTableTableTableManager
|
||||
required String gameId,
|
||||
Value<String?> groupId = const Value.absent(),
|
||||
required String name,
|
||||
Value<String?> notes = const Value.absent(),
|
||||
required String notes,
|
||||
required DateTime createdAt,
|
||||
Value<DateTime?> endedAt = const Value.absent(),
|
||||
Value<int> rowid = const Value.absent(),
|
||||
|
||||
@@ -12,7 +12,7 @@ class MatchTable extends Table {
|
||||
.references(GroupTable, #id, onDelete: KeyAction.setNull)
|
||||
.nullable()();
|
||||
TextColumn get name => text()();
|
||||
TextColumn get notes => text().nullable()();
|
||||
TextColumn get notes => text()();
|
||||
DateTimeColumn get createdAt => dateTime()();
|
||||
DateTimeColumn get endedAt => dateTime().nullable()();
|
||||
BoolColumn get deleted => boolean().withDefault(const Constant(false))();
|
||||
|
||||
@@ -8,8 +8,9 @@ class PlayerMatchTable extends Table {
|
||||
text().references(PlayerTable, #id, onDelete: KeyAction.cascade)();
|
||||
TextColumn get matchId =>
|
||||
text().references(MatchTable, #id, onDelete: KeyAction.cascade)();
|
||||
TextColumn get teamId => text().references(TeamTable, #id).nullable()();
|
||||
BoolColumn get deleted => boolean().withDefault(const Constant(false))();
|
||||
TextColumn get teamId => text()
|
||||
.references(TeamTable, #id, onDelete: KeyAction.setNull)
|
||||
.nullable()();
|
||||
|
||||
@override
|
||||
Set<Column<Object>> get primaryKey => {playerId, matchId};
|
||||
|
||||
@@ -10,27 +10,60 @@ class Game {
|
||||
final String description;
|
||||
final GameColor color;
|
||||
final String icon;
|
||||
final bool deleted;
|
||||
|
||||
Game({
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
required this.name,
|
||||
required this.ruleset,
|
||||
String? description,
|
||||
required this.color,
|
||||
required this.icon,
|
||||
this.deleted = false,
|
||||
this.color = GameColor.orange,
|
||||
this.description = '',
|
||||
this.icon = '',
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
}) : id = id ?? const Uuid().v4(),
|
||||
createdAt = createdAt ?? clock.now(),
|
||||
description = description ?? '';
|
||||
createdAt = createdAt ?? clock.now();
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'Game{id: $id, name: $name, ruleset: $ruleset, description: $description, color: $color, icon: $icon}';
|
||||
}
|
||||
|
||||
/// Creates a Game instance from a JSON object.
|
||||
Game copyWith({
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
String? name,
|
||||
Ruleset? ruleset,
|
||||
String? description,
|
||||
GameColor? color,
|
||||
String? icon,
|
||||
}) {
|
||||
return Game(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
name: name ?? this.name,
|
||||
ruleset: ruleset ?? this.ruleset,
|
||||
description: description ?? this.description,
|
||||
color: color ?? this.color,
|
||||
icon: icon ?? this.icon,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is Game &&
|
||||
runtimeType == other.runtimeType &&
|
||||
id == other.id &&
|
||||
createdAt == other.createdAt &&
|
||||
name == other.name &&
|
||||
ruleset == other.ruleset &&
|
||||
description == other.description &&
|
||||
color == other.color &&
|
||||
icon == other.icon;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(id, createdAt, name, ruleset, description, color, icon);
|
||||
|
||||
Game.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
createdAt = DateTime.parse(json['createdAt']),
|
||||
@@ -41,10 +74,8 @@ class Game {
|
||||
),
|
||||
description = json['description'],
|
||||
color = GameColor.values.firstWhere((e) => e.name == json['color']),
|
||||
icon = json['icon'],
|
||||
deleted = json['deleted'] ?? false;
|
||||
icon = json['icon'];
|
||||
|
||||
/// Converts the Game instance to a JSON object.
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
@@ -53,6 +84,5 @@ class Game {
|
||||
'description': description,
|
||||
'color': color.name,
|
||||
'icon': icon,
|
||||
'deleted': deleted,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
@@ -26,6 +27,42 @@ class Group {
|
||||
return 'Group{id: $id, name: $name, description: $description, members: $members}';
|
||||
}
|
||||
|
||||
Group copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
String? description,
|
||||
DateTime? createdAt,
|
||||
List<Player>? members,
|
||||
}) {
|
||||
return Group(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
description: description ?? this.description,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
members: members ?? this.members,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is Group &&
|
||||
runtimeType == other.runtimeType &&
|
||||
id == other.id &&
|
||||
name == other.name &&
|
||||
description == other.description &&
|
||||
createdAt == other.createdAt &&
|
||||
const DeepCollectionEquality().equals(members, other.members);
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
createdAt,
|
||||
const DeepCollectionEquality().hash(members),
|
||||
);
|
||||
|
||||
/// Creates a Group instance from a JSON object where the related [Player]
|
||||
/// objects are represented by their IDs.
|
||||
Group.fromJson(Map<String, dynamic> json)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/data/models/score_entry.dart';
|
||||
import 'package:tallee/data/models/team.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class Match {
|
||||
@@ -14,6 +16,7 @@ class Match {
|
||||
final Game game;
|
||||
final Group? group;
|
||||
final List<Player> players;
|
||||
final List<Team>? teams;
|
||||
final String notes;
|
||||
Map<String, ScoreEntry?> scores;
|
||||
final bool deleted;
|
||||
@@ -24,6 +27,7 @@ class Match {
|
||||
required this.players,
|
||||
this.endedAt,
|
||||
this.group,
|
||||
this.teams,
|
||||
this.notes = '',
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
@@ -38,9 +42,62 @@ class Match {
|
||||
return 'Match{id: $id, createdAt: $createdAt, endedAt: $endedAt, name: $name, game: $game, group: $group, players: $players, notes: $notes, scores: $scores, mvp: $mvp}';
|
||||
}
|
||||
|
||||
/// Creates a Match instance from a JSON object where related objects are
|
||||
/// represented by their IDs. Therefore, the game, group, and players are not
|
||||
/// fully constructed here.
|
||||
Match copyWith({
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
DateTime? endedAt,
|
||||
String? name,
|
||||
Game? game,
|
||||
Group? group,
|
||||
List<Player>? players,
|
||||
List<Team>? teams,
|
||||
String? notes,
|
||||
Map<String, ScoreEntry?>? scores,
|
||||
}) {
|
||||
return Match(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
endedAt: endedAt ?? this.endedAt,
|
||||
name: name ?? this.name,
|
||||
game: game ?? this.game,
|
||||
group: group ?? this.group,
|
||||
players: players ?? this.players,
|
||||
teams: teams ?? this.teams,
|
||||
notes: notes ?? this.notes,
|
||||
scores: scores ?? this.scores,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is Match &&
|
||||
runtimeType == other.runtimeType &&
|
||||
id == other.id &&
|
||||
createdAt == other.createdAt &&
|
||||
endedAt == other.endedAt &&
|
||||
name == other.name &&
|
||||
game == other.game &&
|
||||
group == other.group &&
|
||||
const DeepCollectionEquality().equals(players, other.players) &&
|
||||
const DeepCollectionEquality().equals(teams, other.teams) &&
|
||||
notes == other.notes &&
|
||||
const DeepCollectionEquality().equals(scores, other.scores);
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
id,
|
||||
createdAt,
|
||||
endedAt,
|
||||
name,
|
||||
game,
|
||||
group,
|
||||
const DeepCollectionEquality().hash(players),
|
||||
const DeepCollectionEquality().hash(teams),
|
||||
notes,
|
||||
const DeepCollectionEquality().hash(scores),
|
||||
);
|
||||
|
||||
Match.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
createdAt = DateTime.parse(json['createdAt']),
|
||||
@@ -57,6 +114,7 @@ class Match {
|
||||
),
|
||||
group = null,
|
||||
players = [],
|
||||
teams = [],
|
||||
scores = json['scores'] != null
|
||||
? (json['scores'] as Map<String, dynamic>).map(
|
||||
(key, value) => MapEntry(
|
||||
@@ -70,9 +128,6 @@ class Match {
|
||||
notes = json['notes'] ?? '',
|
||||
deleted = json['deleted'] ?? false;
|
||||
|
||||
/// Converts the Match instance to a JSON object. Related objects are
|
||||
/// represented by their IDs, so the game, group, and players are not fully
|
||||
/// serialized here.
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
@@ -81,6 +136,7 @@ class Match {
|
||||
'gameId': game.id,
|
||||
'groupId': group?.id,
|
||||
'playerIds': players.map((player) => player.id).toList(),
|
||||
'teams': teams?.map((team) => team.toJson()).toList(),
|
||||
'scores': scores.map((key, value) => MapEntry(key, value?.toJson())),
|
||||
'notes': notes,
|
||||
'deleted': deleted,
|
||||
@@ -103,7 +159,10 @@ class Match {
|
||||
return _getPlayersWithLowestScore().take(1).toList();
|
||||
|
||||
case Ruleset.multipleWinners:
|
||||
return [];
|
||||
return _getPlayersWithHighestScore().toList();
|
||||
|
||||
case Ruleset.placement:
|
||||
return _getPlayersWithHighestScore().take(1).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,36 @@ class Player {
|
||||
return 'Player{id: $id, createdAt: $createdAt, name: $name, nameCount: $nameCount, description: $description}';
|
||||
}
|
||||
|
||||
/// Creates a Player instance from a JSON object.
|
||||
Player copyWith({
|
||||
String? id,
|
||||
DateTime? createdAt,
|
||||
String? name,
|
||||
int? nameCount,
|
||||
String? description,
|
||||
}) {
|
||||
return Player(
|
||||
id: id ?? this.id,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
name: name ?? this.name,
|
||||
nameCount: nameCount ?? this.nameCount,
|
||||
description: description ?? this.description,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is Player &&
|
||||
runtimeType == other.runtimeType &&
|
||||
id == other.id &&
|
||||
createdAt == other.createdAt &&
|
||||
name == other.name &&
|
||||
nameCount == other.nameCount &&
|
||||
description == other.description;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(id, createdAt, name, nameCount, description);
|
||||
|
||||
Player.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
createdAt = DateTime.parse(json['createdAt']),
|
||||
@@ -34,7 +63,6 @@ class Player {
|
||||
description = json['description'],
|
||||
deleted = json['deleted'] ?? false;
|
||||
|
||||
/// Converts the Player instance to a JSON object.
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'createdAt': createdAt.toIso8601String(),
|
||||
|
||||
@@ -11,6 +11,26 @@ class ScoreEntry {
|
||||
return 'ScoreEntry{roundNumber: $roundNumber, score: $score, change: $change}';
|
||||
}
|
||||
|
||||
ScoreEntry copyWith({int? roundNumber, int? score, int? change}) {
|
||||
return ScoreEntry(
|
||||
roundNumber: roundNumber ?? this.roundNumber,
|
||||
score: score ?? this.score,
|
||||
change: change ?? this.change,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is ScoreEntry &&
|
||||
runtimeType == other.runtimeType &&
|
||||
roundNumber == other.roundNumber &&
|
||||
score == other.score &&
|
||||
change == other.change;
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(roundNumber, score, change);
|
||||
|
||||
ScoreEntry.fromJson(Map<String, dynamic> json)
|
||||
: roundNumber = json['roundNumber'],
|
||||
score = json['score'],
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:clock/clock.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
@@ -23,8 +24,38 @@ class Team {
|
||||
return 'Team{id: $id, name: $name, members: $members}';
|
||||
}
|
||||
|
||||
/// Creates a Team instance from a JSON object (memberIds format).
|
||||
/// Player objects are reconstructed from memberIds by the DataTransferService.
|
||||
Team copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
DateTime? createdAt,
|
||||
List<Player>? members,
|
||||
}) {
|
||||
return Team(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
createdAt: createdAt ?? this.createdAt,
|
||||
members: members ?? this.members,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
identical(this, other) ||
|
||||
other is Team &&
|
||||
runtimeType == other.runtimeType &&
|
||||
id == other.id &&
|
||||
name == other.name &&
|
||||
createdAt == other.createdAt &&
|
||||
const DeepCollectionEquality().equals(members, other.members);
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
id,
|
||||
name,
|
||||
createdAt,
|
||||
const DeepCollectionEquality().hash(members),
|
||||
);
|
||||
|
||||
Team.fromJson(Map<String, dynamic> json)
|
||||
: id = json['id'],
|
||||
name = json['name'],
|
||||
@@ -32,8 +63,6 @@ class Team {
|
||||
members = [],
|
||||
deleted = json['deleted'] ?? false;
|
||||
|
||||
/// Converts the Team instance to a JSON object. Related objects are
|
||||
/// represented by their IDs.
|
||||
Map<String, dynamic> toJson() => {
|
||||
'id': id,
|
||||
'name': name,
|
||||
|
||||
@@ -6,10 +6,21 @@
|
||||
"app_name": "Tallee",
|
||||
"best_player": "Beste:r Spieler:in",
|
||||
"cancel": "Abbrechen",
|
||||
"choose_color": "Farbe wählen",
|
||||
"choose_game": "Spielvorlage wählen",
|
||||
"choose_group": "Gruppe wählen",
|
||||
"choose_ruleset": "Regelwerk wählen",
|
||||
"color": "Farbe",
|
||||
"color_blue": "Blau",
|
||||
"color_green": "Grün",
|
||||
"color_orange": "Orange",
|
||||
"color_pink": "Rosa",
|
||||
"color_purple": "Lila",
|
||||
"color_red": "Rot",
|
||||
"color_teal": "Türkis",
|
||||
"color_yellow": "Gelb",
|
||||
"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,16 +33,30 @@
|
||||
"days_ago": "vor {count} Tagen",
|
||||
"delete": "Löschen",
|
||||
"delete_all_data": "Alle Daten löschen",
|
||||
"delete_game": "Spielvorlage löschen",
|
||||
"delete_game_with_matches_warning": "Wenn du diese Spielvorlage löschst, {count, plural, =1{wird 1 Spiel} other{werden {count} Spiele}} mit dieser Spielvorlage ebenfalls gelöscht.",
|
||||
"@delete_game_with_matches_warning": {
|
||||
"placeholders": {
|
||||
"count": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete_group": "Gruppe löschen",
|
||||
"delete_match": "Spiel löschen",
|
||||
"drag_to_set_placement": "Ziehen um Platzierung zu setzen",
|
||||
"description": "Beschreibung",
|
||||
"edit_game": "Spielvorlage bearbeiten",
|
||||
"edit_group": "Gruppe bearbeiten",
|
||||
"edit_match": "Gruppe bearbeiten",
|
||||
"enter_points": "Punkte eingeben",
|
||||
"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",
|
||||
"exit_view": "Ansicht verlassen",
|
||||
"export_canceled": "Export abgebrochen",
|
||||
"export_data": "Daten exportieren",
|
||||
"format_exception": "Formatfehler (siehe Konsole)",
|
||||
@@ -50,6 +75,7 @@
|
||||
"legal": "Rechtliches",
|
||||
"legal_notice": "Impressum",
|
||||
"licenses": "Lizenzen",
|
||||
"live_edit_mode": "Live-Bearbeitungsmodus",
|
||||
"match_in_progress": "Spiel läuft...",
|
||||
"match_name": "Spieltitel",
|
||||
"match_profile": "Spielprofil",
|
||||
@@ -57,6 +83,7 @@
|
||||
"members": "Mitglieder",
|
||||
"most_points": "Höchste Punkte",
|
||||
"no_data_available": "Keine Daten verfügbar",
|
||||
"no_games_created_yet": "Noch keine Spielvorlagen erstellt",
|
||||
"no_groups_created_yet": "Noch keine Gruppen erstellt",
|
||||
"no_licenses_found": "Keine Lizenzen gefunden",
|
||||
"no_license_text_available": "Kein Lizenztext verfügbar",
|
||||
@@ -71,10 +98,11 @@
|
||||
"none": "Kein",
|
||||
"none_group": "Keine",
|
||||
"not_available": "Nicht verfügbar",
|
||||
"placement": "Platzierung",
|
||||
"place": "Platz",
|
||||
"played_matches": "Gespielte Spiele",
|
||||
"player_name": "Spieler:innenname",
|
||||
"players": "Spieler:innen",
|
||||
"players_count": "{count} Spieler",
|
||||
"point": "Punkt",
|
||||
"points": "Punkte",
|
||||
"privacy_policy": "Datenschutzerklärung",
|
||||
@@ -85,12 +113,14 @@
|
||||
"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_placement": "Spieler:innen können in einer Reihenfolge angeordnet werden, die ihre Platzierung reflektiert.",
|
||||
"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",
|
||||
"select_winners": "Gewinner:innen wählen",
|
||||
"select_loser": "Verlierer:in wählen",
|
||||
"selected_players": "Ausgewählte Spieler:innen",
|
||||
"settings": "Einstellungen",
|
||||
@@ -103,6 +133,7 @@
|
||||
"statistics": "Statistiken",
|
||||
"stats": "Statistiken",
|
||||
"successfully_added_player": "Spieler:in {playerName} erfolgreich hinzugefügt",
|
||||
"there_are_no_games_matching_your_search": "Es gibt keine Spielvorlagen, die deiner Suche entspricht",
|
||||
"there_is_no_group_matching_your_search": "Es gibt keine Gruppe, die deiner Suche entspricht",
|
||||
"this_cannot_be_undone": "Dies kann nicht rückgängig gemacht werden.",
|
||||
"tie": "Unentschieden",
|
||||
@@ -110,6 +141,7 @@
|
||||
"undo": "Rückgängig",
|
||||
"unknown_exception": "Unbekannter Fehler (siehe Konsole)",
|
||||
"winner": "Gewinner:in",
|
||||
"winners": "Gewinner:innen",
|
||||
"winrate": "Siegquote",
|
||||
"wins": "Siege",
|
||||
"yesterday_at": "Gestern um"
|
||||
|
||||
@@ -1,349 +1,27 @@
|
||||
{
|
||||
"@@locale": "en",
|
||||
"@all_players": {
|
||||
"description": "Label for all players list"
|
||||
},
|
||||
"@all_players_selected": {
|
||||
"description": "Message when all players are added to selection"
|
||||
},
|
||||
"@amount_of_matches": {
|
||||
"description": "Label for amount of matches statistic"
|
||||
},
|
||||
"@app_name": {
|
||||
"description": "The name of the App"
|
||||
},
|
||||
"@best_player": {
|
||||
"description": "Label for best player statistic"
|
||||
},
|
||||
"@cancel": {
|
||||
"description": "Cancel button text"
|
||||
},
|
||||
"@choose_game": {
|
||||
"description": "Label for choosing a game"
|
||||
},
|
||||
"@choose_group": {
|
||||
"description": "Label for choosing a group"
|
||||
},
|
||||
"@choose_ruleset": {
|
||||
"description": "Label for choosing a ruleset"
|
||||
},
|
||||
"@could_not_add_player": {
|
||||
"description": "Error message when adding a player fails"
|
||||
},
|
||||
"@create_group": {
|
||||
"description": "Button text to create a group"
|
||||
},
|
||||
"@create_match": {
|
||||
"description": "Button text to create a match"
|
||||
},
|
||||
"@create_new_group": {
|
||||
"description": "Appbar text to create a new group"
|
||||
},
|
||||
"@create_new_match": {
|
||||
"description": "Appbar text to create a new match"
|
||||
},
|
||||
"@created_on": {
|
||||
"description": "Label for creation date"
|
||||
},
|
||||
"@data": {
|
||||
"description": "Data label"
|
||||
},
|
||||
"@data_successfully_deleted": {
|
||||
"description": "Success message after deleting data"
|
||||
},
|
||||
"@data_successfully_exported": {
|
||||
"description": "Success message after exporting data"
|
||||
},
|
||||
"@data_successfully_imported": {
|
||||
"description": "Success message after importing data"
|
||||
},
|
||||
"@days_ago": {
|
||||
"description": "Date format for days ago",
|
||||
"placeholders": {
|
||||
"count": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"@delete": {
|
||||
"description": "Delete button text"
|
||||
},
|
||||
"@delete_all_data": {
|
||||
"description": "Confirmation dialog for deleting all data"
|
||||
},
|
||||
"@delete_group": {
|
||||
"description": "Confirmation dialog for deleting a group"
|
||||
},
|
||||
"@delete_match": {
|
||||
"description": "Button text to delete a match"
|
||||
},
|
||||
"@edit_group": {
|
||||
"description": "Button & Appbar label for editing a group"
|
||||
},
|
||||
"@edit_match": {
|
||||
"description": "Button & Appbar label for editing a match"
|
||||
},
|
||||
"@enter_points": {
|
||||
"description": "Label to enter players points"
|
||||
},
|
||||
"@enter_results": {
|
||||
"description": "Button text to enter match results"
|
||||
},
|
||||
"@error_creating_group": {
|
||||
"description": "Error message when group creation 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"
|
||||
},
|
||||
"@export_canceled": {
|
||||
"description": "Message when export is canceled"
|
||||
},
|
||||
"@export_data": {
|
||||
"description": "Export data menu item"
|
||||
},
|
||||
"@format_exception": {
|
||||
"description": "Error message for format exceptions"
|
||||
},
|
||||
"@game": {
|
||||
"description": "Game label"
|
||||
},
|
||||
"@game_name": {
|
||||
"description": "Placeholder for game name search"
|
||||
},
|
||||
"@group": {
|
||||
"description": "Group label"
|
||||
},
|
||||
"@group_name": {
|
||||
"description": "Placeholder for group name input"
|
||||
},
|
||||
"@group_profile": {
|
||||
"description": "Title for group profile view"
|
||||
},
|
||||
"@groups": {
|
||||
"description": "Label for groups"
|
||||
},
|
||||
"@home": {
|
||||
"description": "Home tab label"
|
||||
},
|
||||
"@import_canceled": {
|
||||
"description": "Message when import is canceled"
|
||||
},
|
||||
"@import_data": {
|
||||
"description": "Import data menu item"
|
||||
},
|
||||
"@info": {
|
||||
"description": "Info label"
|
||||
},
|
||||
"@invalid_schema": {
|
||||
"description": "Error message for invalid schema"
|
||||
},
|
||||
"@least_points": {
|
||||
"description": "Title for least points ruleset"
|
||||
},
|
||||
"@legal": {
|
||||
"description": "Legal section header"
|
||||
},
|
||||
"@legal_notice": {
|
||||
"description": "Legal notice menu item"
|
||||
},
|
||||
"@licenses": {
|
||||
"description": "Licenses menu item"
|
||||
},
|
||||
"@match_in_progress": {
|
||||
"description": "Message when match is in progress"
|
||||
},
|
||||
"@match_name": {
|
||||
"description": "Placeholder for match name input"
|
||||
},
|
||||
"@match_profile": {
|
||||
"description": "Title for match profile view"
|
||||
},
|
||||
"@matches": {
|
||||
"description": "Label for matches"
|
||||
},
|
||||
"@members": {
|
||||
"description": "Label for group members"
|
||||
},
|
||||
"@most_points": {
|
||||
"description": "Title for most points ruleset"
|
||||
},
|
||||
"@no_data_available": {
|
||||
"description": "Message when no data in the statistic tiles is given"
|
||||
},
|
||||
"@no_groups_created_yet": {
|
||||
"description": "Message when no groups exist"
|
||||
},
|
||||
"@no_licenses_found": {
|
||||
"description": "Message when no licenses are found"
|
||||
},
|
||||
"@no_license_text_available": {
|
||||
"description": "Message when no license text is available"
|
||||
},
|
||||
"@no_matches_created_yet": {
|
||||
"description": "Message when no matches exist"
|
||||
},
|
||||
"@no_players_created_yet": {
|
||||
"description": "Message when no players exist"
|
||||
},
|
||||
"@no_players_found_with_that_name": {
|
||||
"description": "Message when search returns no results"
|
||||
},
|
||||
"@no_players_selected": {
|
||||
"description": "Message when no players are selected"
|
||||
},
|
||||
"@no_recent_matches_available": {
|
||||
"description": "Message when no recent matches exist"
|
||||
},
|
||||
"@no_results_entered_yet": {
|
||||
"description": "Message when no results have been entered yet"
|
||||
},
|
||||
"@no_second_match_available": {
|
||||
"description": "Message when no second match exists"
|
||||
},
|
||||
"@no_statistics_available": {
|
||||
"description": "Message when no statistics are available, because no matches were played yet"
|
||||
},
|
||||
"@none": {
|
||||
"description": "None option label"
|
||||
},
|
||||
"@none_group": {
|
||||
"description": "None group option label"
|
||||
},
|
||||
"@not_available": {
|
||||
"description": "Abbreviation for not available"
|
||||
},
|
||||
"@played_matches": {
|
||||
"description": "Label for played matches statistic"
|
||||
},
|
||||
"@player_name": {
|
||||
"description": "Placeholder for player name input"
|
||||
},
|
||||
"@players": {
|
||||
"description": "Players label"
|
||||
},
|
||||
"@players_count": {
|
||||
"description": "Shows the number of players",
|
||||
"placeholders": {
|
||||
"count": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"@points": {
|
||||
"description": "Points label"
|
||||
},
|
||||
"@privacy_policy": {
|
||||
"description": "Privacy policy menu item"
|
||||
},
|
||||
"@quick_create": {
|
||||
"description": "Title for quick create section"
|
||||
},
|
||||
"@recent_matches": {
|
||||
"description": "Title for recent matches section"
|
||||
},
|
||||
"@results": {
|
||||
"description": "Label for match results"
|
||||
},
|
||||
"@ruleset": {
|
||||
"description": "Ruleset label"
|
||||
},
|
||||
"@ruleset_least_points": {
|
||||
"description": "Description for least points ruleset"
|
||||
},
|
||||
"@ruleset_most_points": {
|
||||
"description": "Description for most points ruleset"
|
||||
},
|
||||
"@ruleset_single_loser": {
|
||||
"description": "Description for single loser ruleset"
|
||||
},
|
||||
"@ruleset_single_winner": {
|
||||
"description": "Description for single winner ruleset"
|
||||
},
|
||||
"@save_changes": {
|
||||
"description": "Save changes button text"
|
||||
},
|
||||
"@search_for_groups": {
|
||||
"description": "Hint text for group search input field"
|
||||
},
|
||||
"@search_for_players": {
|
||||
"description": "Hint text for player search input field"
|
||||
},
|
||||
"@select_winner": {
|
||||
"description": "Label to select the winner"
|
||||
},
|
||||
"@select_loser": {
|
||||
"description": "Label to select the loser"
|
||||
},
|
||||
"@selected_players": {
|
||||
"description": "Shows the number of selected players"
|
||||
},
|
||||
"@settings": {
|
||||
"description": "Label for the App Settings"
|
||||
},
|
||||
"@single_loser": {
|
||||
"description": "Title for single loser ruleset"
|
||||
},
|
||||
"@single_winner": {
|
||||
"description": "Title for single winner ruleset"
|
||||
},
|
||||
"@statistics": {
|
||||
"description": "Statistics tab label"
|
||||
},
|
||||
"@stats": {
|
||||
"description": "Stats tab label (short)"
|
||||
},
|
||||
"@successfully_added_player": {
|
||||
"description": "Success message when adding a player",
|
||||
"placeholders": {
|
||||
"playerName": {
|
||||
"type": "String",
|
||||
"example": "John"
|
||||
}
|
||||
}
|
||||
},
|
||||
"@there_is_no_group_matching_your_search": {
|
||||
"description": "Message when search returns no groups"
|
||||
},
|
||||
"@this_cannot_be_undone": {
|
||||
"description": "Warning message for irreversible actions"
|
||||
},
|
||||
"@today_at": {
|
||||
"description": "Date format for today"
|
||||
},
|
||||
"@undo": {
|
||||
"description": "Undo button text"
|
||||
},
|
||||
"@unknown_exception": {
|
||||
"description": "Error message for unknown exceptions"
|
||||
},
|
||||
"@winner": {
|
||||
"description": "Winner label"
|
||||
},
|
||||
"@winrate": {
|
||||
"description": "Label for winrate statistic"
|
||||
},
|
||||
"@wins": {
|
||||
"description": "Label for wins statistic"
|
||||
},
|
||||
"@yesterday_at": {
|
||||
"description": "Date format for yesterday"
|
||||
},
|
||||
|
||||
"all_players": "All players",
|
||||
"all_players_selected": "All players selected",
|
||||
"amount_of_matches": "Amount of Matches",
|
||||
"app_name": "Tallee",
|
||||
"best_player": "Best Player",
|
||||
"cancel": "Cancel",
|
||||
"choose_color": "Choose Color",
|
||||
"choose_game": "Choose Game",
|
||||
"choose_group": "Choose Group",
|
||||
"choose_ruleset": "Choose Ruleset",
|
||||
"color": "Color",
|
||||
"color_blue": "Blue",
|
||||
"color_green": "Green",
|
||||
"color_orange": "Orange",
|
||||
"color_pink": "Pink",
|
||||
"color_purple": "Purple",
|
||||
"color_red": "Red",
|
||||
"color_teal": "Teal",
|
||||
"color_yellow": "Yellow",
|
||||
"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",
|
||||
@@ -356,16 +34,30 @@
|
||||
"days_ago": "{count} days ago",
|
||||
"delete": "Delete",
|
||||
"delete_all_data": "Delete all data",
|
||||
"delete_game": "Delete Game",
|
||||
"delete_game_with_matches_warning": "If you delete this game template, {count, plural, =1{1 match} other{{count} matches}} using this game template will also be deleted.",
|
||||
"@delete_game_with_matches_warning": {
|
||||
"placeholders": {
|
||||
"count": {
|
||||
"type": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete_group": "Delete Group",
|
||||
"delete_match": "Delete Match",
|
||||
"drag_to_set_placement": "Drag to set placement",
|
||||
"description": "Description",
|
||||
"edit_game": "Edit Game",
|
||||
"edit_group": "Edit Group",
|
||||
"edit_match": "Edit Match",
|
||||
"enter_points": "Enter points",
|
||||
"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",
|
||||
"exit_view": "Exit View",
|
||||
"export_canceled": "Export canceled",
|
||||
"export_data": "Export data",
|
||||
"format_exception": "Format Exception (see console)",
|
||||
@@ -384,6 +76,7 @@
|
||||
"legal": "Legal",
|
||||
"legal_notice": "Legal Notice",
|
||||
"licenses": "Licenses",
|
||||
"live_edit_mode": "Live Edit Mode",
|
||||
"match_in_progress": "Match in progress...",
|
||||
"match_name": "Match name",
|
||||
"match_profile": "Match Profile",
|
||||
@@ -391,6 +84,7 @@
|
||||
"members": "Members",
|
||||
"most_points": "Most Points",
|
||||
"no_data_available": "No data available",
|
||||
"no_games_created_yet": "No games created yet",
|
||||
"no_groups_created_yet": "No groups created yet",
|
||||
"no_licenses_found": "No licenses found",
|
||||
"no_license_text_available": "No license text available",
|
||||
@@ -405,10 +99,11 @@
|
||||
"none": "None",
|
||||
"none_group": "None",
|
||||
"not_available": "Not available",
|
||||
"placement": "Placement",
|
||||
"place": "place",
|
||||
"played_matches": "Played Matches",
|
||||
"player_name": "Player name",
|
||||
"players": "Players",
|
||||
"players_count": "{count} Players",
|
||||
"point": "Point",
|
||||
"points": "Points",
|
||||
"privacy_policy": "Privacy Policy",
|
||||
@@ -418,12 +113,14 @@
|
||||
"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_placement": "Players can be arranged in an order, which reflects their placement.",
|
||||
"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",
|
||||
"select_winners": "Select Winners",
|
||||
"select_loser": "Select Loser",
|
||||
"selected_players": "Selected players",
|
||||
"settings": "Settings",
|
||||
@@ -436,6 +133,16 @@
|
||||
"statistics": "Statistics",
|
||||
"stats": "Stats",
|
||||
"successfully_added_player": "Successfully added player {playerName}",
|
||||
"@successfully_added_player": {
|
||||
"description": "Success message when adding a player",
|
||||
"placeholders": {
|
||||
"playerName": {
|
||||
"type": "String",
|
||||
"example": "John"
|
||||
}
|
||||
}
|
||||
},
|
||||
"there_are_no_games_matching_your_search": "There are no games matching your search",
|
||||
"there_is_no_group_matching_your_search": "There is no group matching your search",
|
||||
"this_cannot_be_undone": "This can't be undone.",
|
||||
"tie": "Tie",
|
||||
@@ -443,6 +150,7 @@
|
||||
"undo": "Undo",
|
||||
"unknown_exception": "Unknown Exception (see console)",
|
||||
"winner": "Winner",
|
||||
"winners": "Winners",
|
||||
"winrate": "Winrate",
|
||||
"wins": "Wins",
|
||||
"yesterday_at": "Yesterday at"
|
||||
|
||||
@@ -98,571 +98,709 @@ abstract class AppLocalizations {
|
||||
Locale('en'),
|
||||
];
|
||||
|
||||
/// Label for all players list
|
||||
/// No description provided for @all_players.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'All players'**
|
||||
String get all_players;
|
||||
|
||||
/// Message when all players are added to selection
|
||||
/// No description provided for @all_players_selected.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'All players selected'**
|
||||
String get all_players_selected;
|
||||
|
||||
/// Label for amount of matches statistic
|
||||
/// No description provided for @amount_of_matches.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Amount of Matches'**
|
||||
String get amount_of_matches;
|
||||
|
||||
/// The name of the App
|
||||
/// No description provided for @app_name.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Tallee'**
|
||||
String get app_name;
|
||||
|
||||
/// Label for best player statistic
|
||||
/// No description provided for @best_player.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Best Player'**
|
||||
String get best_player;
|
||||
|
||||
/// Cancel button text
|
||||
/// No description provided for @cancel.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Cancel'**
|
||||
String get cancel;
|
||||
|
||||
/// Label for choosing a game
|
||||
/// No description provided for @choose_color.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Choose Color'**
|
||||
String get choose_color;
|
||||
|
||||
/// No description provided for @choose_game.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Choose Game'**
|
||||
String get choose_game;
|
||||
|
||||
/// Label for choosing a group
|
||||
/// No description provided for @choose_group.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Choose Group'**
|
||||
String get choose_group;
|
||||
|
||||
/// Label for choosing a ruleset
|
||||
/// No description provided for @choose_ruleset.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Choose Ruleset'**
|
||||
String get choose_ruleset;
|
||||
|
||||
/// Error message when adding a player fails
|
||||
/// No description provided for @color.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Color'**
|
||||
String get color;
|
||||
|
||||
/// 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_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_purple.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Purple'**
|
||||
String get color_purple;
|
||||
|
||||
/// No description provided for @color_red.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Red'**
|
||||
String get color_red;
|
||||
|
||||
/// No description provided for @color_teal.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Teal'**
|
||||
String get color_teal;
|
||||
|
||||
/// No description provided for @color_yellow.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Yellow'**
|
||||
String get color_yellow;
|
||||
|
||||
/// No description provided for @could_not_add_player.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Could not add player'**
|
||||
String could_not_add_player(Object playerName);
|
||||
|
||||
/// Button text to create a group
|
||||
/// No description provided for @create_game.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Create Game'**
|
||||
String get create_game;
|
||||
|
||||
/// No description provided for @create_group.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Create Group'**
|
||||
String get create_group;
|
||||
|
||||
/// Button text to create a match
|
||||
/// No description provided for @create_match.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Create match'**
|
||||
String get create_match;
|
||||
|
||||
/// Appbar text to create a new group
|
||||
/// No description provided for @create_new_group.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Create new group'**
|
||||
String get create_new_group;
|
||||
|
||||
/// Label for creation date
|
||||
/// No description provided for @created_on.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Created on'**
|
||||
String get created_on;
|
||||
|
||||
/// Appbar text to create a new match
|
||||
/// No description provided for @create_new_match.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Create new match'**
|
||||
String get create_new_match;
|
||||
|
||||
/// Data label
|
||||
/// No description provided for @data.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Data'**
|
||||
String get data;
|
||||
|
||||
/// Success message after deleting data
|
||||
/// No description provided for @data_successfully_deleted.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Data successfully deleted'**
|
||||
String get data_successfully_deleted;
|
||||
|
||||
/// Success message after exporting data
|
||||
/// No description provided for @data_successfully_exported.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Data successfully exported'**
|
||||
String get data_successfully_exported;
|
||||
|
||||
/// Success message after importing data
|
||||
/// No description provided for @data_successfully_imported.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Data successfully imported'**
|
||||
String get data_successfully_imported;
|
||||
|
||||
/// Date format for days ago
|
||||
/// No description provided for @days_ago.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'{count} days ago'**
|
||||
String days_ago(int count);
|
||||
String days_ago(Object count);
|
||||
|
||||
/// Delete button text
|
||||
/// No description provided for @delete.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Delete'**
|
||||
String get delete;
|
||||
|
||||
/// Confirmation dialog for deleting all data
|
||||
/// No description provided for @delete_all_data.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Delete all data'**
|
||||
String get delete_all_data;
|
||||
|
||||
/// Confirmation dialog for deleting a group
|
||||
/// No description provided for @delete_game.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Delete Game'**
|
||||
String get delete_game;
|
||||
|
||||
/// No description provided for @delete_game_with_matches_warning.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'If you delete this game template, {count, plural, =1{1 match} other{{count} matches}} using this game template will also be deleted.'**
|
||||
String delete_game_with_matches_warning(int count);
|
||||
|
||||
/// No description provided for @delete_group.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Delete Group'**
|
||||
String get delete_group;
|
||||
|
||||
/// Button text to delete a match
|
||||
/// No description provided for @delete_match.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Delete Match'**
|
||||
String get delete_match;
|
||||
|
||||
/// Button & Appbar label for editing a group
|
||||
/// No description provided for @drag_to_set_placement.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Drag to set placement'**
|
||||
String get drag_to_set_placement;
|
||||
|
||||
/// 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;
|
||||
|
||||
/// No description provided for @edit_group.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Edit Group'**
|
||||
String get edit_group;
|
||||
|
||||
/// Button & Appbar label for editing a match
|
||||
/// No description provided for @edit_match.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Edit Match'**
|
||||
String get edit_match;
|
||||
|
||||
/// Label to enter players points
|
||||
/// No description provided for @enter_points.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Enter points'**
|
||||
String get enter_points;
|
||||
|
||||
/// Button text to enter match results
|
||||
/// No description provided for @enter_results.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Enter Results'**
|
||||
String get enter_results;
|
||||
|
||||
/// Error message when group creation fails
|
||||
/// No description provided for @error_creating_group.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Error while creating group, please try again'**
|
||||
String get error_creating_group;
|
||||
|
||||
/// Error message when group deletion fails
|
||||
/// No description provided for @error_deleting_game.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Error while deleting game, please try again'**
|
||||
String get error_deleting_game;
|
||||
|
||||
/// No description provided for @error_deleting_group.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Error while deleting group, please try again'**
|
||||
String get error_deleting_group;
|
||||
|
||||
/// Error message when group editing fails
|
||||
/// No description provided for @error_editing_group.
|
||||
///
|
||||
/// 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
|
||||
/// No description provided for @error_reading_file.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Error reading file'**
|
||||
String get error_reading_file;
|
||||
|
||||
/// Message when export is canceled
|
||||
/// No description provided for @exit_view.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Exit View'**
|
||||
String get exit_view;
|
||||
|
||||
/// No description provided for @export_canceled.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Export canceled'**
|
||||
String get export_canceled;
|
||||
|
||||
/// Export data menu item
|
||||
/// No description provided for @export_data.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Export data'**
|
||||
String get export_data;
|
||||
|
||||
/// Error message for format exceptions
|
||||
/// No description provided for @format_exception.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Format Exception (see console)'**
|
||||
String get format_exception;
|
||||
|
||||
/// Game label
|
||||
/// No description provided for @game.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Game'**
|
||||
String get game;
|
||||
|
||||
/// Placeholder for game name search
|
||||
/// No description provided for @game_name.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Game Name'**
|
||||
String get game_name;
|
||||
|
||||
/// Group label
|
||||
/// No description provided for @group.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Group'**
|
||||
String get group;
|
||||
|
||||
/// Placeholder for group name input
|
||||
/// No description provided for @group_name.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Group name'**
|
||||
String get group_name;
|
||||
|
||||
/// Title for group profile view
|
||||
/// No description provided for @group_profile.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Group Profile'**
|
||||
String get group_profile;
|
||||
|
||||
/// Label for groups
|
||||
/// No description provided for @groups.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Groups'**
|
||||
String get groups;
|
||||
|
||||
/// Home tab label
|
||||
/// No description provided for @home.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Home'**
|
||||
String get home;
|
||||
|
||||
/// Message when import is canceled
|
||||
/// No description provided for @import_canceled.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Import canceled'**
|
||||
String get import_canceled;
|
||||
|
||||
/// Import data menu item
|
||||
/// No description provided for @import_data.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Import data'**
|
||||
String get import_data;
|
||||
|
||||
/// Info label
|
||||
/// No description provided for @info.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Info'**
|
||||
String get info;
|
||||
|
||||
/// Error message for invalid schema
|
||||
/// No description provided for @invalid_schema.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Invalid Schema'**
|
||||
String get invalid_schema;
|
||||
|
||||
/// Title for least points ruleset
|
||||
/// No description provided for @least_points.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Least Points'**
|
||||
String get least_points;
|
||||
|
||||
/// Legal section header
|
||||
/// No description provided for @legal.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Legal'**
|
||||
String get legal;
|
||||
|
||||
/// Legal notice menu item
|
||||
/// No description provided for @legal_notice.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Legal Notice'**
|
||||
String get legal_notice;
|
||||
|
||||
/// Licenses menu item
|
||||
/// No description provided for @licenses.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Licenses'**
|
||||
String get licenses;
|
||||
|
||||
/// Message when match is in progress
|
||||
/// No description provided for @live_edit_mode.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Live Edit Mode'**
|
||||
String get live_edit_mode;
|
||||
|
||||
/// No description provided for @match_in_progress.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Match in progress...'**
|
||||
String get match_in_progress;
|
||||
|
||||
/// Placeholder for match name input
|
||||
/// No description provided for @match_name.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Match name'**
|
||||
String get match_name;
|
||||
|
||||
/// Title for match profile view
|
||||
/// No description provided for @match_profile.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Match Profile'**
|
||||
String get match_profile;
|
||||
|
||||
/// Label for matches
|
||||
/// No description provided for @matches.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Matches'**
|
||||
String get matches;
|
||||
|
||||
/// Label for group members
|
||||
/// No description provided for @members.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Members'**
|
||||
String get members;
|
||||
|
||||
/// Title for most points ruleset
|
||||
/// No description provided for @most_points.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Most Points'**
|
||||
String get most_points;
|
||||
|
||||
/// Message when no data in the statistic tiles is given
|
||||
/// No description provided for @no_data_available.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No data available'**
|
||||
String get no_data_available;
|
||||
|
||||
/// Message when no groups exist
|
||||
/// No description provided for @no_games_created_yet.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No games created yet'**
|
||||
String get no_games_created_yet;
|
||||
|
||||
/// No description provided for @no_groups_created_yet.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No groups created yet'**
|
||||
String get no_groups_created_yet;
|
||||
|
||||
/// Message when no licenses are found
|
||||
/// No description provided for @no_licenses_found.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No licenses found'**
|
||||
String get no_licenses_found;
|
||||
|
||||
/// Message when no license text is available
|
||||
/// No description provided for @no_license_text_available.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No license text available'**
|
||||
String get no_license_text_available;
|
||||
|
||||
/// Message when no matches exist
|
||||
/// No description provided for @no_matches_created_yet.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No matches created yet'**
|
||||
String get no_matches_created_yet;
|
||||
|
||||
/// Message when no players exist
|
||||
/// No description provided for @no_players_created_yet.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No players created yet'**
|
||||
String get no_players_created_yet;
|
||||
|
||||
/// Message when search returns no results
|
||||
/// No description provided for @no_players_found_with_that_name.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No players found with that name'**
|
||||
String get no_players_found_with_that_name;
|
||||
|
||||
/// Message when no players are selected
|
||||
/// No description provided for @no_players_selected.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No players selected'**
|
||||
String get no_players_selected;
|
||||
|
||||
/// Message when no recent matches exist
|
||||
/// No description provided for @no_recent_matches_available.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No recent matches available'**
|
||||
String get no_recent_matches_available;
|
||||
|
||||
/// Message when no results have been entered yet
|
||||
/// No description provided for @no_results_entered_yet.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No results entered yet'**
|
||||
String get no_results_entered_yet;
|
||||
|
||||
/// Message when no second match exists
|
||||
/// No description provided for @no_second_match_available.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No second match available'**
|
||||
String get no_second_match_available;
|
||||
|
||||
/// Message when no statistics are available, because no matches were played yet
|
||||
/// No description provided for @no_statistics_available.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'No statistics available'**
|
||||
String get no_statistics_available;
|
||||
|
||||
/// None option label
|
||||
/// No description provided for @none.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'None'**
|
||||
String get none;
|
||||
|
||||
/// None group option label
|
||||
/// No description provided for @none_group.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'None'**
|
||||
String get none_group;
|
||||
|
||||
/// Abbreviation for not available
|
||||
/// No description provided for @not_available.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Not available'**
|
||||
String get not_available;
|
||||
|
||||
/// Label for played matches statistic
|
||||
/// No description provided for @placement.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Placement'**
|
||||
String get placement;
|
||||
|
||||
/// No description provided for @place.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'place'**
|
||||
String get place;
|
||||
|
||||
/// No description provided for @played_matches.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Played Matches'**
|
||||
String get played_matches;
|
||||
|
||||
/// Placeholder for player name input
|
||||
/// No description provided for @player_name.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Player name'**
|
||||
String get player_name;
|
||||
|
||||
/// Players label
|
||||
/// No description provided for @players.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Players'**
|
||||
String get players;
|
||||
|
||||
/// Shows the number of players
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'{count} Players'**
|
||||
String players_count(int count);
|
||||
|
||||
/// No description provided for @point.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Point'**
|
||||
String get point;
|
||||
|
||||
/// Points label
|
||||
/// No description provided for @points.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Points'**
|
||||
String get points;
|
||||
|
||||
/// Privacy policy menu item
|
||||
/// No description provided for @privacy_policy.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Privacy Policy'**
|
||||
String get privacy_policy;
|
||||
|
||||
/// Title for quick create section
|
||||
/// No description provided for @quick_create.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Quick Create'**
|
||||
String get quick_create;
|
||||
|
||||
/// Title for recent matches section
|
||||
/// No description provided for @recent_matches.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Recent Matches'**
|
||||
String get recent_matches;
|
||||
|
||||
/// Label for match results
|
||||
/// No description provided for @results.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Results'**
|
||||
String get results;
|
||||
|
||||
/// Ruleset label
|
||||
/// No description provided for @ruleset.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Ruleset'**
|
||||
String get ruleset;
|
||||
|
||||
/// Description for least points ruleset
|
||||
/// No description provided for @ruleset_least_points.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Inverse scoring: the player with the fewest points wins.'**
|
||||
String get ruleset_least_points;
|
||||
|
||||
/// Description for most points ruleset
|
||||
/// No description provided for @ruleset_most_points.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Traditional ruleset: the player with the most points wins.'**
|
||||
String get ruleset_most_points;
|
||||
|
||||
/// Description for single loser ruleset
|
||||
/// No description provided for @ruleset_placement.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Players can be arranged in an order, which reflects their placement.'**
|
||||
String get ruleset_placement;
|
||||
|
||||
/// No description provided for @ruleset_single_loser.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Exactly one loser is determined; last place receives the penalty or consequence.'**
|
||||
String get ruleset_single_loser;
|
||||
|
||||
/// Description for single winner ruleset
|
||||
/// No description provided for @ruleset_single_winner.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Exactly one winner is chosen; ties are resolved by a predefined tiebreaker.'**
|
||||
String get ruleset_single_winner;
|
||||
|
||||
/// Save changes button text
|
||||
/// No description provided for @save_changes.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Save Changes'**
|
||||
String get save_changes;
|
||||
|
||||
/// Hint text for group search input field
|
||||
/// No description provided for @search_for_groups.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Search for groups'**
|
||||
String get search_for_groups;
|
||||
|
||||
/// Hint text for player search input field
|
||||
/// No description provided for @search_for_players.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Search for players'**
|
||||
String get search_for_players;
|
||||
|
||||
/// Label to select the winner
|
||||
/// No description provided for @select_winner.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Select Winner'**
|
||||
String get select_winner;
|
||||
|
||||
/// Label to select the loser
|
||||
/// No description provided for @select_winners.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Select Winners'**
|
||||
String get select_winners;
|
||||
|
||||
/// No description provided for @select_loser.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Select Loser'**
|
||||
String get select_loser;
|
||||
|
||||
/// Shows the number of selected players
|
||||
/// No description provided for @selected_players.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Selected players'**
|
||||
String get selected_players;
|
||||
|
||||
/// Label for the App Settings
|
||||
/// No description provided for @settings.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Settings'**
|
||||
String get settings;
|
||||
|
||||
/// Title for single loser ruleset
|
||||
/// No description provided for @single_loser.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Single Loser'**
|
||||
String get single_loser;
|
||||
|
||||
/// Title for single winner ruleset
|
||||
/// No description provided for @single_winner.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Single Winner'**
|
||||
@@ -692,13 +830,13 @@ abstract class AppLocalizations {
|
||||
/// **'Multiple Winners'**
|
||||
String get multiple_winners;
|
||||
|
||||
/// Statistics tab label
|
||||
/// No description provided for @statistics.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Statistics'**
|
||||
String get statistics;
|
||||
|
||||
/// Stats tab label (short)
|
||||
/// No description provided for @stats.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Stats'**
|
||||
@@ -710,13 +848,19 @@ abstract class AppLocalizations {
|
||||
/// **'Successfully added player {playerName}'**
|
||||
String successfully_added_player(String playerName);
|
||||
|
||||
/// Message when search returns no groups
|
||||
/// No description provided for @there_are_no_games_matching_your_search.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'There are no games matching your search'**
|
||||
String get there_are_no_games_matching_your_search;
|
||||
|
||||
/// No description provided for @there_is_no_group_matching_your_search.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'There is no group matching your search'**
|
||||
String get there_is_no_group_matching_your_search;
|
||||
|
||||
/// Warning message for irreversible actions
|
||||
/// No description provided for @this_cannot_be_undone.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'This can\'t be undone.'**
|
||||
@@ -728,43 +872,49 @@ abstract class AppLocalizations {
|
||||
/// **'Tie'**
|
||||
String get tie;
|
||||
|
||||
/// Date format for today
|
||||
/// No description provided for @today_at.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Today at'**
|
||||
String get today_at;
|
||||
|
||||
/// Undo button text
|
||||
/// No description provided for @undo.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Undo'**
|
||||
String get undo;
|
||||
|
||||
/// Error message for unknown exceptions
|
||||
/// No description provided for @unknown_exception.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Unknown Exception (see console)'**
|
||||
String get unknown_exception;
|
||||
|
||||
/// Winner label
|
||||
/// No description provided for @winner.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Winner'**
|
||||
String get winner;
|
||||
|
||||
/// Label for winrate statistic
|
||||
/// No description provided for @winners.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Winners'**
|
||||
String get winners;
|
||||
|
||||
/// No description provided for @winrate.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Winrate'**
|
||||
String get winrate;
|
||||
|
||||
/// Label for wins statistic
|
||||
/// No description provided for @wins.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Wins'**
|
||||
String get wins;
|
||||
|
||||
/// Date format for yesterday
|
||||
/// No description provided for @yesterday_at.
|
||||
///
|
||||
/// In en, this message translates to:
|
||||
/// **'Yesterday at'**
|
||||
|
||||
@@ -26,6 +26,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get cancel => 'Abbrechen';
|
||||
|
||||
@override
|
||||
String get choose_color => 'Farbe wählen';
|
||||
|
||||
@override
|
||||
String get choose_game => 'Spielvorlage wählen';
|
||||
|
||||
@@ -35,11 +38,41 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get choose_ruleset => 'Regelwerk wählen';
|
||||
|
||||
@override
|
||||
String get color => 'Farbe';
|
||||
|
||||
@override
|
||||
String get color_blue => 'Blau';
|
||||
|
||||
@override
|
||||
String get color_green => 'Grün';
|
||||
|
||||
@override
|
||||
String get color_orange => 'Orange';
|
||||
|
||||
@override
|
||||
String get color_pink => 'Rosa';
|
||||
|
||||
@override
|
||||
String get color_purple => 'Lila';
|
||||
|
||||
@override
|
||||
String get color_red => 'Rot';
|
||||
|
||||
@override
|
||||
String get color_teal => 'Türkis';
|
||||
|
||||
@override
|
||||
String get color_yellow => 'Gelb';
|
||||
|
||||
@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';
|
||||
|
||||
@@ -68,7 +101,7 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
String get data_successfully_imported => 'Daten erfolgreich importiert';
|
||||
|
||||
@override
|
||||
String days_ago(int count) {
|
||||
String days_ago(Object count) {
|
||||
return 'vor $count Tagen';
|
||||
}
|
||||
|
||||
@@ -78,12 +111,35 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get delete_all_data => 'Alle Daten löschen';
|
||||
|
||||
@override
|
||||
String get delete_game => 'Spielvorlage löschen';
|
||||
|
||||
@override
|
||||
String delete_game_with_matches_warning(int count) {
|
||||
String _temp0 = intl.Intl.pluralLogic(
|
||||
count,
|
||||
locale: localeName,
|
||||
other: 'werden $count Spiele',
|
||||
one: 'wird 1 Spiel',
|
||||
);
|
||||
return 'Wenn du diese Spielvorlage löschst, $_temp0 mit dieser Spielvorlage ebenfalls gelöscht.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get delete_group => 'Gruppe löschen';
|
||||
|
||||
@override
|
||||
String get delete_match => 'Spiel löschen';
|
||||
|
||||
@override
|
||||
String get drag_to_set_placement => 'Ziehen um Platzierung zu setzen';
|
||||
|
||||
@override
|
||||
String get description => 'Beschreibung';
|
||||
|
||||
@override
|
||||
String get edit_game => 'Spielvorlage bearbeiten';
|
||||
|
||||
@override
|
||||
String get edit_group => 'Gruppe bearbeiten';
|
||||
|
||||
@@ -100,6 +156,10 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
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';
|
||||
@@ -111,6 +171,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get error_reading_file => 'Fehler beim Lesen der Datei';
|
||||
|
||||
@override
|
||||
String get exit_view => 'Ansicht verlassen';
|
||||
|
||||
@override
|
||||
String get export_canceled => 'Export abgebrochen';
|
||||
|
||||
@@ -165,6 +228,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get licenses => 'Lizenzen';
|
||||
|
||||
@override
|
||||
String get live_edit_mode => 'Live-Bearbeitungsmodus';
|
||||
|
||||
@override
|
||||
String get match_in_progress => 'Spiel läuft...';
|
||||
|
||||
@@ -186,6 +252,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get no_data_available => 'Keine Daten verfügbar';
|
||||
|
||||
@override
|
||||
String get no_games_created_yet => 'Noch keine Spielvorlagen erstellt';
|
||||
|
||||
@override
|
||||
String get no_groups_created_yet => 'Noch keine Gruppen erstellt';
|
||||
|
||||
@@ -229,6 +298,12 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get not_available => 'Nicht verfügbar';
|
||||
|
||||
@override
|
||||
String get placement => 'Platzierung';
|
||||
|
||||
@override
|
||||
String get place => 'Platz';
|
||||
|
||||
@override
|
||||
String get played_matches => 'Gespielte Spiele';
|
||||
|
||||
@@ -238,11 +313,6 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get players => 'Spieler:innen';
|
||||
|
||||
@override
|
||||
String players_count(int count) {
|
||||
return '$count Spieler';
|
||||
}
|
||||
|
||||
@override
|
||||
String get point => 'Punkt';
|
||||
|
||||
@@ -272,6 +342,10 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
String get ruleset_most_points =>
|
||||
'Traditionelles Regelwerk: Der/die Spieler:in mit den meisten Punkten gewinnt.';
|
||||
|
||||
@override
|
||||
String get ruleset_placement =>
|
||||
'Spieler:innen können in einer Reihenfolge angeordnet werden, die ihre Platzierung reflektiert.';
|
||||
|
||||
@override
|
||||
String get ruleset_single_loser =>
|
||||
'Genau ein:e Verlierer:in wird bestimmt; der letzte Platz erhält die Strafe oder Konsequenz.';
|
||||
@@ -292,6 +366,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get select_winner => 'Gewinner:in wählen';
|
||||
|
||||
@override
|
||||
String get select_winners => 'Gewinner:innen wählen';
|
||||
|
||||
@override
|
||||
String get select_loser => 'Verlierer:in wählen';
|
||||
|
||||
@@ -330,6 +407,10 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
return 'Spieler:in $playerName erfolgreich hinzugefügt';
|
||||
}
|
||||
|
||||
@override
|
||||
String get there_are_no_games_matching_your_search =>
|
||||
'Es gibt keine Spielvorlagen, die deiner Suche entspricht';
|
||||
|
||||
@override
|
||||
String get there_is_no_group_matching_your_search =>
|
||||
'Es gibt keine Gruppe, die deiner Suche entspricht';
|
||||
@@ -353,6 +434,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
||||
@override
|
||||
String get winner => 'Gewinner:in';
|
||||
|
||||
@override
|
||||
String get winners => 'Gewinner:innen';
|
||||
|
||||
@override
|
||||
String get winrate => 'Siegquote';
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get cancel => 'Cancel';
|
||||
|
||||
@override
|
||||
String get choose_color => 'Choose Color';
|
||||
|
||||
@override
|
||||
String get choose_game => 'Choose Game';
|
||||
|
||||
@@ -35,11 +38,41 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get choose_ruleset => 'Choose Ruleset';
|
||||
|
||||
@override
|
||||
String get color => 'Color';
|
||||
|
||||
@override
|
||||
String get color_blue => 'Blue';
|
||||
|
||||
@override
|
||||
String get color_green => 'Green';
|
||||
|
||||
@override
|
||||
String get color_orange => 'Orange';
|
||||
|
||||
@override
|
||||
String get color_pink => 'Pink';
|
||||
|
||||
@override
|
||||
String get color_purple => 'Purple';
|
||||
|
||||
@override
|
||||
String get color_red => 'Red';
|
||||
|
||||
@override
|
||||
String get color_teal => 'Teal';
|
||||
|
||||
@override
|
||||
String get color_yellow => 'Yellow';
|
||||
|
||||
@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';
|
||||
|
||||
@@ -68,7 +101,7 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get data_successfully_imported => 'Data successfully imported';
|
||||
|
||||
@override
|
||||
String days_ago(int count) {
|
||||
String days_ago(Object count) {
|
||||
return '$count days ago';
|
||||
}
|
||||
|
||||
@@ -78,12 +111,35 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get delete_all_data => 'Delete all data';
|
||||
|
||||
@override
|
||||
String get delete_game => 'Delete Game';
|
||||
|
||||
@override
|
||||
String delete_game_with_matches_warning(int count) {
|
||||
String _temp0 = intl.Intl.pluralLogic(
|
||||
count,
|
||||
locale: localeName,
|
||||
other: '$count matches',
|
||||
one: '1 match',
|
||||
);
|
||||
return 'If you delete this game template, $_temp0 using this game template will also be deleted.';
|
||||
}
|
||||
|
||||
@override
|
||||
String get delete_group => 'Delete Group';
|
||||
|
||||
@override
|
||||
String get delete_match => 'Delete Match';
|
||||
|
||||
@override
|
||||
String get drag_to_set_placement => 'Drag to set placement';
|
||||
|
||||
@override
|
||||
String get description => 'Description';
|
||||
|
||||
@override
|
||||
String get edit_game => 'Edit Game';
|
||||
|
||||
@override
|
||||
String get edit_group => 'Edit Group';
|
||||
|
||||
@@ -100,6 +156,10 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
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';
|
||||
@@ -111,6 +171,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get error_reading_file => 'Error reading file';
|
||||
|
||||
@override
|
||||
String get exit_view => 'Exit View';
|
||||
|
||||
@override
|
||||
String get export_canceled => 'Export canceled';
|
||||
|
||||
@@ -165,6 +228,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get licenses => 'Licenses';
|
||||
|
||||
@override
|
||||
String get live_edit_mode => 'Live Edit Mode';
|
||||
|
||||
@override
|
||||
String get match_in_progress => 'Match in progress...';
|
||||
|
||||
@@ -186,6 +252,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get no_data_available => 'No data available';
|
||||
|
||||
@override
|
||||
String get no_games_created_yet => 'No games created yet';
|
||||
|
||||
@override
|
||||
String get no_groups_created_yet => 'No groups created yet';
|
||||
|
||||
@@ -229,6 +298,12 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get not_available => 'Not available';
|
||||
|
||||
@override
|
||||
String get placement => 'Placement';
|
||||
|
||||
@override
|
||||
String get place => 'place';
|
||||
|
||||
@override
|
||||
String get played_matches => 'Played Matches';
|
||||
|
||||
@@ -238,11 +313,6 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get players => 'Players';
|
||||
|
||||
@override
|
||||
String players_count(int count) {
|
||||
return '$count Players';
|
||||
}
|
||||
|
||||
@override
|
||||
String get point => 'Point';
|
||||
|
||||
@@ -272,6 +342,10 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
String get ruleset_most_points =>
|
||||
'Traditional ruleset: the player with the most points wins.';
|
||||
|
||||
@override
|
||||
String get ruleset_placement =>
|
||||
'Players can be arranged in an order, which reflects their placement.';
|
||||
|
||||
@override
|
||||
String get ruleset_single_loser =>
|
||||
'Exactly one loser is determined; last place receives the penalty or consequence.';
|
||||
@@ -292,6 +366,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get select_winner => 'Select Winner';
|
||||
|
||||
@override
|
||||
String get select_winners => 'Select Winners';
|
||||
|
||||
@override
|
||||
String get select_loser => 'Select Loser';
|
||||
|
||||
@@ -330,6 +407,10 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
return 'Successfully added player $playerName';
|
||||
}
|
||||
|
||||
@override
|
||||
String get there_are_no_games_matching_your_search =>
|
||||
'There are no games matching your search';
|
||||
|
||||
@override
|
||||
String get there_is_no_group_matching_your_search =>
|
||||
'There is no group matching your search';
|
||||
@@ -352,6 +433,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
||||
@override
|
||||
String get winner => 'Winner';
|
||||
|
||||
@override
|
||||
String get winners => 'Winners';
|
||||
|
||||
@override
|
||||
String get winrate => 'Winrate';
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ 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/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';
|
||||
import 'package:tallee/presentation/views/main_menu/statistics_view.dart';
|
||||
@@ -31,7 +30,6 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
||||
final loc = AppLocalizations.of(context);
|
||||
// Pretty ugly but works
|
||||
final List<Widget> tabs = [
|
||||
KeyedSubtree(key: ValueKey('home_$tabKeyCount'), child: const HomeView()),
|
||||
KeyedSubtree(
|
||||
key: ValueKey('matches_$tabKeyCount'),
|
||||
child: const MatchView(),
|
||||
@@ -101,27 +99,20 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
||||
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,
|
||||
index: 1,
|
||||
isSelected: currentIndex == 1,
|
||||
icon: Icons.group_rounded,
|
||||
label: loc.groups,
|
||||
onTabTapped: onTabTapped,
|
||||
),
|
||||
NavbarItem(
|
||||
index: 3,
|
||||
isSelected: currentIndex == 3,
|
||||
index: 2,
|
||||
isSelected: currentIndex == 2,
|
||||
icon: Icons.bar_chart_rounded,
|
||||
label: loc.statistics,
|
||||
onTabTapped: onTabTapped,
|
||||
@@ -145,12 +136,10 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
||||
final loc = AppLocalizations.of(context);
|
||||
switch (currentIndex) {
|
||||
case 0:
|
||||
return loc.home;
|
||||
case 1:
|
||||
return loc.matches;
|
||||
case 2:
|
||||
case 1:
|
||||
return loc.groups;
|
||||
case 3:
|
||||
case 2:
|
||||
return loc.statistics;
|
||||
default:
|
||||
return '';
|
||||
|
||||
@@ -172,12 +172,12 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
if (widget.groupToEdit!.name != groupName) {
|
||||
successfullNameChange = await db.groupDao.updateGroupName(
|
||||
groupId: widget.groupToEdit!.id,
|
||||
newName: groupName,
|
||||
name: groupName,
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.groupToEdit!.members != selectedPlayers) {
|
||||
successfullMemberChange = await db.groupDao.replaceGroupPlayers(
|
||||
successfullMemberChange = await db.playerGroupDao.replaceGroupPlayers(
|
||||
groupId: widget.groupToEdit!.id,
|
||||
newPlayers: selectedPlayers,
|
||||
);
|
||||
@@ -197,7 +197,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
/// obsolete. For each such match, the group association is removed by setting
|
||||
/// its [groupId] to null.
|
||||
Future<void> deleteObsoleteMatchGroupRelations() async {
|
||||
final groupMatches = await db.matchDao.getGroupMatches(
|
||||
final groupMatches = await db.matchDao.getMatchesByGroup(
|
||||
groupId: widget.groupToEdit!.id,
|
||||
);
|
||||
|
||||
|
||||
@@ -244,7 +244,9 @@ class _GroupDetailViewState extends State<GroupDetailView> {
|
||||
/// Loads statistics for this group
|
||||
Future<void> _loadStatistics() async {
|
||||
isLoading = true;
|
||||
final groupMatches = await db.matchDao.getGroupMatches(groupId: _group.id);
|
||||
final groupMatches = await db.matchDao.getMatchesByGroup(
|
||||
groupId: _group.id,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
totalMatches = groupMatches.length;
|
||||
|
||||
@@ -1,259 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
import 'package:tallee/core/constants.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/match_result_view.dart';
|
||||
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/quick_create_button.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/info_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/match_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/quick_info_tile.dart';
|
||||
|
||||
class HomeView extends StatefulWidget {
|
||||
/// The main home view of the application, displaying quick info,
|
||||
/// recent matches, and quick create options.
|
||||
const HomeView({super.key});
|
||||
|
||||
@override
|
||||
State<HomeView> createState() => _HomeViewState();
|
||||
}
|
||||
|
||||
class _HomeViewState extends State<HomeView> {
|
||||
bool isLoading = true;
|
||||
|
||||
/// Amount of matches in the database
|
||||
int matchCount = 0;
|
||||
|
||||
/// Amount of groups in the database
|
||||
int groupCount = 0;
|
||||
|
||||
/// Loaded recent matches from the database
|
||||
List<Match> loadedRecentMatches = [];
|
||||
|
||||
/// Recent matches to display, initially filled with skeleton matches
|
||||
List<Match> recentMatches = List.filled(
|
||||
2,
|
||||
Match(
|
||||
name: 'Skeleton Match',
|
||||
game: Game(
|
||||
name: 'Skeleton Game',
|
||||
ruleset: Ruleset.singleWinner,
|
||||
description: 'This is a skeleton game description.',
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
),
|
||||
group: Group(
|
||||
name: 'Skeleton Group',
|
||||
description: 'This is a skeleton group description.',
|
||||
members: [
|
||||
Player(
|
||||
name:
|
||||
'Skeleton Player 1'
|
||||
'',
|
||||
),
|
||||
Player(
|
||||
name:
|
||||
'Skeleton Player 2'
|
||||
'',
|
||||
),
|
||||
],
|
||||
),
|
||||
notes: 'These are skeleton notes.',
|
||||
players: [
|
||||
Player(
|
||||
name:
|
||||
'Skeleton Player 1'
|
||||
'',
|
||||
),
|
||||
Player(
|
||||
name:
|
||||
'Skeleton Player 2'
|
||||
'',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loadHomeViewData();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
return LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
return AppSkeleton(
|
||||
fixLayoutBuilder: true,
|
||||
enabled: isLoading,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
QuickInfoTile(
|
||||
width: constraints.maxWidth * 0.45,
|
||||
height: constraints.maxHeight * 0.15,
|
||||
title: loc.matches,
|
||||
icon: Icons.groups_rounded,
|
||||
value: matchCount,
|
||||
),
|
||||
SizedBox(width: constraints.maxWidth * 0.05),
|
||||
QuickInfoTile(
|
||||
width: constraints.maxWidth * 0.45,
|
||||
height: constraints.maxHeight * 0.15,
|
||||
title: loc.groups,
|
||||
icon: Icons.groups_rounded,
|
||||
value: groupCount,
|
||||
),
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||
child: InfoTile(
|
||||
width: constraints.maxWidth * 0.95,
|
||||
title: loc.recent_matches,
|
||||
icon: Icons.history_rounded,
|
||||
content: Column(
|
||||
children: [
|
||||
if (recentMatches.isNotEmpty)
|
||||
for (Match match in recentMatches)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 6.0,
|
||||
),
|
||||
child: MatchTile(
|
||||
compact: true,
|
||||
width: constraints.maxWidth * 0.9,
|
||||
match: match,
|
||||
onTap: () async {
|
||||
await Navigator.of(context).push(
|
||||
adaptivePageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (context) =>
|
||||
MatchResultView(match: match),
|
||||
),
|
||||
);
|
||||
await loadRecentMatches();
|
||||
|
||||
setState(() {
|
||||
print('loaded');
|
||||
});
|
||||
},
|
||||
),
|
||||
)
|
||||
else
|
||||
Center(
|
||||
heightFactor: 5,
|
||||
child: Text(loc.no_recent_matches_available),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.zero,
|
||||
child: InfoTile(
|
||||
width: constraints.maxWidth * 0.95,
|
||||
title: loc.quick_create,
|
||||
icon: Icons.add_box_rounded,
|
||||
content: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
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: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
QuickCreateButton(
|
||||
text: 'Category 5',
|
||||
onPressed: () {},
|
||||
),
|
||||
QuickCreateButton(
|
||||
text: 'Category 6',
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(height: MediaQuery.paddingOf(context).bottom),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Loads the data for the HomeView from the database.
|
||||
/// This includes the match count, group count, and recent matches.
|
||||
Future<void> loadHomeViewData() async {
|
||||
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||
Future.wait([
|
||||
db.matchDao.getMatchCount(),
|
||||
db.groupDao.getGroupCount(),
|
||||
db.matchDao.getAllMatches(),
|
||||
Future.delayed(Constants.MINIMUM_SKELETON_DURATION),
|
||||
]).then((results) {
|
||||
matchCount = results[0] as int;
|
||||
groupCount = results[1] as int;
|
||||
loadedRecentMatches = results[2] as List<Match>;
|
||||
recentMatches =
|
||||
(loadedRecentMatches
|
||||
..sort((a, b) => b.createdAt.compareTo(a.createdAt)))
|
||||
.take(2)
|
||||
.toList();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> loadRecentMatches() async {
|
||||
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||
final matches = await db.matchDao.getAllMatches();
|
||||
recentMatches =
|
||||
(matches..sort((a, b) => b.createdAt.compareTo(a.createdAt)))
|
||||
.take(2)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,26 @@
|
||||
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/custom_theme.dart';
|
||||
import 'package:tallee/data/db/database.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/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';
|
||||
import 'package:tallee/presentation/widgets/tiles/game_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/top_centered_message.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
|
||||
/// - [initialGameId]: 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.initialGameId,
|
||||
this.onGamesUpdated,
|
||||
});
|
||||
|
||||
/// A list of tuples containing the game name, description and ruleset
|
||||
@@ -22,20 +29,37 @@ class ChooseGameView extends StatefulWidget {
|
||||
/// The id of the initially selected game
|
||||
final String initialGameId;
|
||||
|
||||
/// Optional callback invoked when the games are updated
|
||||
final VoidCallback? onGamesUpdated;
|
||||
|
||||
@override
|
||||
State<ChooseGameView> createState() => _ChooseGameViewState();
|
||||
}
|
||||
|
||||
class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
late final AppDatabase db;
|
||||
|
||||
late List<(Game, int)> gameCounts = [];
|
||||
|
||||
/// Controller for the search bar
|
||||
final TextEditingController searchBarController = TextEditingController();
|
||||
|
||||
/// Currently selected game index
|
||||
late String selectedGameId;
|
||||
|
||||
/// Games filtered according to the current search query
|
||||
late List<Game> filteredGames;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
fetchGameCounts();
|
||||
|
||||
selectedGameId = widget.initialGameId;
|
||||
|
||||
// Start with all games visible
|
||||
filteredGames = List<Game>.from(widget.games);
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -58,6 +82,30 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
);
|
||||
},
|
||||
),
|
||||
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(
|
||||
@@ -72,37 +120,101 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
// Search Bar
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: CustomSearchBar(
|
||||
controller: searchBarController,
|
||||
hintText: loc.game_name,
|
||||
onChanged: (value) {
|
||||
_applySearchFilter(value);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
|
||||
// Game list
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: widget.games.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return TitleDescriptionListTile(
|
||||
title: widget.games[index].name,
|
||||
description: widget.games[index].description,
|
||||
badgeText: translateRulesetToString(
|
||||
widget.games[index].ruleset,
|
||||
child: Visibility(
|
||||
visible: filteredGames.isNotEmpty,
|
||||
replacement: Visibility(
|
||||
visible: widget.games.isNotEmpty,
|
||||
replacement: TopCenteredMessage(
|
||||
icon: Icons.info,
|
||||
title: loc.info,
|
||||
message: loc.no_games_created_yet,
|
||||
),
|
||||
child: TopCenteredMessage(
|
||||
icon: Icons.info,
|
||||
title: loc.info,
|
||||
message: AppLocalizations.of(
|
||||
context,
|
||||
),
|
||||
isHighlighted: selectedGameId == widget.games[index].id,
|
||||
onPressed: () async {
|
||||
setState(() {
|
||||
if (selectedGameId != widget.games[index].id) {
|
||||
selectedGameId = widget.games[index].id;
|
||||
} else {
|
||||
selectedGameId = '';
|
||||
).there_are_no_games_matching_your_search,
|
||||
),
|
||||
),
|
||||
child: ListView.builder(
|
||||
itemCount: filteredGames.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final game = filteredGames[index];
|
||||
return GameTile(
|
||||
title: game.name,
|
||||
description: game.description,
|
||||
badgeText: translateRulesetToString(
|
||||
game.ruleset,
|
||||
context,
|
||||
),
|
||||
badgeColor: getColorFromGameColor(game.color),
|
||||
isHighlighted: selectedGameId == game.id,
|
||||
onTap: () async {
|
||||
setState(() {
|
||||
if (selectedGameId == game.id) {
|
||||
selectedGameId = '';
|
||||
} else {
|
||||
selectedGameId = game.id;
|
||||
}
|
||||
});
|
||||
},
|
||||
onLongPress: () async {
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) => CreateGameView(
|
||||
gameToEdit: game,
|
||||
matchCount: getMatchCount(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(() {
|
||||
// deselect the game
|
||||
if (selectedGameId == game.id) {
|
||||
selectedGameId = '';
|
||||
}
|
||||
widget.games.removeAt(originalIndex);
|
||||
widget.onGamesUpdated?.call();
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
widget.games[originalIndex] = result.game;
|
||||
});
|
||||
}
|
||||
_refreshFromSource();
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -110,4 +222,39 @@ 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);
|
||||
}
|
||||
|
||||
Future<void> fetchGameCounts() async {
|
||||
gameCounts = await db.gameDao.getGameUsage();
|
||||
}
|
||||
|
||||
// Returns the number of matches that use the given [game].
|
||||
int getMatchCount(Game game) {
|
||||
return gameCounts
|
||||
.firstWhere((gc) => gc.$1.id == game.id, orElse: () => (game, 0))
|
||||
.$2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,505 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_popup/flutter_popup.dart';
|
||||
import 'package:provider/provider.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/models/game.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/custom_width_button.dart';
|
||||
import 'package:tallee/presentation/widgets/dialog/custom_alert_dialog.dart';
|
||||
import 'package:tallee/presentation/widgets/dialog/custom_dialog_action.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,
|
||||
required this.onGameChanged,
|
||||
this.gameToEdit,
|
||||
this.matchCount = 0,
|
||||
});
|
||||
|
||||
/// Callback to invoke when the game is created or edited
|
||||
final VoidCallback onGameChanged;
|
||||
|
||||
/// An optional game to prefill the fields
|
||||
final Game? gameToEdit;
|
||||
|
||||
final int matchCount;
|
||||
|
||||
@override
|
||||
State<CreateGameView> createState() => _CreateGameViewState();
|
||||
}
|
||||
|
||||
class _CreateGameViewState extends State<CreateGameView> {
|
||||
/// GlobalKey for ScaffoldMessenger to show snackbars
|
||||
final _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
|
||||
|
||||
late final AppDatabase db;
|
||||
|
||||
late List<(Ruleset, String)> _rulesets;
|
||||
late List<(GameColor, String)> _colors;
|
||||
|
||||
Ruleset? selectedRuleset = Ruleset.singleWinner;
|
||||
GameColor? selectedColor = GameColor.orange;
|
||||
|
||||
/// 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 = List.generate(
|
||||
Ruleset.values.length,
|
||||
(index) => (
|
||||
Ruleset.values[index],
|
||||
translateRulesetToString(Ruleset.values[index], context),
|
||||
),
|
||||
);
|
||||
_colors = List.generate(
|
||||
GameColor.values.length,
|
||||
(index) => (
|
||||
GameColor.values[index],
|
||||
translateGameColorToString(GameColor.values[index], context),
|
||||
),
|
||||
);
|
||||
|
||||
if (widget.gameToEdit != null) {
|
||||
_gameNameController.text = widget.gameToEdit!.name;
|
||||
_descriptionController.text = widget.gameToEdit!.description;
|
||||
selectedRuleset = widget.gameToEdit!.ruleset;
|
||||
selectedColor = widget.gameToEdit!.color;
|
||||
selectedRuleset = widget.gameToEdit!.ruleset;
|
||||
}
|
||||
}
|
||||
|
||||
@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: [
|
||||
if (isEditMode())
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
if (!context.mounted) return;
|
||||
|
||||
// Build the dialog content based on match count
|
||||
final String dialogContent = widget.matchCount > 0
|
||||
? loc.delete_game_with_matches_warning(widget.matchCount)
|
||||
: loc.this_cannot_be_undone;
|
||||
|
||||
showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => CustomAlertDialog(
|
||||
title: loc.delete_game,
|
||||
content: Text(
|
||||
dialogContent,
|
||||
style: const TextStyle(fontSize: 15),
|
||||
),
|
||||
actions: [
|
||||
CustomDialogAction(
|
||||
isDestructive: true,
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
text: loc.delete,
|
||||
),
|
||||
CustomDialogAction(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
buttonType: ButtonType.secondary,
|
||||
text: loc.cancel,
|
||||
),
|
||||
],
|
||||
),
|
||||
).then((confirmed) async {
|
||||
if (confirmed == true && context.mounted) {
|
||||
// Delete assocaited matches
|
||||
if (widget.matchCount > 0) {
|
||||
await db.matchDao.deleteMatchesByGame(
|
||||
gameId: widget.gameToEdit!.id,
|
||||
);
|
||||
}
|
||||
|
||||
// Delete the targetted game
|
||||
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: [
|
||||
// Game name input field
|
||||
Container(
|
||||
margin: CustomTheme.tileMargin,
|
||||
child: TextInputField(
|
||||
controller: _gameNameController,
|
||||
maxLength: Constants.MAX_MATCH_NAME_LENGTH,
|
||||
hintText: loc.game_name,
|
||||
),
|
||||
),
|
||||
|
||||
// Choose ruleset tile
|
||||
if (!isEditMode())
|
||||
ChooseTile(
|
||||
title: loc.ruleset,
|
||||
trailing: getRulesetDropdown(loc),
|
||||
),
|
||||
|
||||
// Choose color tile
|
||||
ChooseTile(title: loc.color, trailing: getColorDropdown(loc)),
|
||||
|
||||
// Description input field
|
||||
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(),
|
||||
|
||||
// Create/Edit game button
|
||||
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 &&
|
||||
selectedRuleset != null &&
|
||||
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, name: newGame.name);
|
||||
}
|
||||
|
||||
if (oldGame.description != newGame.description) {
|
||||
await db.gameDao.updateGameDescription(
|
||||
gameId: oldGame.id,
|
||||
description: newGame.description,
|
||||
);
|
||||
}
|
||||
|
||||
if (oldGame.ruleset != newGame.ruleset) {
|
||||
await db.gameDao.updateGameRuleset(
|
||||
gameId: oldGame.id,
|
||||
ruleset: newGame.ruleset,
|
||||
);
|
||||
}
|
||||
|
||||
if (oldGame.color != newGame.color) {
|
||||
await db.gameDao.updateGameColor(
|
||||
gameId: oldGame.id,
|
||||
color: newGame.color,
|
||||
);
|
||||
}
|
||||
|
||||
if (oldGame.icon != newGame.icon) {
|
||||
await db.gameDao.updateGameIcon(gameId: oldGame.id, icon: 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,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool isEditMode() {
|
||||
return widget.gameToEdit != null;
|
||||
}
|
||||
|
||||
Widget getRulesetDropdown(AppLocalizations loc) {
|
||||
return CustomPopup(
|
||||
showArrow: true,
|
||||
arrowColor: CustomTheme.boxBorderColor,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 0, vertical: 10),
|
||||
barrierColor: Colors.transparent,
|
||||
contentDecoration: CustomTheme.standardBoxDecoration,
|
||||
content: StatefulBuilder(
|
||||
builder: (context, setPopupState) => SizedBox(
|
||||
width: 280,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: List.generate(
|
||||
_rulesets.length,
|
||||
(index) => GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selectedRuleset = _rulesets[index].$1;
|
||||
});
|
||||
setPopupState(() {});
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(8),
|
||||
),
|
||||
color: selectedRuleset == _rulesets[index].$1
|
||||
? CustomTheme.textColor.withAlpha(20)
|
||||
: Colors.transparent,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 8,
|
||||
horizontal: 16,
|
||||
),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
Icon(getRulesetIcon(_rulesets[index].$1), size: 16),
|
||||
Text(
|
||||
_rulesets[index].$2,
|
||||
style: const TextStyle(
|
||||
color: CustomTheme.textColor,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (index < _rulesets.length - 1)
|
||||
const Divider(indent: 15, endIndent: 15),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
Icon(getRulesetIcon(selectedRuleset!), size: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 5),
|
||||
child: Text(
|
||||
translateRulesetToString(selectedRuleset!, context),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
),
|
||||
Transform.rotate(
|
||||
angle: pi / 2,
|
||||
child: const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getColorDropdown(AppLocalizations loc) {
|
||||
return CustomPopup(
|
||||
showArrow: true,
|
||||
arrowColor: CustomTheme.boxBorderColor,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 0, vertical: 10),
|
||||
barrierColor: Colors.transparent,
|
||||
contentDecoration: CustomTheme.standardBoxDecoration,
|
||||
content: StatefulBuilder(
|
||||
builder: (context, setPopupState) => SizedBox(
|
||||
width: 150,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: List.generate(
|
||||
_colors.length,
|
||||
(index) => GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selectedColor = _colors[index].$1;
|
||||
});
|
||||
setPopupState(() {});
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
// Selected Highlighting
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(8),
|
||||
),
|
||||
color: selectedColor == _colors[index].$1
|
||||
? CustomTheme.textColor.withAlpha(20)
|
||||
: Colors.transparent,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: selectedColor == null
|
||||
? [Text(loc.none)]
|
||||
: [
|
||||
Container(
|
||||
width: 16,
|
||||
height: 16,
|
||||
margin: const EdgeInsets.only(left: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: getColorFromGameColor(
|
||||
_colors[index].$1,
|
||||
),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_colors[index].$2,
|
||||
style: const TextStyle(
|
||||
color: CustomTheme.textColor,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (index < _colors.length - 1)
|
||||
const Divider(indent: 15, endIndent: 15),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
// Selected Color
|
||||
Container(
|
||||
width: 16,
|
||||
height: 16,
|
||||
decoration: BoxDecoration(
|
||||
color: getColorFromGameColor(selectedColor!),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 5),
|
||||
child: Text(translateGameColorToString(selectedColor!, context)),
|
||||
),
|
||||
Transform.rotate(
|
||||
angle: pi / 2,
|
||||
child: const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,13 @@ class CreateMatchView extends StatefulWidget {
|
||||
this.onWinnerChanged,
|
||||
this.matchToEdit,
|
||||
this.onMatchUpdated,
|
||||
this.onMatchesUpdated,
|
||||
});
|
||||
|
||||
final VoidCallback? onWinnerChanged;
|
||||
|
||||
final VoidCallback? onMatchesUpdated;
|
||||
|
||||
final void Function(Match)? onMatchUpdated;
|
||||
|
||||
/// An optional match to prefill the fields for editing.
|
||||
@@ -115,6 +118,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
// Match name input field.
|
||||
Container(
|
||||
margin: CustomTheme.tileMargin,
|
||||
child: TextInputField(
|
||||
@@ -123,34 +127,40 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
maxLength: Constants.MAX_MATCH_NAME_LENGTH,
|
||||
),
|
||||
),
|
||||
ChooseTile(
|
||||
title: loc.game,
|
||||
trailingText: selectedGame == null
|
||||
? loc.none_group
|
||||
: selectedGame!.name,
|
||||
onPressed: () async {
|
||||
selectedGame = await Navigator.of(context).push(
|
||||
adaptivePageRoute(
|
||||
builder: (context) => ChooseGameView(
|
||||
games: gamesList,
|
||||
initialGameId: selectedGame?.id ?? '',
|
||||
|
||||
// Game selection tile.
|
||||
if (!isEditMode())
|
||||
ChooseTile(
|
||||
title: loc.game,
|
||||
trailing: selectedGame == null
|
||||
? Text(loc.none_group)
|
||||
: Text(selectedGame!.name),
|
||||
onPressed: () async {
|
||||
selectedGame = await Navigator.of(context).push(
|
||||
adaptivePageRoute(
|
||||
builder: (context) => ChooseGameView(
|
||||
games: gamesList,
|
||||
initialGameId: selectedGame?.id ?? '',
|
||||
onGamesUpdated: widget.onMatchesUpdated,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
if (selectedGame != null) {
|
||||
hintText = selectedGame!.name;
|
||||
} else {
|
||||
hintText = loc.match_name;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
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,
|
||||
trailing: selectedGroup == null
|
||||
? Text(loc.none_group)
|
||||
: Text(selectedGroup!.name),
|
||||
onPressed: () async {
|
||||
// Remove all players from the previously selected group from
|
||||
// the selected players list, in case the user deselects the
|
||||
@@ -181,6 +191,8 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
// Player selection widget.
|
||||
Expanded(
|
||||
child: PlayerSelection(
|
||||
key: ValueKey(selectedGroup?.id ?? 'no_group'),
|
||||
@@ -193,6 +205,8 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// Create or save button.
|
||||
CustomWidthButton(
|
||||
text: buttonText,
|
||||
sizeRelativeToWidth: 0.95,
|
||||
@@ -217,17 +231,17 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
/// Determines whether the "Create Match" button should be enabled.
|
||||
///
|
||||
/// Returns `true` if:
|
||||
/// - A ruleset is selected AND
|
||||
/// - Either a group is selected OR at least 2 players are selected
|
||||
/// - A game is selected AND
|
||||
/// - Either a group is selected OR at least 2 players are selected.
|
||||
bool _enableCreateGameButton() {
|
||||
return (selectedGroup != null ||
|
||||
(selectedPlayers.length > 1) && selectedGame != null);
|
||||
return ((selectedGroup != null || selectedPlayers.length > 1) &&
|
||||
selectedGame != null);
|
||||
}
|
||||
|
||||
// If a match was provided to the view, it updates the match in the database
|
||||
// and navigates back to the previous screen.
|
||||
// If no match was provided, it creates a new match in the database and
|
||||
// navigates to the MatchResultView for the newly created match.
|
||||
/// 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 (isEditMode()) {
|
||||
await updateMatch();
|
||||
@@ -252,8 +266,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates attributes of the existing match in the database based on the
|
||||
/// changes made in the edit view.
|
||||
/// Updates the existing match in the database.
|
||||
Future<void> updateMatch() async {
|
||||
final updatedMatch = Match(
|
||||
id: widget.matchToEdit!.id,
|
||||
@@ -262,7 +275,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
: _matchNameController.text.trim(),
|
||||
group: selectedGroup,
|
||||
players: selectedPlayers,
|
||||
game: widget.matchToEdit!.game,
|
||||
game: selectedGame!,
|
||||
createdAt: widget.matchToEdit!.createdAt,
|
||||
endedAt: widget.matchToEdit!.endedAt,
|
||||
notes: widget.matchToEdit!.notes,
|
||||
@@ -271,14 +284,14 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
if (widget.matchToEdit!.name != updatedMatch.name) {
|
||||
await db.matchDao.updateMatchName(
|
||||
matchId: widget.matchToEdit!.id,
|
||||
newName: updatedMatch.name,
|
||||
name: updatedMatch.name,
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.matchToEdit!.group?.id != updatedMatch.group?.id) {
|
||||
await db.matchDao.updateMatchGroup(
|
||||
matchId: widget.matchToEdit!.id,
|
||||
newGroupId: updatedMatch.group?.id,
|
||||
groupId: updatedMatch.group?.id,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttericon/rpg_awesome_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
@@ -14,6 +15,7 @@ import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||
import 'package:tallee/presentation/widgets/colored_icon_container.dart';
|
||||
import 'package:tallee/presentation/widgets/dialog/custom_alert_dialog.dart';
|
||||
import 'package:tallee/presentation/widgets/dialog/custom_dialog_action.dart';
|
||||
import 'package:tallee/presentation/widgets/game_label.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/info_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/text_icon_tile.dart';
|
||||
|
||||
@@ -102,6 +104,7 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
bottom: 100,
|
||||
),
|
||||
children: [
|
||||
// Controller Icon
|
||||
const Center(
|
||||
child: ColoredIconContainer(
|
||||
icon: Icons.sports_esports,
|
||||
@@ -110,6 +113,8 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// Match Name
|
||||
Text(
|
||||
match.name,
|
||||
style: const TextStyle(
|
||||
@@ -120,6 +125,8 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
|
||||
// Creation Date
|
||||
Text(
|
||||
'${loc.created_on} ${DateFormat.yMMMd(Localizations.localeOf(context).toString()).format(match.createdAt)}',
|
||||
style: const TextStyle(
|
||||
@@ -129,6 +136,8 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// Group Name
|
||||
if (match.group != null) ...[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -143,6 +152,8 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
|
||||
// Players
|
||||
InfoTile(
|
||||
title: loc.players,
|
||||
icon: Icons.people,
|
||||
@@ -162,6 +173,30 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// Game
|
||||
InfoTile(
|
||||
title: loc.game,
|
||||
icon: RpgAwesome.clovers_card,
|
||||
horizontalAlignment: CrossAxisAlignment.start,
|
||||
content: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 4,
|
||||
horizontal: 8,
|
||||
),
|
||||
child: GameLabel(
|
||||
title: match.game.name,
|
||||
description: translateRulesetToString(
|
||||
match.game.ruleset,
|
||||
context,
|
||||
),
|
||||
color: match.game.color,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// Results
|
||||
InfoTile(
|
||||
title: loc.results,
|
||||
icon: Icons.emoji_events,
|
||||
@@ -205,7 +240,9 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
match: match,
|
||||
onWinnerChanged: () {
|
||||
widget.onMatchUpdate.call();
|
||||
setState(() {});
|
||||
setState(() {
|
||||
updateScoresForCurrentMatch();
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -234,103 +271,180 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
Widget getResultWidget(AppLocalizations loc) {
|
||||
if (isSingleRowResult()) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: getSingleResultRow(loc),
|
||||
);
|
||||
} else {
|
||||
return getScoreResultWidget(loc);
|
||||
return getMultiResultRows(loc);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the result row for single winner/loser rulesets or a placeholder
|
||||
/// if no result is entered yet
|
||||
List<Widget> getSingleResultRow(AppLocalizations loc) {
|
||||
// Single Winner
|
||||
if (match.mvp.isNotEmpty && match.game.ruleset == Ruleset.singleWinner) {
|
||||
return [
|
||||
Text(
|
||||
loc.winner,
|
||||
style: const TextStyle(fontSize: 16, color: CustomTheme.textColor),
|
||||
),
|
||||
Text(
|
||||
match.mvp.first.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: CustomTheme.primaryColor,
|
||||
),
|
||||
),
|
||||
];
|
||||
// Single Loser
|
||||
} else if (match.game.ruleset == Ruleset.singleLoser) {
|
||||
return [
|
||||
Text(
|
||||
loc.loser,
|
||||
style: const TextStyle(fontSize: 16, color: CustomTheme.textColor),
|
||||
),
|
||||
Text(
|
||||
match.mvp.first.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: CustomTheme.primaryColor,
|
||||
),
|
||||
),
|
||||
];
|
||||
// No result entered yet
|
||||
} else {
|
||||
return [
|
||||
Text(
|
||||
loc.no_results_entered_yet,
|
||||
style: const TextStyle(fontSize: 14, color: CustomTheme.textColor),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
if (match.mvp.isNotEmpty) {
|
||||
final ruleset = match.game.ruleset;
|
||||
|
||||
/// Returns the result widget for scores
|
||||
Widget getScoreResultWidget(AppLocalizations loc) {
|
||||
List<(String, int)> playerScores = [];
|
||||
for (var player in match.players) {
|
||||
int score = match.scores[player.id]?.score ?? 0;
|
||||
playerScores.add((player.name, score));
|
||||
}
|
||||
if (widget.match.game.ruleset == Ruleset.highestScore) {
|
||||
playerScores.sort((a, b) => b.$2.compareTo(a.$2));
|
||||
} else if (widget.match.game.ruleset == Ruleset.lowestScore) {
|
||||
playerScores.sort((a, b) => a.$2.compareTo(b.$2));
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
for (var score in playerScores)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
score.$1,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: CustomTheme.textColor,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
getPointLabel(loc, score.$2),
|
||||
if (ruleset == Ruleset.singleWinner || ruleset == Ruleset.singleLoser) {
|
||||
return [
|
||||
Text(
|
||||
ruleset == Ruleset.singleWinner ? loc.winner : loc.loser,
|
||||
style: const TextStyle(fontSize: 16, color: CustomTheme.textColor),
|
||||
),
|
||||
Text(
|
||||
match.mvp.first.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: CustomTheme.primaryColor,
|
||||
),
|
||||
),
|
||||
];
|
||||
} else if (match.game.ruleset == Ruleset.multipleWinners) {
|
||||
return [
|
||||
Text(
|
||||
loc.winners,
|
||||
style: const TextStyle(fontSize: 16, color: CustomTheme.textColor),
|
||||
),
|
||||
Flexible(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.only(left: 10),
|
||||
child: Text(
|
||||
match.mvp.map((player) => player.name).join(', '),
|
||||
textAlign: TextAlign.end,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: CustomTheme.primaryColor,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// No results yet
|
||||
return [
|
||||
Text(
|
||||
loc.no_results_entered_yet,
|
||||
style: const TextStyle(fontSize: 14, color: CustomTheme.textColor),
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// Returns the result widget for scores or placement
|
||||
Widget getMultiResultRows(AppLocalizations loc) {
|
||||
List<(String, int)> playerScores = [];
|
||||
for (var player in match.players) {
|
||||
int score = match.scores[player.id]?.score ?? 0;
|
||||
playerScores.add((player.name, score));
|
||||
}
|
||||
|
||||
final ruleset = match.game.ruleset;
|
||||
|
||||
if (ruleset == Ruleset.highestScore || ruleset == Ruleset.placement) {
|
||||
playerScores.sort((a, b) => b.$2.compareTo(a.$2));
|
||||
} else if (ruleset == Ruleset.lowestScore) {
|
||||
playerScores.sort((a, b) => a.$2.compareTo(b.$2));
|
||||
}
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
for (var i = 0; i < playerScores.length; i++)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
playerScores[i].$1,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
color: CustomTheme.textColor,
|
||||
),
|
||||
),
|
||||
getResultValueText(loc, i, playerScores[i].$2),
|
||||
],
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget getResultValueText(AppLocalizations loc, int index, int score) {
|
||||
final ruleset = match.game.ruleset;
|
||||
|
||||
if (ruleset == Ruleset.placement) {
|
||||
return Text(
|
||||
getPlacementText(context, index + 1),
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: getPlacementTextcolor(index),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return Text(
|
||||
getPointLabel(loc, score),
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: CustomTheme.primaryColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Color getPlacementTextcolor(int placement) {
|
||||
switch (placement) {
|
||||
case 0:
|
||||
return const Color(0xFFFFBF00);
|
||||
case 1:
|
||||
return const Color(0xBBFFFFFF);
|
||||
case 2:
|
||||
return const Color(0xFFCD7F32);
|
||||
default:
|
||||
return CustomTheme.textColor;
|
||||
}
|
||||
}
|
||||
|
||||
// Returns if the result can be displayed in a single row
|
||||
bool isSingleRowResult() {
|
||||
return match.game.ruleset == Ruleset.singleWinner ||
|
||||
match.game.ruleset == Ruleset.singleLoser;
|
||||
match.game.ruleset == Ruleset.singleLoser ||
|
||||
match.game.ruleset == Ruleset.multipleWinners;
|
||||
}
|
||||
|
||||
String getPlacementText(BuildContext context, int rank) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
final locale = Localizations.localeOf(context).languageCode;
|
||||
|
||||
if (locale == 'de') {
|
||||
return '$rank. ${loc.place}';
|
||||
}
|
||||
|
||||
return '${_ordinalEn(rank)} ${loc.place}';
|
||||
}
|
||||
|
||||
String _ordinalEn(int number) {
|
||||
if (number % 100 >= 11 && number % 100 <= 13) {
|
||||
return '${number}th';
|
||||
}
|
||||
|
||||
switch (number % 10) {
|
||||
case 1:
|
||||
return '${number}st';
|
||||
case 2:
|
||||
return '${number}nd';
|
||||
case 3:
|
||||
return '${number}rd';
|
||||
default:
|
||||
return '${number}th';
|
||||
}
|
||||
}
|
||||
|
||||
void updateScoresForCurrentMatch() {
|
||||
db.scoreEntryDao
|
||||
.getAllMatchScores(matchId: match.id)
|
||||
.then((scores) => match.scores = scores);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,11 @@ import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/data/models/score_entry.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/custom_width_button.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/custom_radio_list_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/score_list_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/match_result_view/custom_checkbox_list_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/match_result_view/custom_radio_list_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/match_result_view/live_edit_list_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/match_result_view/score_list_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/text_icon_list_tile.dart';
|
||||
|
||||
class MatchResultView extends StatefulWidget {
|
||||
/// A view that allows selecting and saving the winner of a match
|
||||
@@ -30,6 +33,8 @@ class MatchResultView extends StatefulWidget {
|
||||
class _MatchResultViewState extends State<MatchResultView> {
|
||||
late final AppDatabase db;
|
||||
|
||||
bool isLiveEditMode = false;
|
||||
|
||||
late final Ruleset ruleset;
|
||||
|
||||
/// List of all players who participated in the match
|
||||
@@ -38,11 +43,15 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
/// List of text controllers for score entry, one for each player
|
||||
late final List<TextEditingController> controller;
|
||||
|
||||
/// Flag to indicate if the save button should be enabled
|
||||
late bool canSave;
|
||||
|
||||
/// Currently selected winner player
|
||||
/// Currently selected player (single winner / looser)
|
||||
Player? _selectedPlayer;
|
||||
|
||||
/// Currently selected players (multiple winners)
|
||||
final Set<Player> _selectedPlayers = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
@@ -57,17 +66,32 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
(index) => TextEditingController()..addListener(() => onTextEnter()),
|
||||
);
|
||||
|
||||
// Prefill fields
|
||||
if (widget.match.mvp.isNotEmpty) {
|
||||
if (rulesetSupportsWinnerSelection()) {
|
||||
_selectedPlayer = allPlayers.firstWhere(
|
||||
(p) => p.id == widget.match.mvp.first.id,
|
||||
);
|
||||
if (rulesetSupportsPlayerSelection()) {
|
||||
if (ruleset == Ruleset.multipleWinners) {
|
||||
for (int i = 0; i < allPlayers.length; i++) {
|
||||
if (widget.match.scores[allPlayers[i].id]?.score == 1) {
|
||||
_selectedPlayers.add(allPlayers[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_selectedPlayer = allPlayers.firstWhere(
|
||||
(p) => p.id == widget.match.mvp.first.id,
|
||||
);
|
||||
}
|
||||
} else if (rulesetSupportsScoreEntry()) {
|
||||
for (int i = 0; i < allPlayers.length; i++) {
|
||||
final scoreList = widget.match.scores[allPlayers[i].id];
|
||||
final score = scoreList?.score ?? 0;
|
||||
controller[i].text = score.toString();
|
||||
}
|
||||
} else if (rulesetSupportsDragBehaviour()) {
|
||||
allPlayers.sort((a, b) {
|
||||
final scoreA = widget.match.scores[a.id]?.score ?? 0;
|
||||
final scoreB = widget.match.scores[b.id]?.score ?? 0;
|
||||
return scoreB.compareTo(scoreA);
|
||||
});
|
||||
}
|
||||
super.initState();
|
||||
}
|
||||
@@ -101,86 +125,262 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
child: Column(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 10,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
horizontal: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.boxColor,
|
||||
border: Border.all(color: CustomTheme.boxBorderColor),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'${getTitleForRuleset(loc)}:',
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (rulesetSupportsWinnerSelection())
|
||||
Expanded(
|
||||
child: RadioGroup<Player>(
|
||||
groupValue: _selectedPlayer,
|
||||
onChanged: (Player? value) async {
|
||||
child: isLiveEditMode
|
||||
// Live Edit Mode
|
||||
? ListView.builder(
|
||||
itemCount: allPlayers.length,
|
||||
itemBuilder: (context, index) {
|
||||
return LiveEditListTile(
|
||||
title: allPlayers[index].name,
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_selectedPlayer = value;
|
||||
controller[index].text = value.toString();
|
||||
});
|
||||
},
|
||||
child: ListView.builder(
|
||||
itemCount: allPlayers.length,
|
||||
itemBuilder: (context, index) {
|
||||
return CustomRadioListTile(
|
||||
text: allPlayers[index].name,
|
||||
value: allPlayers[index],
|
||||
onContainerTap: (value) async {
|
||||
setState(() {
|
||||
// Check if the already selected player is the same as the newly tapped player.
|
||||
if (_selectedPlayer == value) {
|
||||
// If yes deselected the player by setting it to null.
|
||||
_selectedPlayer = null;
|
||||
} else {
|
||||
// If no assign the newly tapped player to the selected player.
|
||||
(_selectedPlayer = value);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
value: int.tryParse(controller[index].text) ?? 0,
|
||||
);
|
||||
},
|
||||
)
|
||||
// Normal Container
|
||||
: Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 10,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10,
|
||||
horizontal: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.boxColor,
|
||||
border: Border.all(color: CustomTheme.boxBorderColor),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
getTitleForRuleset(loc),
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// Show player selection
|
||||
if (rulesetSupportsPlayerSelection())
|
||||
Expanded(
|
||||
child: ruleset == Ruleset.multipleWinners
|
||||
// Multiple winners
|
||||
? ListView.builder(
|
||||
physics:
|
||||
const NeverScrollableScrollPhysics(),
|
||||
itemCount: allPlayers.length,
|
||||
itemBuilder: (context, index) {
|
||||
return CustomCheckboxListTile(
|
||||
text: allPlayers[index].name,
|
||||
value: _selectedPlayers.contains(
|
||||
allPlayers[index],
|
||||
),
|
||||
onChanged: (bool value) {
|
||||
setState(() {
|
||||
if (value) {
|
||||
_selectedPlayers.add(
|
||||
allPlayers[index],
|
||||
);
|
||||
} else {
|
||||
_selectedPlayers.remove(
|
||||
allPlayers[index],
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
)
|
||||
// Single winner / looser
|
||||
: RadioGroup<Player>(
|
||||
groupValue: _selectedPlayer,
|
||||
onChanged: (Player? value) async {
|
||||
setState(() {
|
||||
_selectedPlayer = value;
|
||||
});
|
||||
},
|
||||
child: ListView.builder(
|
||||
physics:
|
||||
const NeverScrollableScrollPhysics(),
|
||||
itemCount: allPlayers.length,
|
||||
itemBuilder: (context, index) {
|
||||
return CustomRadioListTile(
|
||||
text: allPlayers[index].name,
|
||||
value: allPlayers[index],
|
||||
onContainerTap: (value) async {
|
||||
setState(() {
|
||||
// Check if the already selected player is the same as the newly tapped player.
|
||||
if (_selectedPlayer == value) {
|
||||
// If yes deselected the player by setting it to null.
|
||||
_selectedPlayer = null;
|
||||
} else {
|
||||
// If no assign the newly tapped player to the selected player.
|
||||
(_selectedPlayer = value);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Show score entry
|
||||
if (rulesetSupportsScoreEntry())
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
itemCount: allPlayers.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ScoreListTile(
|
||||
text: allPlayers[index].name,
|
||||
controller: controller[index],
|
||||
);
|
||||
},
|
||||
separatorBuilder:
|
||||
(BuildContext context, int index) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 8.0,
|
||||
),
|
||||
child: Divider(indent: 20),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// Show draggable placement list
|
||||
if (rulesetSupportsDragBehaviour())
|
||||
Expanded(
|
||||
child: Row(
|
||||
children: [
|
||||
// Placement indicators
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 8.0),
|
||||
child: Column(
|
||||
children: [
|
||||
for (
|
||||
int i = 0;
|
||||
i < allPlayers.length;
|
||||
i++
|
||||
)
|
||||
Container(
|
||||
alignment: Alignment.center,
|
||||
height: 60,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
CustomTheme.boxBorderColor,
|
||||
borderRadius: CustomTheme
|
||||
.standardBorderRadiusAll,
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
height: 50,
|
||||
width: 50,
|
||||
child: Text(
|
||||
' #${i + 1} ',
|
||||
style: const TextStyle(
|
||||
color: CustomTheme.textColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Drag list
|
||||
Expanded(
|
||||
child: ReorderableListView.builder(
|
||||
physics:
|
||||
const NeverScrollableScrollPhysics(),
|
||||
padding: EdgeInsets.zero,
|
||||
proxyDecorator: (child, index, animation) {
|
||||
return AnimatedBuilder(
|
||||
animation: animation,
|
||||
child: child,
|
||||
builder: (context, child) {
|
||||
final alpha =
|
||||
(Curves.easeInOut.transform(
|
||||
animation.value,
|
||||
) *
|
||||
40)
|
||||
.toInt();
|
||||
return Stack(
|
||||
children: [
|
||||
child!,
|
||||
Positioned.fill(
|
||||
left: 4,
|
||||
top: 4,
|
||||
right: 4,
|
||||
bottom: 4,
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white
|
||||
.withAlpha(alpha),
|
||||
borderRadius: CustomTheme
|
||||
.standardBorderRadiusAll,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
onReorder: (int oldIndex, int newIndex) {
|
||||
setState(() {
|
||||
if (newIndex > oldIndex) {
|
||||
newIndex -= 1;
|
||||
}
|
||||
final Player item = allPlayers
|
||||
.removeAt(oldIndex);
|
||||
allPlayers.insert(newIndex, item);
|
||||
});
|
||||
},
|
||||
itemCount: allPlayers.length,
|
||||
itemBuilder: (context, index) {
|
||||
return TextIconListTile(
|
||||
key: ValueKey(allPlayers[index].id),
|
||||
text: allPlayers[index].name,
|
||||
icon: Icons.drag_handle,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
if (rulesetSupportsScoreEntry())
|
||||
Expanded(
|
||||
child: ListView.separated(
|
||||
itemCount: allPlayers.length,
|
||||
itemBuilder: (context, index) {
|
||||
return ScoreListTile(
|
||||
text: allPlayers[index].name,
|
||||
controller: controller[index],
|
||||
);
|
||||
},
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Divider(indent: 20),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (rulesetSupportsScoreEntry())
|
||||
// Button to switch to live edit mode
|
||||
...[
|
||||
CustomWidthButton(
|
||||
text: isLiveEditMode ? loc.exit_view : loc.live_edit_mode,
|
||||
sizeRelativeToWidth: 0.95,
|
||||
buttonType: ButtonType.secondary,
|
||||
onPressed: () => setState(() {
|
||||
isLiveEditMode = !isLiveEditMode;
|
||||
}),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
],
|
||||
|
||||
// Save Changes Button
|
||||
CustomWidthButton(
|
||||
text: loc.save_changes,
|
||||
sizeRelativeToWidth: 0.95,
|
||||
@@ -222,12 +422,16 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
} else if (ruleset == Ruleset.lowestScore ||
|
||||
ruleset == Ruleset.highestScore) {
|
||||
await _handleScores();
|
||||
} else if (ruleset == Ruleset.placement) {
|
||||
await _handlePlacement();
|
||||
} else if (ruleset == Ruleset.multipleWinners) {
|
||||
await _handleWinners();
|
||||
}
|
||||
|
||||
widget.onWinnerChanged?.call();
|
||||
}
|
||||
|
||||
/// Handles saving or removing the winner in the database.
|
||||
/// Handles saving or removing the (single) winner in the database.
|
||||
Future<bool> _handleWinner() async {
|
||||
if (_selectedPlayer == null) {
|
||||
return await db.scoreEntryDao.removeWinner(matchId: widget.match.id);
|
||||
@@ -239,12 +443,24 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles saving the (multiple) winners to the database.
|
||||
Future<bool> _handleWinners() async {
|
||||
if (_selectedPlayers.isEmpty) {
|
||||
return await db.scoreEntryDao.removeWinner(matchId: widget.match.id);
|
||||
} else {
|
||||
return await db.scoreEntryDao.setWinners(
|
||||
matchId: widget.match.id,
|
||||
winners: allPlayers.where((p) => _selectedPlayers.contains(p)).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles saving or removing the loser in the database.
|
||||
Future<bool> _handleLoser() async {
|
||||
if (_selectedPlayer == null) {
|
||||
return await db.scoreEntryDao.removeLooser(matchId: widget.match.id);
|
||||
return await db.scoreEntryDao.removeLoser(matchId: widget.match.id);
|
||||
} else {
|
||||
return await db.scoreEntryDao.setLooser(
|
||||
return await db.scoreEntryDao.setLoser(
|
||||
matchId: widget.match.id,
|
||||
playerId: _selectedPlayer!.id,
|
||||
);
|
||||
@@ -267,22 +483,40 @@ class _MatchResultViewState extends State<MatchResultView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles saving the placement for each player in the database.
|
||||
Future<void> _handlePlacement() async {
|
||||
await db.scoreEntryDao.setPlacements(
|
||||
matchId: widget.match.id,
|
||||
players: allPlayers,
|
||||
);
|
||||
}
|
||||
|
||||
String getTitleForRuleset(AppLocalizations loc) {
|
||||
switch (ruleset) {
|
||||
case Ruleset.singleWinner:
|
||||
return loc.select_winner;
|
||||
case Ruleset.singleLoser:
|
||||
return loc.select_loser;
|
||||
case Ruleset.placement:
|
||||
return loc.drag_to_set_placement;
|
||||
case Ruleset.multipleWinners:
|
||||
return loc.select_winners;
|
||||
default:
|
||||
return loc.enter_points;
|
||||
}
|
||||
}
|
||||
|
||||
bool rulesetSupportsWinnerSelection() {
|
||||
return ruleset == Ruleset.singleWinner || ruleset == Ruleset.singleLoser;
|
||||
bool rulesetSupportsPlayerSelection() {
|
||||
return ruleset == Ruleset.singleWinner ||
|
||||
ruleset == Ruleset.singleLoser ||
|
||||
ruleset == Ruleset.multipleWinners;
|
||||
}
|
||||
|
||||
bool rulesetSupportsScoreEntry() {
|
||||
return ruleset == Ruleset.lowestScore || ruleset == Ruleset.highestScore;
|
||||
}
|
||||
|
||||
bool rulesetSupportsDragBehaviour() {
|
||||
return ruleset == Ruleset.placement;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/data/models/score_entry.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_detail_view.dart';
|
||||
@@ -30,8 +31,7 @@ class _MatchViewState extends State<MatchView> {
|
||||
late final AppDatabase db;
|
||||
bool isLoading = true;
|
||||
|
||||
/// Loaded matches from the database,
|
||||
/// initially filled with skeleton matches
|
||||
/// Loaded matches from the database, initially filled with skeleton matches
|
||||
List<Match> matches = List.filled(
|
||||
4,
|
||||
Match(
|
||||
@@ -46,7 +46,15 @@ class _MatchViewState extends State<MatchView> {
|
||||
name: 'Group name',
|
||||
members: List.filled(5, Player(name: 'Player')),
|
||||
),
|
||||
players: [Player(name: 'Player')],
|
||||
players: [
|
||||
Player(name: 'Player'),
|
||||
Player(name: 'Player'),
|
||||
Player(name: 'Player'),
|
||||
Player(name: 'Player'),
|
||||
Player(id: 'mvp_id', name: 'Player'),
|
||||
],
|
||||
scores: {'mvp_id': ScoreEntry(score: 1)},
|
||||
endedAt: DateTime.now(),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -118,8 +126,10 @@ class _MatchViewState extends State<MatchView> {
|
||||
Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) =>
|
||||
CreateMatchView(onWinnerChanged: loadMatches),
|
||||
builder: (context) => CreateMatchView(
|
||||
onWinnerChanged: loadMatches,
|
||||
onMatchesUpdated: loadMatches,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -6,6 +6,7 @@ import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/data/models/player.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/quick_info_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/statistics_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/top_centered_message.dart';
|
||||
|
||||
@@ -18,6 +19,9 @@ class StatisticsView extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _StatisticsViewState extends State<StatisticsView> {
|
||||
int matchCount = 0;
|
||||
int groupCount = 0;
|
||||
|
||||
List<(Player, int)> winCounts = List.filled(6, (
|
||||
Player(name: 'Skeleton Player'),
|
||||
1,
|
||||
@@ -53,7 +57,27 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(height: constraints.maxHeight * 0.01),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
QuickInfoTile(
|
||||
width: constraints.maxWidth * 0.45,
|
||||
height: constraints.maxHeight * 0.13,
|
||||
title: loc.matches,
|
||||
icon: Icons.groups_rounded,
|
||||
value: matchCount,
|
||||
),
|
||||
SizedBox(width: constraints.maxWidth * 0.05),
|
||||
QuickInfoTile(
|
||||
width: constraints.maxWidth * 0.45,
|
||||
height: constraints.maxHeight * 0.13,
|
||||
title: loc.groups,
|
||||
icon: Icons.groups_rounded,
|
||||
value: groupCount,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: constraints.maxHeight * 0.02),
|
||||
Visibility(
|
||||
visible:
|
||||
winCounts.isEmpty &&
|
||||
@@ -115,11 +139,17 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
Future.wait([
|
||||
db.matchDao.getAllMatches(),
|
||||
db.playerDao.getAllPlayers(),
|
||||
db.matchDao.getMatchCount(),
|
||||
db.groupDao.getGroupCount(),
|
||||
Future.delayed(Constants.MINIMUM_SKELETON_DURATION),
|
||||
]).then((results) async {
|
||||
if (!mounted) return;
|
||||
|
||||
final matches = results[0] as List<Match>;
|
||||
final players = results[1] as List<Player>;
|
||||
matchCount = results[2] as int;
|
||||
groupCount = results[3] as int;
|
||||
|
||||
winCounts = _calculateWinsForAllPlayers(
|
||||
matches: matches,
|
||||
players: players,
|
||||
@@ -134,6 +164,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
||||
winCounts: winCounts,
|
||||
matchCounts: matchCounts,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
|
||||
@@ -14,6 +14,7 @@ class AnimatedDialogButton extends StatefulWidget {
|
||||
required this.onPressed,
|
||||
this.buttonConstraints,
|
||||
this.buttonType = ButtonType.primary,
|
||||
this.isDescructive = false,
|
||||
});
|
||||
|
||||
final String buttonText;
|
||||
@@ -24,6 +25,8 @@ class AnimatedDialogButton extends StatefulWidget {
|
||||
|
||||
final ButtonType buttonType;
|
||||
|
||||
final bool isDescructive;
|
||||
|
||||
@override
|
||||
State<AnimatedDialogButton> createState() => _AnimatedDialogButtonState();
|
||||
}
|
||||
@@ -33,28 +36,8 @@ class _AnimatedDialogButtonState extends State<AnimatedDialogButton> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final textStyling = TextStyle(
|
||||
color: widget.buttonType == ButtonType.primary
|
||||
? Colors.black
|
||||
: Colors.white,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
);
|
||||
|
||||
final buttonDecoration = widget.buttonType == ButtonType.primary
|
||||
// Primary
|
||||
? BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
)
|
||||
: widget.buttonType == ButtonType.secondary
|
||||
// Secondary
|
||||
? BoxDecoration(
|
||||
border: BoxBorder.all(color: Colors.white, width: 2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
)
|
||||
// Tertiary
|
||||
: const BoxDecoration();
|
||||
final textStyling = _getTextStyling();
|
||||
final buttonDecoration = _getButtonDecoration();
|
||||
|
||||
return GestureDetector(
|
||||
onTapDown: (_) => setState(() => _isPressed = true),
|
||||
@@ -84,4 +67,42 @@ class _AnimatedDialogButtonState extends State<AnimatedDialogButton> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
TextStyle _getTextStyling() {
|
||||
late Color textColor;
|
||||
if (widget.buttonType == ButtonType.primary) {
|
||||
textColor = widget.isDescructive ? Colors.white : Colors.black;
|
||||
} else if (widget.buttonType == ButtonType.secondary) {
|
||||
textColor = widget.isDescructive ? Colors.red : Colors.white;
|
||||
} else {
|
||||
textColor = widget.isDescructive ? Colors.red : Colors.white;
|
||||
}
|
||||
|
||||
return TextStyle(
|
||||
color: textColor,
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.bold,
|
||||
);
|
||||
}
|
||||
|
||||
BoxDecoration _getButtonDecoration() {
|
||||
if (widget.buttonType == ButtonType.primary) {
|
||||
// Primary
|
||||
return BoxDecoration(
|
||||
color: widget.isDescructive ? Colors.red : Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
);
|
||||
} else if (widget.buttonType == ButtonType.secondary) {
|
||||
// Secondary
|
||||
return BoxDecoration(
|
||||
border: BoxBorder.all(
|
||||
color: widget.isDescructive ? Colors.red : Colors.white,
|
||||
width: 2,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
);
|
||||
}
|
||||
// Tertiary
|
||||
return const BoxDecoration();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ class CustomWidthButton extends StatelessWidget {
|
||||
MediaQuery.sizeOf(context).width * sizeRelativeToWidth,
|
||||
60,
|
||||
),
|
||||
side: BorderSide(color: borderSideColor, width: 2),
|
||||
side: BorderSide(color: borderSideColor, width: 3),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: CustomTheme.standardBorderRadiusAll,
|
||||
),
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class MainMenuButton extends StatefulWidget {
|
||||
@@ -10,6 +12,7 @@ class MainMenuButton extends StatefulWidget {
|
||||
required this.onPressed,
|
||||
required this.icon,
|
||||
this.text,
|
||||
this.onLongPressed,
|
||||
});
|
||||
|
||||
/// The callback to be invoked when the button is pressed.
|
||||
@@ -21,6 +24,8 @@ class MainMenuButton extends StatefulWidget {
|
||||
/// The text of the button.
|
||||
final String? text;
|
||||
|
||||
final void Function()? onLongPressed;
|
||||
|
||||
@override
|
||||
State<MainMenuButton> createState() => _MainMenuButtonState();
|
||||
}
|
||||
@@ -30,6 +35,14 @@ class _MainMenuButtonState extends State<MainMenuButton>
|
||||
late AnimationController _animationController;
|
||||
late Animation<double> _scaleAnimation;
|
||||
|
||||
/// How long the button needs to be pressed to register it as long press
|
||||
Timer? _longPressTimer;
|
||||
|
||||
/// How much time between two onLongPressed calls
|
||||
Timer? _repeatTimer;
|
||||
|
||||
bool _isLongPressing = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -51,14 +64,29 @@ class _MainMenuButtonState extends State<MainMenuButton>
|
||||
child: GestureDetector(
|
||||
onTapDown: (_) {
|
||||
_animationController.forward();
|
||||
},
|
||||
onTapUp: (_) async {
|
||||
await _animationController.reverse();
|
||||
if (mounted) {
|
||||
widget.onPressed();
|
||||
if (widget.onLongPressed != null) {
|
||||
_longPressTimer = Timer(const Duration(milliseconds: 400), () {
|
||||
_isLongPressing = true;
|
||||
widget.onLongPressed?.call();
|
||||
_repeatTimer = Timer.periodic(
|
||||
const Duration(milliseconds: 250),
|
||||
(_) => widget.onLongPressed?.call(),
|
||||
);
|
||||
});
|
||||
}
|
||||
},
|
||||
onTapUp: (_) async {
|
||||
_cancelTimers();
|
||||
if (mounted && !_isLongPressing) {
|
||||
widget.onPressed();
|
||||
}
|
||||
_isLongPressing = false;
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
await _animationController.reverse();
|
||||
},
|
||||
onTapCancel: () {
|
||||
_isLongPressing = false;
|
||||
_cancelTimers();
|
||||
_animationController.reverse();
|
||||
},
|
||||
child: Container(
|
||||
@@ -92,7 +120,15 @@ class _MainMenuButtonState extends State<MainMenuButton>
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_cancelTimers();
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _cancelTimers() {
|
||||
_longPressTimer?.cancel();
|
||||
_longPressTimer = null;
|
||||
_repeatTimer?.cancel();
|
||||
_repeatTimer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ class CustomDialogAction extends StatelessWidget {
|
||||
required this.onPressed,
|
||||
required this.text,
|
||||
this.buttonType = ButtonType.primary,
|
||||
this.isDestructive = false,
|
||||
});
|
||||
|
||||
final String text;
|
||||
@@ -20,12 +21,15 @@ class CustomDialogAction extends StatelessWidget {
|
||||
|
||||
final VoidCallback onPressed;
|
||||
|
||||
final bool isDestructive;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AnimatedDialogButton(
|
||||
onPressed: onPressed,
|
||||
buttonText: text,
|
||||
buttonType: buttonType,
|
||||
isDescructive: isDestructive,
|
||||
buttonConstraints: const BoxConstraints(minWidth: 300),
|
||||
);
|
||||
}
|
||||
|
||||
71
lib/presentation/widgets/game_label.dart
Normal file
71
lib/presentation/widgets/game_label.dart
Normal file
@@ -0,0 +1,71 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
|
||||
class GameLabel extends StatelessWidget {
|
||||
const GameLabel({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.description,
|
||||
required this.color,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String description;
|
||||
final GameColor color;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final backgroundColor = getColorFromGameColor(color);
|
||||
final fontColor = backgroundColor.computeLuminance() > 0.5
|
||||
? Colors.black
|
||||
: Colors.white;
|
||||
|
||||
return IntrinsicHeight(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Title
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor.withAlpha(230),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(8),
|
||||
bottomLeft: Radius.circular(8),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
|
||||
child: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: fontColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Description
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: backgroundColor.withAlpha(140),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(8),
|
||||
bottomRight: Radius.circular(8),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
|
||||
child: Text(
|
||||
description,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: fontColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -44,24 +44,49 @@ class _NavbarItemState extends State<NavbarItem>
|
||||
/// Scale animation for the icon when selected
|
||||
late Animation<double> _scaleAnimation;
|
||||
|
||||
/// Color animation for the icon
|
||||
late Animation<Color?> _iconColorAnimation;
|
||||
|
||||
/// Background color animation for the icon container
|
||||
late Animation<Color?> _bgColorAnimation;
|
||||
|
||||
/// Font size animation for the label
|
||||
late Animation<double> _fontSizeAnimation;
|
||||
|
||||
/// A simple double tween used to lerp between two font weights
|
||||
late Animation<double> _fontWeightT;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_animationController = AnimationController(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
vsync: this,
|
||||
// Set initial value directly so the visual state matches widget.isSelected
|
||||
value: widget.isSelected ? 1.0 : 0.0,
|
||||
);
|
||||
|
||||
_scaleAnimation = Tween<double>(begin: 1.0, end: 1.2).animate(
|
||||
CurvedAnimation(
|
||||
parent: _animationController,
|
||||
curve: Curves.easeInOutBack,
|
||||
),
|
||||
final curved = CurvedAnimation(
|
||||
parent: _animationController,
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
|
||||
if (widget.isSelected) {
|
||||
_animationController.forward();
|
||||
}
|
||||
_scaleAnimation = Tween<double>(begin: 1.0, end: 1.2).animate(curved);
|
||||
|
||||
_iconColorAnimation = ColorTween(
|
||||
begin: CustomTheme.navBarItemUnselectedColor,
|
||||
end: CustomTheme.navBarItemSelectedColor,
|
||||
).animate(curved);
|
||||
|
||||
_bgColorAnimation = ColorTween(
|
||||
begin: Colors.transparent,
|
||||
end: CustomTheme.primaryColor.withAlpha(50),
|
||||
).animate(curved);
|
||||
|
||||
_fontSizeAnimation = Tween<double>(begin: 11.0, end: 12.0).animate(curved);
|
||||
|
||||
// drives font weight interpolation
|
||||
_fontWeightT = Tween<double>(begin: 0.0, end: 1.0).animate(curved);
|
||||
}
|
||||
|
||||
// Retrigger animation on selection change
|
||||
@@ -83,46 +108,44 @@ class _NavbarItemState extends State<NavbarItem>
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 5.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
AnimatedContainer(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: widget.isSelected
|
||||
? 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,
|
||||
child: AnimatedBuilder(
|
||||
animation: _animationController,
|
||||
builder: (context, child) {
|
||||
final iconColor = _iconColorAnimation.value!;
|
||||
final bgColor = _bgColorAnimation.value!;
|
||||
final fontSize = _fontSizeAnimation.value;
|
||||
final fontWeight = FontWeight.lerp(
|
||||
FontWeight.w500,
|
||||
FontWeight.bold,
|
||||
_fontWeightT.value,
|
||||
);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: bgColor,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(15)),
|
||||
),
|
||||
child: ScaleTransition(
|
||||
scale: _scaleAnimation,
|
||||
child: Icon(widget.icon, color: iconColor, size: 32),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
widget.label,
|
||||
style: TextStyle(
|
||||
color: widget.isSelected
|
||||
? CustomTheme.navBarItemSelectedColor
|
||||
: CustomTheme.navBarItemUnselectedColor,
|
||||
fontSize: widget.isSelected ? 12 : 11,
|
||||
fontWeight: widget.isSelected
|
||||
? FontWeight.bold
|
||||
: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
],
|
||||
Text(
|
||||
widget.label,
|
||||
style: TextStyle(
|
||||
color: iconColor,
|
||||
fontSize: fontSize,
|
||||
fontWeight: fontWeight,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -196,6 +196,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
|
||||
return TextIconListTile(
|
||||
text: suggestedPlayers[index].name,
|
||||
suffixText: getNameCountText(suggestedPlayers[index]),
|
||||
icon: Icons.add,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
// If the player is not already selected
|
||||
|
||||
@@ -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,13 +50,15 @@ 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.boxBorderColor),
|
||||
|
||||
@@ -4,12 +4,12 @@ import 'package:tallee/core/custom_theme.dart';
|
||||
class ChooseTile extends StatefulWidget {
|
||||
/// A tile widget that allows users to choose an option by tapping on it.
|
||||
/// - [title]: The title text displayed on the tile.
|
||||
/// - [trailingText]: Optional trailing text displayed on the tile.
|
||||
/// - [trailing]: Optional trailing text displayed on the tile.
|
||||
/// - [onPressed]: The callback invoked when the tile is tapped.
|
||||
const ChooseTile({
|
||||
super.key,
|
||||
required this.title,
|
||||
this.trailingText,
|
||||
this.trailing,
|
||||
this.onPressed,
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ class ChooseTile extends StatefulWidget {
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
/// Optional trailing text displayed on the tile.
|
||||
final String? trailingText;
|
||||
final Widget? trailing;
|
||||
|
||||
@override
|
||||
State<ChooseTile> createState() => _ChooseTileState();
|
||||
@@ -42,9 +42,11 @@ class _ChooseTileState extends State<ChooseTile> {
|
||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const Spacer(),
|
||||
if (widget.trailingText != null) Text(widget.trailingText!),
|
||||
const SizedBox(width: 10),
|
||||
const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
if (widget.trailing != null) widget.trailing!,
|
||||
if (widget.onPressed != null) ...[
|
||||
const SizedBox(width: 10),
|
||||
const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
151
lib/presentation/widgets/tiles/game_tile.dart
Normal file
151
lib/presentation/widgets/tiles/game_tile.dart
Normal file
@@ -0,0 +1,151 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
|
||||
class GameTile extends StatelessWidget {
|
||||
/// A list tile widget that displays a title and description, with optional highlighting and badge.
|
||||
/// - [title]: The title text displayed on the tile.
|
||||
/// - [description]: The description text displayed below the title.
|
||||
/// - [onTap]: 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.
|
||||
const GameTile({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.description,
|
||||
this.onTap,
|
||||
this.onLongPress,
|
||||
this.isHighlighted = false,
|
||||
this.badgeText,
|
||||
this.badgeColor,
|
||||
});
|
||||
|
||||
/// The title text displayed on the tile.
|
||||
final String title;
|
||||
|
||||
/// The description text displayed below the title.
|
||||
final String description;
|
||||
|
||||
/// The callback invoked when the tile is tapped.
|
||||
final VoidCallback? 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;
|
||||
|
||||
/// Optional text to display in a badge on the right side of the title.
|
||||
final String? badgeText;
|
||||
|
||||
/// Optional color for the badge background.
|
||||
final Color? badgeColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final badgeTextColor = badgeColor != null
|
||||
? (badgeColor!.computeLuminance() > 0.5 ? Colors.black : Colors.white)
|
||||
: Colors.white;
|
||||
|
||||
final gameColor = badgeColor ?? getColorFromGameColor(GameColor.orange);
|
||||
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
onLongPress: onLongPress,
|
||||
child: AnimatedContainer(
|
||||
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
||||
decoration: !isHighlighted
|
||||
? CustomTheme.standardBoxDecoration
|
||||
: CustomTheme.highlightedBoxDecoration.copyWith(
|
||||
border: Border.all(
|
||||
color: gameColor.withValues(alpha: 0.9),
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
duration: const Duration(milliseconds: 200),
|
||||
child: Stack(
|
||||
children: [
|
||||
// Gradient overlay
|
||||
Positioned.fill(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
gameColor.withValues(alpha: 0.08),
|
||||
gameColor.withValues(alpha: 0.02),
|
||||
Colors.transparent,
|
||||
],
|
||||
stops: const [0.0, 0.5, 1.0],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Content
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Title
|
||||
Text(
|
||||
title,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
softWrap: false,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
|
||||
// Badge
|
||||
if (badgeText != null) ...[
|
||||
const SizedBox(height: 5),
|
||||
Container(
|
||||
constraints: const BoxConstraints(maxWidth: 250),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 2,
|
||||
horizontal: 6,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: gameColor,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
badgeText!,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
softWrap: false,
|
||||
style: TextStyle(
|
||||
color: badgeTextColor,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// Description
|
||||
if (description.isNotEmpty) ...[
|
||||
const SizedBox(height: 10),
|
||||
Text(description, style: const TextStyle(fontSize: 14)),
|
||||
const SizedBox(height: 2.5),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
|
||||
class CustomCheckboxListTile extends StatelessWidget {
|
||||
const CustomCheckboxListTile({
|
||||
super.key,
|
||||
required this.text,
|
||||
required this.value,
|
||||
required this.onChanged,
|
||||
});
|
||||
|
||||
final String text;
|
||||
final bool value;
|
||||
final ValueChanged<bool> onChanged;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: () => onChanged(!value),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.boxColor,
|
||||
border: Border.all(color: CustomTheme.boxBorderColor),
|
||||
borderRadius: CustomTheme.standardBorderRadiusAll,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
value: value,
|
||||
onChanged: (bool? v) {
|
||||
if (v == null) return;
|
||||
onChanged(v);
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
text,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_numeric_text/flutter_numeric_text.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||
|
||||
class LiveEditListTile extends StatefulWidget {
|
||||
const LiveEditListTile({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.value,
|
||||
this.onChanged,
|
||||
});
|
||||
|
||||
final String title;
|
||||
|
||||
final int value;
|
||||
|
||||
final void Function(int newValue)? onChanged;
|
||||
|
||||
@override
|
||||
State<LiveEditListTile> createState() => _LiveEditListTileState();
|
||||
}
|
||||
|
||||
class _LiveEditListTileState extends State<LiveEditListTile> {
|
||||
int _score = 0;
|
||||
final int maxScore = 9999;
|
||||
final int minScore = -9999;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
_score = widget.value;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 20),
|
||||
margin: const EdgeInsets.symmetric(vertical: 12, horizontal: 8),
|
||||
decoration: CustomTheme.standardBoxDecoration,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
MainMenuButton(
|
||||
onPressed: () => _score > minScore
|
||||
? {
|
||||
setState(() {
|
||||
_score--;
|
||||
if (widget.onChanged != null) {
|
||||
widget.onChanged!(_score);
|
||||
}
|
||||
}),
|
||||
}
|
||||
: null,
|
||||
onLongPressed: () => _score > minScore
|
||||
? {
|
||||
setState(() {
|
||||
_score -= 10;
|
||||
if (widget.onChanged != null) {
|
||||
widget.onChanged!(_score);
|
||||
}
|
||||
}),
|
||||
}
|
||||
: null,
|
||||
icon: Icons.remove_rounded,
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
Text(
|
||||
widget.title,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
width: 150,
|
||||
child: NumericText(
|
||||
_score.toString(),
|
||||
maxLines: 1,
|
||||
textAlign: TextAlign.center,
|
||||
textWidthBasis: TextWidthBasis.longestLine,
|
||||
textHeightBehavior: const TextHeightBehavior(
|
||||
applyHeightToFirstAscent: false,
|
||||
applyHeightToLastDescent: false,
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 48,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
MainMenuButton(
|
||||
onPressed: () => _score < maxScore
|
||||
? {
|
||||
setState(() {
|
||||
_score++;
|
||||
if (widget.onChanged != null) {
|
||||
widget.onChanged!(_score);
|
||||
}
|
||||
}),
|
||||
}
|
||||
: null,
|
||||
onLongPressed: () => _score > minScore
|
||||
? {
|
||||
setState(() {
|
||||
_score += 10;
|
||||
if (widget.onChanged != null) {
|
||||
widget.onChanged!(_score);
|
||||
}
|
||||
}),
|
||||
}
|
||||
: null,
|
||||
icon: Icons.add_rounded,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -40,9 +40,13 @@ class ScoreListTile extends StatelessWidget {
|
||||
height: 40,
|
||||
child: TextField(
|
||||
controller: controller,
|
||||
keyboardType: TextInputType.number,
|
||||
maxLength: 4,
|
||||
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
|
||||
keyboardType: const TextInputType.numberWithOptions(signed: true),
|
||||
maxLength: 5,
|
||||
inputFormatters: [
|
||||
TextInputFormatter.withFunction((oldValue, newValue) {
|
||||
return isValidScoreInput(newValue.text) ? newValue : oldValue;
|
||||
}),
|
||||
],
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
@@ -62,7 +66,7 @@ class ScoreListTile extends StatelessWidget {
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
borderSide: BorderSide(
|
||||
color: CustomTheme.textColor.withAlpha(100),
|
||||
color: CustomTheme.textColor.withAlpha(250),
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
@@ -80,4 +84,21 @@ class ScoreListTile extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Validates the input for the score text field.
|
||||
bool isValidScoreInput(String text) {
|
||||
if (text.isEmpty || text == '-') {
|
||||
return true;
|
||||
}
|
||||
|
||||
final isNegative = text.startsWith('-');
|
||||
final digits = isNegative ? text.substring(1) : text;
|
||||
|
||||
if (digits.isEmpty || digits.length > 4) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// CHeck if all characters are digits 0 <= x <= 9
|
||||
return digits.codeUnits.every((unit) => unit >= 48 && unit <= 57);
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/models/match.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/widgets/game_label.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/text_icon_tile.dart';
|
||||
|
||||
class MatchTile extends StatefulWidget {
|
||||
@@ -116,56 +117,13 @@ class _MatchTileState extends State<MatchTile> {
|
||||
|
||||
// Game + Ruleset Badge
|
||||
if (!widget.compact)
|
||||
IntrinsicHeight(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Game
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.primaryColor.withAlpha(230),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topLeft: Radius.circular(8),
|
||||
bottomLeft: Radius.circular(8),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 4,
|
||||
horizontal: 8,
|
||||
),
|
||||
child: Text(
|
||||
match.game.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
// Ruleset
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.primaryColor.withAlpha(140),
|
||||
borderRadius: const BorderRadius.only(
|
||||
topRight: Radius.circular(8),
|
||||
bottomRight: Radius.circular(8),
|
||||
),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 4,
|
||||
horizontal: 8,
|
||||
),
|
||||
child: Text(
|
||||
translateRulesetToString(match.game.ruleset, context),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
GameLabel(
|
||||
title: match.game.name,
|
||||
description: translateRulesetToString(
|
||||
match.game.ruleset,
|
||||
context,
|
||||
),
|
||||
color: match.game.color,
|
||||
),
|
||||
|
||||
const SizedBox(height: 12),
|
||||
@@ -303,30 +261,32 @@ class _MatchTileState extends State<MatchTile> {
|
||||
final mvp = widget.match.mvp;
|
||||
final mvpScore = widget.match.scores[mvp.first.id]?.score ?? 0;
|
||||
final mvpNames = mvp.map((player) => player.name).join(', ');
|
||||
|
||||
return '${loc.winner}: $mvpNames (${getPointLabel(loc, mvpScore)})';
|
||||
} else if (ruleset == Ruleset.placement) {
|
||||
return '${loc.winner}: ${widget.match.mvp.first.name}';
|
||||
} else if (ruleset == Ruleset.multipleWinners) {
|
||||
final mvpNames = widget.match.mvp.map((player) => player.name).join(', ');
|
||||
return '${loc.winners}: $mvpNames';
|
||||
}
|
||||
return '${loc.winner}: n.A.';
|
||||
}
|
||||
|
||||
Icon getMvpIcon() {
|
||||
const Icon(Icons.emoji_events, size: 20, color: Colors.amber);
|
||||
final icon = getRulesetIcon(widget.match.game.ruleset);
|
||||
|
||||
switch (widget.match.game.ruleset) {
|
||||
case Ruleset.singleWinner:
|
||||
return const Icon(Icons.emoji_events, size: 20, color: Colors.amber);
|
||||
return Icon(icon, size: 20, color: Colors.amber);
|
||||
case Ruleset.singleLoser:
|
||||
return const Icon(
|
||||
Icons.sentiment_dissatisfied_outlined,
|
||||
size: 20,
|
||||
color: Colors.blue,
|
||||
);
|
||||
return Icon(icon, size: 20, color: Colors.blue);
|
||||
case Ruleset.lowestScore:
|
||||
return const Icon(Icons.arrow_downward, size: 20, color: Colors.orange);
|
||||
return Icon(icon, size: 20, color: Colors.orange);
|
||||
case Ruleset.highestScore:
|
||||
return const Icon(Icons.arrow_upward, size: 20, color: Colors.green);
|
||||
default:
|
||||
return const Icon(Icons.emoji_events, size: 20, color: Colors.amber);
|
||||
return Icon(icon, size: 20, color: Colors.green);
|
||||
case Ruleset.multipleWinners:
|
||||
return Icon(icon, size: 20, color: Colors.amber);
|
||||
case Ruleset.placement:
|
||||
return Icon(icon, size: 20, color: Colors.deepOrangeAccent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class _QuickInfoTileState extends State<QuickInfoTile> {
|
||||
width: widget.width ?? 180,
|
||||
decoration: CustomTheme.standardBoxDecoration,
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
@@ -65,7 +65,6 @@ class _QuickInfoTileState extends State<QuickInfoTile> {
|
||||
),
|
||||
],
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
widget.value.toString(),
|
||||
style: const TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
|
||||
|
||||
@@ -10,7 +10,7 @@ class TextIconListTile extends StatelessWidget {
|
||||
super.key,
|
||||
required this.text,
|
||||
this.suffixText = '',
|
||||
this.iconEnabled = true,
|
||||
this.icon,
|
||||
this.onPressed,
|
||||
});
|
||||
|
||||
@@ -20,8 +20,8 @@ class TextIconListTile extends StatelessWidget {
|
||||
/// An optional suffix text to display after the main text.
|
||||
final String suffixText;
|
||||
|
||||
/// A boolean to determine if the icon should be displayed.
|
||||
final bool iconEnabled;
|
||||
/// The icon to display in the tile.
|
||||
final IconData? icon;
|
||||
|
||||
/// The callback to be invoked when the icon is pressed.
|
||||
final VoidCallback? onPressed;
|
||||
@@ -64,11 +64,8 @@ class TextIconListTile extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (iconEnabled)
|
||||
GestureDetector(
|
||||
onTap: onPressed,
|
||||
child: const Icon(Icons.add, size: 20),
|
||||
),
|
||||
if (icon != null)
|
||||
GestureDetector(onTap: onPressed, child: Icon(icon, size: 20)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -2,21 +2,17 @@ import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
|
||||
class TitleDescriptionListTile extends StatelessWidget {
|
||||
/// A list tile widget that displays a title and description, with optional highlighting and badge.
|
||||
/// A list tile widget that displays a title and description
|
||||
/// - [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.
|
||||
/// - [onTap]: 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.
|
||||
const TitleDescriptionListTile({
|
||||
super.key,
|
||||
required this.title,
|
||||
required this.description,
|
||||
this.onPressed,
|
||||
this.onTap,
|
||||
this.isHighlighted = false,
|
||||
this.badgeText,
|
||||
this.badgeColor,
|
||||
});
|
||||
|
||||
/// The title text displayed on the tile.
|
||||
@@ -26,21 +22,15 @@ class TitleDescriptionListTile extends StatelessWidget {
|
||||
final String description;
|
||||
|
||||
/// The callback invoked when the tile is tapped.
|
||||
final VoidCallback? onPressed;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
/// A boolean to determine if the tile should be highlighted.
|
||||
final bool isHighlighted;
|
||||
|
||||
/// Optional text to display in a badge on the right side of the title.
|
||||
final String? badgeText;
|
||||
|
||||
/// Optional color for the badge background.
|
||||
final Color? badgeColor;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return GestureDetector(
|
||||
onTap: onPressed,
|
||||
onTap: onTap,
|
||||
child: AnimatedContainer(
|
||||
margin: const EdgeInsets.symmetric(vertical: 10, horizontal: 10),
|
||||
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
|
||||
@@ -51,53 +41,26 @@ class TitleDescriptionListTile extends StatelessWidget {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 230,
|
||||
child: Text(
|
||||
title,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
softWrap: false,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
// Title
|
||||
SizedBox(
|
||||
width: 230,
|
||||
child: Text(
|
||||
title,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
softWrap: false,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
if (badgeText != null) ...[
|
||||
const Spacer(),
|
||||
Container(
|
||||
constraints: const BoxConstraints(maxWidth: 115),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 2,
|
||||
horizontal: 6,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: badgeColor ?? CustomTheme.primaryColor,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
badgeText!,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
softWrap: false,
|
||||
style: const TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Description
|
||||
if (description.isNotEmpty) ...[
|
||||
const SizedBox(height: 5),
|
||||
const SizedBox(height: 10),
|
||||
Text(description, style: const TextStyle(fontSize: 14)),
|
||||
const SizedBox(height: 2.5),
|
||||
],
|
||||
|
||||
@@ -35,13 +35,11 @@ class DataTransferService {
|
||||
final groups = await db.groupDao.getAllGroups();
|
||||
final players = await db.playerDao.getAllPlayers();
|
||||
final games = await db.gameDao.getAllGames();
|
||||
final teams = await db.teamDao.getAllTeams();
|
||||
|
||||
final Map<String, dynamic> jsonMap = {
|
||||
'players': players.map((player) => player.toJson()).toList(),
|
||||
'games': games.map((game) => game.toJson()).toList(),
|
||||
'groups': groups.map((group) => group.toJson()).toList(),
|
||||
'teams': teams.map((team) => team.toJson()).toList(),
|
||||
'matches': matches.map((match) => match.toJson()).toList(),
|
||||
};
|
||||
|
||||
@@ -130,8 +128,6 @@ class DataTransferService {
|
||||
final importedGroups = parseGroupsFromJson(decodedJson, playerById);
|
||||
final groupById = {for (final g in importedGroups) g.id: g};
|
||||
|
||||
final importedTeams = parseTeamsFromJson(decodedJson, playerById);
|
||||
|
||||
final importedMatches = parseMatchesFromJson(
|
||||
decodedJson,
|
||||
gameById,
|
||||
@@ -142,8 +138,7 @@ class DataTransferService {
|
||||
await db.playerDao.addPlayersAsList(players: importedPlayers);
|
||||
await db.gameDao.addGamesAsList(games: importedGames);
|
||||
await db.groupDao.addGroupsAsList(groups: importedGroups);
|
||||
await db.teamDao.addTeamsAsList(teams: importedTeams);
|
||||
await db.matchDao.addMatchAsList(matches: importedMatches);
|
||||
await db.matchDao.addMatchesAsList(matches: importedMatches);
|
||||
}
|
||||
|
||||
/* Parsing Methods */
|
||||
@@ -190,13 +185,12 @@ class DataTransferService {
|
||||
}).toList();
|
||||
}
|
||||
|
||||
/// Parses teams from JSON data.
|
||||
/// Parses teams from a list of JSON objects.
|
||||
@visibleForTesting
|
||||
static List<Team> parseTeamsFromJson(
|
||||
Map<String, dynamic> decodedJson,
|
||||
List<dynamic> teamsJson,
|
||||
Map<String, Player> playerById,
|
||||
) {
|
||||
final teamsJson = (decodedJson['teams'] as List<dynamic>?) ?? [];
|
||||
return teamsJson.map((t) {
|
||||
final map = t as Map<String, dynamic>;
|
||||
final memberIds = (map['memberIds'] as List<dynamic>? ?? [])
|
||||
@@ -259,12 +253,16 @@ class DataTransferService {
|
||||
.whereType<Player>()
|
||||
.toList();
|
||||
|
||||
final teamsJson = (map['teams'] as List<dynamic>?) ?? [];
|
||||
final teams = parseTeamsFromJson(teamsJson, playersMap);
|
||||
|
||||
return Match(
|
||||
id: id,
|
||||
name: name,
|
||||
game: game,
|
||||
group: group,
|
||||
players: players,
|
||||
teams: teams.isEmpty ? null : teams,
|
||||
createdAt: createdAt,
|
||||
endedAt: endedAt,
|
||||
notes: notes,
|
||||
|
||||
Reference in New Issue
Block a user