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