10 Commits

Author SHA1 Message Date
ddf32797aa Implemented ruleset in match view
Some checks failed
Pull Request Pipeline / test (pull_request) Successful in 43s
Pull Request Pipeline / lint (pull_request) Failing after 46s
2026-04-14 23:26:26 +02:00
df1bc4bf32 Merge branch 'development' into feature/132-verschiedene-regelsaetze-implementieren
# Conflicts:
#	lib/presentation/views/main_menu/match_view/match_result_view.dart
2026-04-14 23:09:15 +02:00
9b2fcf1860 Fix: Linter exclude
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 40s
Pull Request Pipeline / lint (pull_request) Successful in 46s
2026-03-08 22:27:27 +01:00
f0c575d2c9 Implemented different result view depending on ruleset
Some checks failed
Pull Request Pipeline / test (pull_request) Successful in 38s
Pull Request Pipeline / lint (pull_request) Failing after 45s
2026-03-08 22:25:55 +01:00
d5a7bb320f Implememented different result tiles in match detail view for different rulesets 2026-03-08 22:25:23 +01:00
84b8541822 Fixed match edit error with game
Some checks failed
Pull Request Pipeline / test (pull_request) Successful in 39s
Pull Request Pipeline / lint (pull_request) Failing after 46s
2026-03-08 11:00:42 +01:00
544e55c4fd Merge branch 'development' into feature/132-verschiedene-regelsaetze-implementieren
# Conflicts:
#	lib/l10n/arb/app_de.arb
#	lib/l10n/arb/app_en.arb
#	lib/l10n/generated/app_localizations.dart
#	lib/l10n/generated/app_localizations_de.dart
#	lib/l10n/generated/app_localizations_en.dart
#	lib/presentation/views/main_menu/match_view/match_result_view.dart
2026-03-08 10:57:33 +01:00
c50ad288fa Implemented basic structure
Some checks failed
Pull Request Pipeline / test (pull_request) Successful in 39s
Pull Request Pipeline / lint (pull_request) Failing after 44s
2026-03-08 08:29:45 +01:00
494dec8c61 Added localizations 2026-03-08 08:29:15 +01:00
975679b048 Updated dependencie 2026-03-08 08:24:35 +01:00
22 changed files with 520 additions and 636 deletions

View File

@@ -1,5 +1,9 @@
include: package:flutter_lints/flutter.yaml
analyzer:
exclude:
- lib/presentation/views/main_menu/settings_view/licenses/oss_licenses.dart
linter:
rules:
avoid_print: false
@@ -11,8 +15,4 @@ linter:
prefer_const_literals_to_create_immutables: true
unnecessary_const: true
lines_longer_than_80_chars: false
constant_identifier_names: false
analyzer:
exclude:
- lib/presentation/views/main_menu/settings_view/licenses/oss_licenses.dart
constant_identifier_names: false

View File

@@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:tallee/core/enums.dart';
import 'package:tallee/data/models/match.dart';
import 'package:tallee/data/models/player.dart';
import 'package:tallee/l10n/generated/app_localizations.dart';
/// Translates a [Ruleset] enum value to its corresponding localized string.
@@ -44,10 +43,3 @@ String getExtraPlayerCount(Match match) {
}
return ' + ${count.toString()}';
}
String getNameCountText(Player player) {
if (player.nameCount >= 1) {
return ' #${player.nameCount}';
}
return '';
}

View File

@@ -85,21 +85,21 @@ class CustomTheme {
);
static const SearchBarThemeData searchBarTheme = SearchBarThemeData(
textStyle: WidgetStatePropertyAll(TextStyle(color: CustomTheme.textColor)),
hintStyle: WidgetStatePropertyAll(TextStyle(color: CustomTheme.hintColor)),
textStyle: WidgetStatePropertyAll(TextStyle(color: textColor)),
hintStyle: WidgetStatePropertyAll(TextStyle(color: hintColor)),
);
static final RadioThemeData radioTheme = RadioThemeData(
fillColor: WidgetStateProperty.resolveWith<Color>((states) {
if (states.contains(WidgetState.selected)) {
return CustomTheme.primaryColor;
return primaryColor;
}
return CustomTheme.textColor;
return textColor;
}),
);
static const InputDecorationTheme inputDecorationTheme = InputDecorationTheme(
labelStyle: TextStyle(color: CustomTheme.textColor),
hintStyle: TextStyle(color: CustomTheme.hintColor),
labelStyle: TextStyle(color: textColor),
hintStyle: TextStyle(color: hintColor),
);
}

View File

@@ -1,5 +1,4 @@
import 'package:drift/drift.dart';
import 'package:flutter/cupertino.dart';
import 'package:tallee/data/db/database.dart';
import 'package:tallee/data/db/tables/player_table.dart';
import 'package:tallee/data/models/player.dart';
@@ -21,7 +20,6 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
name: row.name,
description: row.description,
createdAt: row.createdAt,
nameCount: row.nameCount,
),
)
.toList();
@@ -36,7 +34,6 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
name: result.name,
description: result.description,
createdAt: result.createdAt,
nameCount: result.nameCount,
);
}
@@ -45,15 +42,12 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
/// the new one.
Future<bool> addPlayer({required Player player}) async {
if (!await playerExists(playerId: player.id)) {
final int nameCount = await calculateNameCount(name: player.name);
await into(playerTable).insert(
PlayerTableCompanion.insert(
id: player.id,
name: player.name,
description: player.description,
createdAt: player.createdAt,
nameCount: Value(nameCount),
),
mode: InsertMode.insertOrReplace,
);
@@ -68,67 +62,20 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
Future<bool> addPlayersAsList({required List<Player> players}) async {
if (players.isEmpty) return false;
// Filter out players that already exist
final newPlayers = <Player>[];
for (final player in players) {
if (!await playerExists(playerId: player.id)) {
newPlayers.add(player);
}
}
if (newPlayers.isEmpty) return false;
// Group players by name
final nameGroups = <String, List<Player>>{};
for (final player in newPlayers) {
nameGroups.putIfAbsent(player.name, () => []).add(player);
}
final playersToInsert = <PlayerTableCompanion>[];
// Process each group of players with the same name
for (final entry in nameGroups.entries) {
final name = entry.key;
final playersWithName = entry.value;
// Get the current nameCount
var nameCount = await calculateNameCount(name: name);
// One player with the same name
if (playersWithName.length == 1) {
final player = playersWithName[0];
playersToInsert.add(
PlayerTableCompanion.insert(
id: player.id,
name: player.name,
description: player.description,
createdAt: player.createdAt,
nameCount: Value(nameCount),
),
);
} else {
if (nameCount == 0) nameCount++;
// Multiple players with the same name
for (var i = 0; i < playersWithName.length; i++) {
final player = playersWithName[i];
playersToInsert.add(
PlayerTableCompanion.insert(
id: player.id,
name: player.name,
description: player.description,
createdAt: player.createdAt,
nameCount: Value(nameCount + i),
),
);
}
}
}
await db.batch(
(b) => b.insertAll(
playerTable,
playersToInsert,
mode: InsertMode.insertOrReplace,
players
.map(
(player) => PlayerTableCompanion.insert(
id: player.id,
name: player.name,
description: player.description,
createdAt: player.createdAt,
),
)
.toList(),
mode: InsertMode.insertOrIgnore,
),
);
@@ -143,7 +90,7 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
return rowsAffected > 0;
}
/// Checks if a player with the given [playerId] exists in the database.
/// Checks if a player with the given [id] exists in the database.
/// Returns `true` if the player exists, `false` otherwise.
Future<bool> playerExists({required String playerId}) async {
final query = select(playerTable)..where((p) => p.id.equals(playerId));
@@ -156,38 +103,9 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
required String playerId,
required String newName,
}) async {
// Get previous name and name count for the player before updating
final previousPlayerName =
await (select(playerTable)..where((p) => p.id.equals(playerId)))
.map((row) => row.name)
.getSingleOrNull() ??
'';
final previousNameCount = await getNameCount(name: previousPlayerName);
await (update(playerTable)..where((p) => p.id.equals(playerId))).write(
PlayerTableCompanion(name: Value(newName)),
);
// Update name count for the new name
final count = await calculateNameCount(name: newName);
if (count > 0) {
await (update(playerTable)..where((p) => p.name.equals(newName))).write(
PlayerTableCompanion(nameCount: Value(count)),
);
}
if (previousNameCount > 0) {
// Get the player with that name and the hightest nameCount, and update their nameCount to previousNameCount
final player = await getPlayerWithHighestNameCount(
name: previousPlayerName,
);
if (player != null) {
await updateNameCount(
playerId: player.id,
nameCount: previousNameCount,
);
}
}
}
/// Retrieves the total count of players in the database.
@@ -199,76 +117,6 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
return count ?? 0;
}
/// Retrieves the count of players with the given [name].
Future<int> getNameCount({required String name}) async {
final query = select(playerTable)..where((p) => p.name.equals(name));
final result = await query.get();
return result.length;
}
/// Updates the nameCount for the player with the given [playerId] to [nameCount].
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> updateNameCount({
required String playerId,
required int nameCount,
}) async {
final query = update(playerTable)..where((p) => p.id.equals(playerId));
final rowsAffected = await query.write(
PlayerTableCompanion(nameCount: Value(nameCount)),
);
return rowsAffected > 0;
}
@visibleForTesting
Future<Player?> getPlayerWithHighestNameCount({required String name}) async {
final query = select(playerTable)
..where((p) => p.name.equals(name))
..orderBy([(p) => OrderingTerm.desc(p.nameCount)])
..limit(1);
final result = await query.getSingleOrNull();
if (result != null) {
return Player(
id: result.id,
name: result.name,
description: result.description,
createdAt: result.createdAt,
nameCount: result.nameCount,
);
}
return null;
}
@visibleForTesting
Future<int> calculateNameCount({required String name}) async {
final count = await getNameCount(name: name);
final int nameCount;
if (count == 1) {
// If one other player exists with the same name, initialize the nameCount
await initializeNameCount(name: name);
// And for the new player, set nameCount to 2
nameCount = 2;
} else if (count > 1) {
// If more than one player exists with the same name, just increment
// the nameCount for the new player
nameCount = count + 1;
} else {
// If no other players exist with the same name, set nameCount to 0
nameCount = 0;
}
return nameCount;
}
@visibleForTesting
Future<bool> initializeNameCount({required String name}) async {
final rowsAffected =
await (update(playerTable)..where((p) => p.name.equals(name))).write(
const PlayerTableCompanion(nameCount: Value(1)),
);
return rowsAffected > 0;
}
/// Deletes all players from the database.
/// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> deleteAllPlayers() async {

View File

@@ -18,17 +18,6 @@ class $PlayerTableTable extends PlayerTable
type: DriftSqlType.string,
requiredDuringInsert: true,
);
static const VerificationMeta _createdAtMeta = const VerificationMeta(
'createdAt',
);
@override
late final GeneratedColumn<DateTime> createdAt = GeneratedColumn<DateTime>(
'created_at',
aliasedName,
false,
type: DriftSqlType.dateTime,
requiredDuringInsert: true,
);
static const VerificationMeta _nameMeta = const VerificationMeta('name');
@override
late final GeneratedColumn<String> name = GeneratedColumn<String>(
@@ -38,18 +27,6 @@ class $PlayerTableTable extends PlayerTable
type: DriftSqlType.string,
requiredDuringInsert: true,
);
static const VerificationMeta _nameCountMeta = const VerificationMeta(
'nameCount',
);
@override
late final GeneratedColumn<int> nameCount = GeneratedColumn<int>(
'name_count',
aliasedName,
false,
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultValue: const Constant(0),
);
static const VerificationMeta _descriptionMeta = const VerificationMeta(
'description',
);
@@ -61,14 +38,19 @@ class $PlayerTableTable extends PlayerTable
type: DriftSqlType.string,
requiredDuringInsert: true,
);
static const VerificationMeta _createdAtMeta = const VerificationMeta(
'createdAt',
);
@override
List<GeneratedColumn> get $columns => [
id,
createdAt,
name,
nameCount,
description,
];
late final GeneratedColumn<DateTime> createdAt = GeneratedColumn<DateTime>(
'created_at',
aliasedName,
false,
type: DriftSqlType.dateTime,
requiredDuringInsert: true,
);
@override
List<GeneratedColumn> get $columns => [id, name, description, createdAt];
@override
String get aliasedName => _alias ?? actualTableName;
@override
@@ -86,14 +68,6 @@ class $PlayerTableTable extends PlayerTable
} else if (isInserting) {
context.missing(_idMeta);
}
if (data.containsKey('created_at')) {
context.handle(
_createdAtMeta,
createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta),
);
} else if (isInserting) {
context.missing(_createdAtMeta);
}
if (data.containsKey('name')) {
context.handle(
_nameMeta,
@@ -102,12 +76,6 @@ class $PlayerTableTable extends PlayerTable
} else if (isInserting) {
context.missing(_nameMeta);
}
if (data.containsKey('name_count')) {
context.handle(
_nameCountMeta,
nameCount.isAcceptableOrUnknown(data['name_count']!, _nameCountMeta),
);
}
if (data.containsKey('description')) {
context.handle(
_descriptionMeta,
@@ -119,6 +87,14 @@ class $PlayerTableTable extends PlayerTable
} else if (isInserting) {
context.missing(_descriptionMeta);
}
if (data.containsKey('created_at')) {
context.handle(
_createdAtMeta,
createdAt.isAcceptableOrUnknown(data['created_at']!, _createdAtMeta),
);
} else if (isInserting) {
context.missing(_createdAtMeta);
}
return context;
}
@@ -132,22 +108,18 @@ class $PlayerTableTable extends PlayerTable
DriftSqlType.string,
data['${effectivePrefix}id'],
)!,
createdAt: attachedDatabase.typeMapping.read(
DriftSqlType.dateTime,
data['${effectivePrefix}created_at'],
)!,
name: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}name'],
)!,
nameCount: attachedDatabase.typeMapping.read(
DriftSqlType.int,
data['${effectivePrefix}name_count'],
)!,
description: attachedDatabase.typeMapping.read(
DriftSqlType.string,
data['${effectivePrefix}description'],
)!,
createdAt: attachedDatabase.typeMapping.read(
DriftSqlType.dateTime,
data['${effectivePrefix}created_at'],
)!,
);
}
@@ -159,35 +131,31 @@ class $PlayerTableTable extends PlayerTable
class PlayerTableData extends DataClass implements Insertable<PlayerTableData> {
final String id;
final DateTime createdAt;
final String name;
final int nameCount;
final String description;
final DateTime createdAt;
const PlayerTableData({
required this.id,
required this.createdAt,
required this.name,
required this.nameCount,
required this.description,
required this.createdAt,
});
@override
Map<String, Expression> toColumns(bool nullToAbsent) {
final map = <String, Expression>{};
map['id'] = Variable<String>(id);
map['created_at'] = Variable<DateTime>(createdAt);
map['name'] = Variable<String>(name);
map['name_count'] = Variable<int>(nameCount);
map['description'] = Variable<String>(description);
map['created_at'] = Variable<DateTime>(createdAt);
return map;
}
PlayerTableCompanion toCompanion(bool nullToAbsent) {
return PlayerTableCompanion(
id: Value(id),
createdAt: Value(createdAt),
name: Value(name),
nameCount: Value(nameCount),
description: Value(description),
createdAt: Value(createdAt),
);
}
@@ -198,10 +166,9 @@ class PlayerTableData extends DataClass implements Insertable<PlayerTableData> {
serializer ??= driftRuntimeOptions.defaultSerializer;
return PlayerTableData(
id: serializer.fromJson<String>(json['id']),
createdAt: serializer.fromJson<DateTime>(json['createdAt']),
name: serializer.fromJson<String>(json['name']),
nameCount: serializer.fromJson<int>(json['nameCount']),
description: serializer.fromJson<String>(json['description']),
createdAt: serializer.fromJson<DateTime>(json['createdAt']),
);
}
@override
@@ -209,35 +176,31 @@ class PlayerTableData extends DataClass implements Insertable<PlayerTableData> {
serializer ??= driftRuntimeOptions.defaultSerializer;
return <String, dynamic>{
'id': serializer.toJson<String>(id),
'createdAt': serializer.toJson<DateTime>(createdAt),
'name': serializer.toJson<String>(name),
'nameCount': serializer.toJson<int>(nameCount),
'description': serializer.toJson<String>(description),
'createdAt': serializer.toJson<DateTime>(createdAt),
};
}
PlayerTableData copyWith({
String? id,
DateTime? createdAt,
String? name,
int? nameCount,
String? description,
DateTime? createdAt,
}) => PlayerTableData(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
name: name ?? this.name,
nameCount: nameCount ?? this.nameCount,
description: description ?? this.description,
createdAt: createdAt ?? this.createdAt,
);
PlayerTableData copyWithCompanion(PlayerTableCompanion data) {
return PlayerTableData(
id: data.id.present ? data.id.value : this.id,
createdAt: data.createdAt.present ? data.createdAt.value : this.createdAt,
name: data.name.present ? data.name.value : this.name,
nameCount: data.nameCount.present ? data.nameCount.value : this.nameCount,
description: data.description.present
? data.description.value
: this.description,
createdAt: data.createdAt.present ? data.createdAt.value : this.createdAt,
);
}
@@ -245,85 +208,76 @@ class PlayerTableData extends DataClass implements Insertable<PlayerTableData> {
String toString() {
return (StringBuffer('PlayerTableData(')
..write('id: $id, ')
..write('createdAt: $createdAt, ')
..write('name: $name, ')
..write('nameCount: $nameCount, ')
..write('description: $description')
..write('description: $description, ')
..write('createdAt: $createdAt')
..write(')'))
.toString();
}
@override
int get hashCode => Object.hash(id, createdAt, name, nameCount, description);
int get hashCode => Object.hash(id, name, description, createdAt);
@override
bool operator ==(Object other) =>
identical(this, other) ||
(other is PlayerTableData &&
other.id == this.id &&
other.createdAt == this.createdAt &&
other.name == this.name &&
other.nameCount == this.nameCount &&
other.description == this.description);
other.description == this.description &&
other.createdAt == this.createdAt);
}
class PlayerTableCompanion extends UpdateCompanion<PlayerTableData> {
final Value<String> id;
final Value<DateTime> createdAt;
final Value<String> name;
final Value<int> nameCount;
final Value<String> description;
final Value<DateTime> createdAt;
final Value<int> rowid;
const PlayerTableCompanion({
this.id = const Value.absent(),
this.createdAt = const Value.absent(),
this.name = const Value.absent(),
this.nameCount = const Value.absent(),
this.description = const Value.absent(),
this.createdAt = const Value.absent(),
this.rowid = const Value.absent(),
});
PlayerTableCompanion.insert({
required String id,
required DateTime createdAt,
required String name,
this.nameCount = const Value.absent(),
required String description,
required DateTime createdAt,
this.rowid = const Value.absent(),
}) : id = Value(id),
createdAt = Value(createdAt),
name = Value(name),
description = Value(description);
description = Value(description),
createdAt = Value(createdAt);
static Insertable<PlayerTableData> custom({
Expression<String>? id,
Expression<DateTime>? createdAt,
Expression<String>? name,
Expression<int>? nameCount,
Expression<String>? description,
Expression<DateTime>? createdAt,
Expression<int>? rowid,
}) {
return RawValuesInsertable({
if (id != null) 'id': id,
if (createdAt != null) 'created_at': createdAt,
if (name != null) 'name': name,
if (nameCount != null) 'name_count': nameCount,
if (description != null) 'description': description,
if (createdAt != null) 'created_at': createdAt,
if (rowid != null) 'rowid': rowid,
});
}
PlayerTableCompanion copyWith({
Value<String>? id,
Value<DateTime>? createdAt,
Value<String>? name,
Value<int>? nameCount,
Value<String>? description,
Value<DateTime>? createdAt,
Value<int>? rowid,
}) {
return PlayerTableCompanion(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
name: name ?? this.name,
nameCount: nameCount ?? this.nameCount,
description: description ?? this.description,
createdAt: createdAt ?? this.createdAt,
rowid: rowid ?? this.rowid,
);
}
@@ -334,18 +288,15 @@ class PlayerTableCompanion extends UpdateCompanion<PlayerTableData> {
if (id.present) {
map['id'] = Variable<String>(id.value);
}
if (createdAt.present) {
map['created_at'] = Variable<DateTime>(createdAt.value);
}
if (name.present) {
map['name'] = Variable<String>(name.value);
}
if (nameCount.present) {
map['name_count'] = Variable<int>(nameCount.value);
}
if (description.present) {
map['description'] = Variable<String>(description.value);
}
if (createdAt.present) {
map['created_at'] = Variable<DateTime>(createdAt.value);
}
if (rowid.present) {
map['rowid'] = Variable<int>(rowid.value);
}
@@ -356,10 +307,9 @@ class PlayerTableCompanion extends UpdateCompanion<PlayerTableData> {
String toString() {
return (StringBuffer('PlayerTableCompanion(')
..write('id: $id, ')
..write('createdAt: $createdAt, ')
..write('name: $name, ')
..write('nameCount: $nameCount, ')
..write('description: $description, ')
..write('createdAt: $createdAt, ')
..write('rowid: $rowid')
..write(')'))
.toString();
@@ -2840,19 +2790,17 @@ abstract class _$AppDatabase extends GeneratedDatabase {
typedef $$PlayerTableTableCreateCompanionBuilder =
PlayerTableCompanion Function({
required String id,
required DateTime createdAt,
required String name,
Value<int> nameCount,
required String description,
required DateTime createdAt,
Value<int> rowid,
});
typedef $$PlayerTableTableUpdateCompanionBuilder =
PlayerTableCompanion Function({
Value<String> id,
Value<DateTime> createdAt,
Value<String> name,
Value<int> nameCount,
Value<String> description,
Value<DateTime> createdAt,
Value<int> rowid,
});
@@ -2944,23 +2892,18 @@ class $$PlayerTableTableFilterComposer
builder: (column) => ColumnFilters(column),
);
ColumnFilters<DateTime> get createdAt => $composableBuilder(
column: $table.createdAt,
builder: (column) => ColumnFilters(column),
);
ColumnFilters<String> get name => $composableBuilder(
column: $table.name,
builder: (column) => ColumnFilters(column),
);
ColumnFilters<int> get nameCount => $composableBuilder(
column: $table.nameCount,
ColumnFilters<String> get description => $composableBuilder(
column: $table.description,
builder: (column) => ColumnFilters(column),
);
ColumnFilters<String> get description => $composableBuilder(
column: $table.description,
ColumnFilters<DateTime> get createdAt => $composableBuilder(
column: $table.createdAt,
builder: (column) => ColumnFilters(column),
);
@@ -3054,23 +2997,18 @@ class $$PlayerTableTableOrderingComposer
builder: (column) => ColumnOrderings(column),
);
ColumnOrderings<DateTime> get createdAt => $composableBuilder(
column: $table.createdAt,
builder: (column) => ColumnOrderings(column),
);
ColumnOrderings<String> get name => $composableBuilder(
column: $table.name,
builder: (column) => ColumnOrderings(column),
);
ColumnOrderings<int> get nameCount => $composableBuilder(
column: $table.nameCount,
ColumnOrderings<String> get description => $composableBuilder(
column: $table.description,
builder: (column) => ColumnOrderings(column),
);
ColumnOrderings<String> get description => $composableBuilder(
column: $table.description,
ColumnOrderings<DateTime> get createdAt => $composableBuilder(
column: $table.createdAt,
builder: (column) => ColumnOrderings(column),
);
}
@@ -3087,20 +3025,17 @@ class $$PlayerTableTableAnnotationComposer
GeneratedColumn<String> get id =>
$composableBuilder(column: $table.id, builder: (column) => column);
GeneratedColumn<DateTime> get createdAt =>
$composableBuilder(column: $table.createdAt, builder: (column) => column);
GeneratedColumn<String> get name =>
$composableBuilder(column: $table.name, builder: (column) => column);
GeneratedColumn<int> get nameCount =>
$composableBuilder(column: $table.nameCount, builder: (column) => column);
GeneratedColumn<String> get description => $composableBuilder(
column: $table.description,
builder: (column) => column,
);
GeneratedColumn<DateTime> get createdAt =>
$composableBuilder(column: $table.createdAt, builder: (column) => column);
Expression<T> playerGroupTableRefs<T extends Object>(
Expression<T> Function($$PlayerGroupTableTableAnnotationComposer a) f,
) {
@@ -3210,33 +3145,29 @@ class $$PlayerTableTableTableManager
updateCompanionCallback:
({
Value<String> id = const Value.absent(),
Value<DateTime> createdAt = const Value.absent(),
Value<String> name = const Value.absent(),
Value<int> nameCount = const Value.absent(),
Value<String> description = const Value.absent(),
Value<DateTime> createdAt = const Value.absent(),
Value<int> rowid = const Value.absent(),
}) => PlayerTableCompanion(
id: id,
createdAt: createdAt,
name: name,
nameCount: nameCount,
description: description,
createdAt: createdAt,
rowid: rowid,
),
createCompanionCallback:
({
required String id,
required DateTime createdAt,
required String name,
Value<int> nameCount = const Value.absent(),
required String description,
required DateTime createdAt,
Value<int> rowid = const Value.absent(),
}) => PlayerTableCompanion.insert(
id: id,
createdAt: createdAt,
name: name,
nameCount: nameCount,
description: description,
createdAt: createdAt,
rowid: rowid,
),
withReferenceMapper: (p0) => p0

View File

@@ -2,10 +2,9 @@ import 'package:drift/drift.dart';
class PlayerTable extends Table {
TextColumn get id => text()();
DateTimeColumn get createdAt => dateTime()();
TextColumn get name => text()();
IntColumn get nameCount => integer().withDefault(const Constant(0))();
TextColumn get description => text()();
DateTimeColumn get createdAt => dateTime()();
@override
Set<Column<Object>> get primaryKey => {id};

View File

@@ -5,14 +5,12 @@ class Player {
final String id;
final DateTime createdAt;
final String name;
int nameCount;
final String description;
Player({
String? id,
DateTime? createdAt,
required this.name,
this.nameCount = 0,
String? description,
}) : id = id ?? const Uuid().v4(),
createdAt = createdAt ?? clock.now(),
@@ -20,7 +18,7 @@ class Player {
@override
String toString() {
return 'Player{id: $id, createdAt: $createdAt, name: $name, nameCount: $nameCount, description: $description}';
return 'Player{id: $id, name: $name, description: $description}';
}
/// Creates a Player instance from a JSON object.
@@ -28,7 +26,6 @@ class Player {
: id = json['id'],
createdAt = DateTime.parse(json['createdAt']),
name = json['name'],
nameCount = 0,
description = json['description'];
/// Converts the Player instance to a JSON object.

View File

@@ -22,10 +22,11 @@
"days_ago": "vor {count} Tagen",
"delete": "Löschen",
"delete_all_data": "Alle Daten löschen",
"delete_group": "Diese Gruppe löschen",
"delete_group": "Gruppe löschen",
"delete_match": "Spiel löschen",
"edit_group": "Gruppe bearbeiten",
"edit_match": "Gruppe bearbeiten",
"enter_points": "Punkte eingeben",
"enter_results": "Ergebnisse eintragen",
"error_creating_group": "Fehler beim Erstellen der Gruppe, bitte erneut versuchen",
"error_deleting_group": "Fehler beim Löschen der Gruppe, bitte erneut versuchen",
@@ -74,6 +75,7 @@
"player_name": "Spieler:innenname",
"players": "Spieler:innen",
"players_count": "{count} Spieler",
"points": "Punkte",
"privacy_policy": "Datenschutzerklärung",
"quick_create": "Schnellzugriff",
"recent_matches": "Letzte Spiele",
@@ -87,12 +89,14 @@
"save_changes": "Änderungen speichern",
"search_for_groups": "Nach Gruppen suchen",
"search_for_players": "Nach Spieler:innen suchen",
"select_winner": "Gewinner:in wählen:",
"select_winner": "Gewinner:in wählen",
"select_loser": "Verlierer:in wählen",
"selected_players": "Ausgewählte Spieler:innen",
"settings": "Einstellungen",
"single_loser": "Ein:e Verlierer:in",
"single_winner": "Ein:e Gewinner:in",
"highest_score": "Höchste Punkte",
"loser": "Verlierer:in",
"lowest_score": "Niedrigste Punkte",
"multiple_winners": "Mehrere Gewinner:innen",
"statistics": "Statistiken",

View File

@@ -83,6 +83,9 @@
"@edit_match": {
"description": "Button & Appbar label for editing a match"
},
"@enter_points": {
"description": "Label to enter players points"
},
"@enter_results": {
"description": "Button text to enter match results"
},
@@ -232,6 +235,9 @@
}
}
},
"@points": {
"description": "Points label"
},
"@privacy_policy": {
"description": "Privacy policy menu item"
},
@@ -271,6 +277,9 @@
"@select_winner": {
"description": "Label to select the winner"
},
"@select_loser": {
"description": "Label to select the loser"
},
"@selected_players": {
"description": "Shows the number of selected players"
},
@@ -351,6 +360,7 @@
"delete_match": "Delete Match",
"edit_group": "Edit Group",
"edit_match": "Edit Match",
"enter_points": "Enter points",
"enter_results": "Enter Results",
"error_creating_group": "Error while creating group, please try again",
"error_deleting_group": "Error while deleting group, please try again",
@@ -399,6 +409,7 @@
"player_name": "Player name",
"players": "Players",
"players_count": "{count} Players",
"points": "Points",
"privacy_policy": "Privacy Policy",
"quick_create": "Quick Create",
"recent_matches": "Recent Matches",
@@ -411,12 +422,14 @@
"save_changes": "Save Changes",
"search_for_groups": "Search for groups",
"search_for_players": "Search for players",
"select_winner": "Select Winner:",
"select_winner": "Select Winner",
"select_loser": "Select Loser",
"selected_players": "Selected players",
"settings": "Settings",
"single_loser": "Single Loser",
"single_winner": "Single Winner",
"highest_score": "Highest Score",
"loser": "Loser",
"lowest_score": "Lowest Score",
"multiple_winners": "Multiple Winners",
"statistics": "Statistics",

View File

@@ -254,6 +254,12 @@ abstract class AppLocalizations {
/// **'Edit Match'**
String get edit_match;
/// Label to enter players points
///
/// In en, this message translates to:
/// **'Enter points'**
String get enter_points;
/// Button text to enter match results
///
/// In en, this message translates to:
@@ -542,6 +548,12 @@ abstract class AppLocalizations {
/// **'{count} Players'**
String players_count(int count);
/// Points label
///
/// In en, this message translates to:
/// **'Points'**
String get points;
/// Privacy policy menu item
///
/// In en, this message translates to:
@@ -617,9 +629,15 @@ abstract class AppLocalizations {
/// Label to select the winner
///
/// In en, this message translates to:
/// **'Select Winner:'**
/// **'Select Winner'**
String get select_winner;
/// Label to select the loser
///
/// In en, this message translates to:
/// **'Select Loser'**
String get select_loser;
/// Shows the number of selected players
///
/// In en, this message translates to:
@@ -650,6 +668,12 @@ abstract class AppLocalizations {
/// **'Highest Score'**
String get highest_score;
/// No description provided for @loser.
///
/// In en, this message translates to:
/// **'Loser'**
String get loser;
/// No description provided for @lowest_score.
///
/// In en, this message translates to:

View File

@@ -79,7 +79,7 @@ class AppLocalizationsDe extends AppLocalizations {
String get delete_all_data => 'Alle Daten löschen';
@override
String get delete_group => 'Diese Gruppe löschen';
String get delete_group => 'Gruppe löschen';
@override
String get delete_match => 'Spiel löschen';
@@ -90,6 +90,9 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get edit_match => 'Gruppe bearbeiten';
@override
String get enter_points => 'Punkte eingeben';
@override
String get enter_results => 'Ergebnisse eintragen';
@@ -240,6 +243,9 @@ class AppLocalizationsDe extends AppLocalizations {
return '$count Spieler';
}
@override
String get points => 'Punkte';
@override
String get privacy_policy => 'Datenschutzerklärung';
@@ -281,7 +287,10 @@ class AppLocalizationsDe extends AppLocalizations {
String get search_for_players => 'Nach Spieler:innen suchen';
@override
String get select_winner => 'Gewinner:in wählen:';
String get select_winner => 'Gewinner:in wählen';
@override
String get select_loser => 'Verlierer:in wählen';
@override
String get selected_players => 'Ausgewählte Spieler:innen';
@@ -298,6 +307,9 @@ class AppLocalizationsDe extends AppLocalizations {
@override
String get highest_score => 'Höchste Punkte';
@override
String get loser => 'Verlierer:in';
@override
String get lowest_score => 'Niedrigste Punkte';

View File

@@ -90,6 +90,9 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get edit_match => 'Edit Match';
@override
String get enter_points => 'Enter points';
@override
String get enter_results => 'Enter Results';
@@ -240,6 +243,9 @@ class AppLocalizationsEn extends AppLocalizations {
return '$count Players';
}
@override
String get points => 'Points';
@override
String get privacy_policy => 'Privacy Policy';
@@ -281,7 +287,10 @@ class AppLocalizationsEn extends AppLocalizations {
String get search_for_players => 'Search for players';
@override
String get select_winner => 'Select Winner:';
String get select_winner => 'Select Winner';
@override
String get select_loser => 'Select Loser';
@override
String get selected_players => 'Selected players';
@@ -298,6 +307,9 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get highest_score => 'Highest Score';
@override
String get loser => 'Loser';
@override
String get lowest_score => 'Lowest Score';

View File

@@ -2,7 +2,6 @@ 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/models/group.dart';
@@ -154,7 +153,6 @@ class _GroupDetailViewState extends State<GroupDetailView> {
children: _group.members.map((member) {
return TextIconTile(
text: member.name,
suffixText: getNameCountText(member),
iconEnabled: false,
);
}).toList(),

View File

@@ -4,6 +4,7 @@ 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/core/enums.dart';
import 'package:tallee/data/db/database.dart';
import 'package:tallee/data/models/match.dart';
import 'package:tallee/l10n/generated/app_localizations.dart';
@@ -161,7 +162,6 @@ class _MatchDetailViewState extends State<MatchDetailView> {
children: match.players.map((player) {
return TextIconTile(
text: player.name,
suffixText: getNameCountText(player),
iconEnabled: false,
);
}).toList(),
@@ -176,37 +176,7 @@ class _MatchDetailViewState extends State<MatchDetailView> {
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,
),
),
],
],
),
child: getResultWidget(loc),
),
),
],
@@ -265,4 +235,91 @@ class _MatchDetailViewState extends State<MatchDetailView> {
});
widget.onMatchUpdate.call();
}
/// Returns the widget to be displayed in the result [InfoTile]
/// TODO: Update when score logic is overhauled
Widget getResultWidget(AppLocalizations loc) {
if (isSingleRowResult()) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: getResultRow(loc),
);
} else {
return Column(
children: [
for (var player in match.players)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
player.name,
style: const TextStyle(
fontSize: 16,
color: CustomTheme.textColor,
),
),
Text(
'0 ${loc.points}',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: CustomTheme.primaryColor,
),
),
],
),
],
);
}
}
/// Returns the result row for single winner/loser rulesets or a placeholder
/// if no result is entered yet
/// TODO: Update when score logic is overhauled
List<Widget> getResultRow(AppLocalizations loc) {
if (match.winner != null && match.game.ruleset == Ruleset.singleWinner) {
return [
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 if (match.game.ruleset == Ruleset.singleLoser) {
return [
Text(
loc.loser,
style: const TextStyle(fontSize: 16, color: CustomTheme.textColor),
),
Text(
match.winner!.name,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color: CustomTheme.primaryColor,
),
),
];
} else {
return [
Text(
loc.no_results_entered_yet,
style: const TextStyle(fontSize: 14, color: CustomTheme.textColor),
),
];
}
}
// Returns if the result can be displayed in a single row
bool isSingleRowResult() {
return match.game.ruleset == Ruleset.singleWinner ||
match.game.ruleset == Ruleset.singleLoser;
}
}

View File

@@ -1,21 +1,33 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:tallee/core/custom_theme.dart';
import 'package:tallee/core/enums.dart';
import 'package:tallee/data/db/database.dart';
import 'package:tallee/data/models/match.dart';
import 'package:tallee/data/models/player.dart';
import 'package:tallee/l10n/generated/app_localizations.dart';
import 'package:tallee/presentation/widgets/buttons/custom_width_button.dart';
import 'package:tallee/presentation/widgets/tiles/custom_radio_list_tile.dart';
import 'package:tallee/presentation/widgets/tiles/score_list_tile.dart';
class MatchResultView extends StatefulWidget {
/// A view that allows selecting and saving the winner of a match
/// [match]: The match for which the winner is to be selected
/// [onWinnerChanged]: Optional callback invoked when the winner is changed
const MatchResultView({super.key, required this.match, this.onWinnerChanged});
const MatchResultView({
super.key,
required this.match,
this.ruleset = Ruleset.singleWinner,
this.onWinnerChanged,
});
/// The match for which the winner is to be selected
final Match match;
/// The ruleset of the match, determines how the winner is selected or how
/// scores are entered
final Ruleset ruleset;
/// Optional callback invoked when the winner is changed
final VoidCallback? onWinnerChanged;
@@ -29,6 +41,9 @@ class _MatchResultViewState extends State<MatchResultView> {
/// List of all players who participated in the match
late final List<Player> allPlayers;
/// List of text controllers for score entry, one for each player
late final List<TextEditingController> controller;
/// Currently selected winner player
Player? _selectedPlayer;
@@ -39,10 +54,19 @@ class _MatchResultViewState extends State<MatchResultView> {
allPlayers = widget.match.players;
allPlayers.sort((a, b) => a.name.compareTo(b.name));
controller = List.generate(
allPlayers.length,
(index) => TextEditingController(),
);
if (widget.match.winner != null) {
_selectedPlayer = allPlayers.firstWhere(
(p) => p.id == widget.match.winner!.id,
);
if (rulesetSupportsWinnerSelection()) {
_selectedPlayer = allPlayers.firstWhere(
(p) => p.id == widget.match.winner!.id,
);
} else if (rulesetSupportsScoreEntry()) {
/// TODO: Update when score logic is overhauled
}
}
super.initState();
}
@@ -50,6 +74,7 @@ class _MatchResultViewState extends State<MatchResultView> {
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context);
return Scaffold(
backgroundColor: CustomTheme.backgroundColor,
appBar: AppBar(
@@ -85,50 +110,77 @@ class _MatchResultViewState extends State<MatchResultView> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
loc.select_winner,
'${getTitleForRuleset(loc)}:',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
Expanded(
child: RadioGroup<Player>(
groupValue: _selectedPlayer,
onChanged: (Player? value) async {
setState(() {
_selectedPlayer = value;
});
await _handleWinnerSaving();
},
child: ListView.builder(
if (rulesetSupportsWinnerSelection())
Expanded(
child: RadioGroup<Player>(
groupValue: _selectedPlayer,
onChanged: (Player? value) async {
setState(() {
_selectedPlayer = value;
});
},
child: ListView.builder(
itemCount: allPlayers.length,
itemBuilder: (context, index) {
return CustomRadioListTile(
text: allPlayers[index].name,
value: allPlayers[index],
onContainerTap: (value) async {
setState(() {
// Check if the already selected player is the same as the newly tapped player.
if (_selectedPlayer == value) {
// If yes deselected the player by setting it to null.
_selectedPlayer = null;
} else {
// If no assign the newly tapped player to the selected player.
(_selectedPlayer = value);
}
});
},
);
},
),
),
),
if (rulesetSupportsScoreEntry())
Expanded(
child: ListView.separated(
itemCount: allPlayers.length,
itemBuilder: (context, index) {
return CustomRadioListTile(
print(allPlayers[index].name);
return ScoreListTile(
text: allPlayers[index].name,
value: allPlayers[index],
onContainerTap: (value) async {
setState(() {
// Check if the already selected player is the same as the newly tapped player.
if (_selectedPlayer == value) {
// If yes deselected the player by setting it to null.
_selectedPlayer = null;
} else {
// If no assign the newly tapped player to the selected player.
(_selectedPlayer = value);
}
});
await _handleWinnerSaving();
},
controller: controller[index],
);
},
separatorBuilder: (BuildContext context, int index) {
return const Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Divider(indent: 20),
);
},
),
),
),
],
),
),
),
CustomWidthButton(
text: loc.save_changes,
sizeRelativeToWidth: 0.95,
onPressed: () async {
await _handleSaving();
if (!context.mounted) return;
Navigator.of(context).pop(_selectedPlayer);
},
),
],
),
),
@@ -137,7 +189,20 @@ class _MatchResultViewState extends State<MatchResultView> {
/// Handles saving or removing the winner in the database
/// based on the current selection.
Future<void> _handleWinnerSaving() async {
Future<void> _handleSaving() async {
if (widget.ruleset == Ruleset.singleWinner) {
await _handleWinner();
} else if (widget.ruleset == Ruleset.singleLoser) {
await _handleLoser();
} else if (widget.ruleset == Ruleset.lowestScore ||
widget.ruleset == Ruleset.highestScore) {
await _handleScores();
}
widget.onWinnerChanged?.call();
}
Future<bool> _handleWinner() async {
if (_selectedPlayer == null) {
await db.scoreEntryDao.removeWinner(matchId: widget.match.id);
} else {
@@ -146,6 +211,53 @@ class _MatchResultViewState extends State<MatchResultView> {
playerId: _selectedPlayer!.id,
);
}
widget.onWinnerChanged?.call();
}
Future<bool> _handleLoser() async {
if (_selectedPlayer == null) {
/// TODO: Update when score logic is overhauled
return false;
} else {
/// TODO: Update when score logic is overhauled
return false;
}
}
/// Handles saving the scores for each player in the database.
Future<bool> _handleScores() async {
for (int i = 0; i < allPlayers.length; i++) {
var text = controller[i].text;
if (text.isEmpty) {
text = '0';
}
final score = int.parse(text);
await db.playerMatchDao.updatePlayerScore(
matchId: widget.match.id,
playerId: allPlayers[i].id,
newScore: score,
);
}
return false;
}
String getTitleForRuleset(AppLocalizations loc) {
switch (widget.ruleset) {
case Ruleset.singleWinner:
return loc.select_winner;
case Ruleset.singleLoser:
return loc.select_loser;
default:
return loc.enter_points;
}
}
bool rulesetSupportsWinnerSelection() {
return widget.ruleset == Ruleset.singleWinner ||
widget.ruleset == Ruleset.singleLoser;
}
bool rulesetSupportsScoreEntry() {
return widget.ruleset == Ruleset.lowestScore ||
widget.ruleset == Ruleset.highestScore;
}
}

View File

@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:tallee/core/common.dart';
import 'package:tallee/core/constants.dart';
import 'package:tallee/core/custom_theme.dart';
import 'package:tallee/data/db/database.dart';
@@ -141,7 +140,6 @@ class _PlayerSelectionState extends State<PlayerSelection> {
padding: const EdgeInsets.only(right: 8.0),
child: TextIconTile(
text: player.name,
suffixText: getNameCountText(player),
onIconTap: () {
setState(() {
// Removes the player from the selection and notifies the parent.
@@ -195,7 +193,6 @@ class _PlayerSelectionState extends State<PlayerSelection> {
itemBuilder: (BuildContext context, int index) {
return TextIconListTile(
text: suggestedPlayers[index].name,
suffixText: getNameCountText(suggestedPlayers[index]),
onPressed: () {
setState(() {
// If the player is not already selected
@@ -285,8 +282,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
final loc = AppLocalizations.of(context);
final playerName = _searchBarController.text.trim();
int nameCount = _calculateNameCount(playerName);
final createdPlayer = Player(name: playerName, nameCount: nameCount);
final createdPlayer = Player(name: playerName, description: '');
final success = await db.playerDao.addPlayer(player: createdPlayer);
if (!context.mounted) return;
@@ -299,22 +295,6 @@ class _PlayerSelectionState extends State<PlayerSelection> {
}
}
int _calculateNameCount(String playerName) {
final playersWithSameName =
allPlayers.where((player) => player.name == playerName).toList()
..sort((a, b) => a.nameCount.compareTo(b.nameCount));
if (playersWithSameName.isEmpty) {
return 0;
} else if (playersWithSameName.length == 1) {
// Initialize nameCount
playersWithSameName[0].nameCount = 1;
}
// Return following count
return playersWithSameName.length + 1;
}
/// Updates the state after successfully adding a new player.
void _handleSuccessfulPlayerCreation(Player player) {
selectedPlayers.insert(0, player);

View File

@@ -1,5 +1,4 @@
import 'package:flutter/material.dart';
import 'package:tallee/core/common.dart';
import 'package:tallee/core/custom_theme.dart';
import 'package:tallee/data/models/group.dart';
import 'package:tallee/presentation/widgets/tiles/text_icon_tile.dart';
@@ -82,11 +81,7 @@ class _GroupTileState extends State<GroupTile> {
for (var member in [
...widget.group.members,
]..sort((a, b) => a.name.compareTo(b.name)))
TextIconTile(
text: member.name,
suffixText: getNameCountText(member),
iconEnabled: false,
),
TextIconTile(text: member.name, iconEnabled: false),
],
),
const SizedBox(height: 2.5),

View File

@@ -79,6 +79,24 @@ class _MatchTileState extends State<MatchTile> {
],
),
const SizedBox(height: 4),
Container(
decoration: BoxDecoration(
color: CustomTheme.primaryColor,
borderRadius: BorderRadius.circular(8),
),
padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8),
child: Text(
translateRulesetToString(match.game.ruleset, context),
style: const TextStyle(
fontSize: 12,
color: Colors.white,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(height: 8),
if (group != null) ...[
@@ -203,11 +221,7 @@ class _MatchTileState extends State<MatchTile> {
spacing: 6,
runSpacing: 6,
children: players.map((player) {
return TextIconTile(
text: player.name,
suffixText: getNameCountText(player),
iconEnabled: false,
);
return TextIconTile(text: player.name, iconEnabled: false);
}).toList(),
),
],

View File

@@ -0,0 +1,91 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:tallee/core/custom_theme.dart';
import 'package:tallee/l10n/generated/app_localizations.dart';
class ScoreListTile extends StatelessWidget {
/// A custom list tile widget that has a text field for inputting a score.
/// - [text]: The leading text to be displayed.
/// - [controller]: The controller for the text field to input the score.
const ScoreListTile({
super.key,
required this.text,
required this.controller,
/*
required this.onContainerTap,
*/
});
/// The text to display next to the radio button.
final String text;
final TextEditingController controller;
/// The callback invoked when the container is tapped.
/*
final ValueChanged<T> onContainerTap;
*/
@override
Widget build(BuildContext context) {
final loc = AppLocalizations.of(context);
return Container(
margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
padding: const EdgeInsets.symmetric(horizontal: 20),
decoration: const BoxDecoration(color: CustomTheme.boxColor),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
text,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 17, fontWeight: FontWeight.w500),
),
SizedBox(
width: 100,
height: 40,
child: TextField(
controller: controller,
keyboardType: TextInputType.number,
maxLength: 4,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: CustomTheme.textColor,
),
cursorColor: CustomTheme.textColor,
decoration: InputDecoration(
hintText: loc.points,
counterText: '',
filled: true,
fillColor: CustomTheme.onBoxColor,
contentPadding: const EdgeInsets.symmetric(
horizontal: 0,
vertical: 0,
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(
color: CustomTheme.textColor.withAlpha(100),
width: 2,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: const BorderSide(
color: CustomTheme.primaryColor,
width: 2,
),
),
),
),
),
],
),
);
}
}

View File

@@ -9,7 +9,6 @@ class TextIconListTile extends StatelessWidget {
const TextIconListTile({
super.key,
required this.text,
this.suffixText = '',
this.iconEnabled = true,
this.onPressed,
});
@@ -17,9 +16,6 @@ class TextIconListTile extends StatelessWidget {
/// The text to display in the tile.
final String text;
/// An optional suffix text to display after the main text.
final String suffixText;
/// A boolean to determine if the icon should be displayed.
final bool iconEnabled;
@@ -39,27 +35,12 @@ class TextIconListTile extends StatelessWidget {
Flexible(
child: Container(
padding: const EdgeInsets.symmetric(vertical: 12.5),
child: RichText(
child: Text(
text,
overflow: TextOverflow.ellipsis,
text: TextSpan(
style: DefaultTextStyle.of(context).style,
children: [
TextSpan(
text: text,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
TextSpan(
text: suffixText,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: CustomTheme.textColor.withAlpha(100),
),
),
],
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),

View File

@@ -9,7 +9,6 @@ class TextIconTile extends StatelessWidget {
const TextIconTile({
super.key,
required this.text,
this.suffixText = '',
this.iconEnabled = true,
this.onIconTap,
});
@@ -17,8 +16,6 @@ class TextIconTile extends StatelessWidget {
/// The text to display in the tile.
final String text;
final String suffixText;
/// A boolean to determine if the icon should be displayed.
final bool iconEnabled;
@@ -39,28 +36,10 @@ class TextIconTile extends StatelessWidget {
children: [
if (iconEnabled) const SizedBox(width: 3),
Flexible(
child: RichText(
child: Text(
text,
overflow: TextOverflow.ellipsis,
text: TextSpan(
style: DefaultTextStyle.of(context).style,
children: [
TextSpan(
text: text,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
TextSpan(
text: suffixText,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w500,
color: CustomTheme.textColor.withAlpha(120),
),
),
],
),
style: const TextStyle(fontSize: 14, fontWeight: FontWeight.w500),
),
),
if (iconEnabled) ...<Widget>[

View File

@@ -1,5 +1,5 @@
import 'package:clock/clock.dart';
import 'package:drift/drift.dart' hide isNull, isNotNull;
import 'package:drift/drift.dart' hide isNull;
import 'package:drift/native.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tallee/data/db/database.dart';
@@ -381,160 +381,5 @@ void main() {
);
expect(playerExists, true);
});
group('Name Count Tests', () {
test('Single player gets initialized wih name count 0', () async {
await database.playerDao.addPlayer(player: testPlayer1);
final player = await database.playerDao.getPlayerById(
playerId: testPlayer1.id,
);
expect(player.nameCount, 0);
});
test('Multiple players get initialized wih name count 0', () async {
await database.playerDao.addPlayersAsList(
players: [testPlayer1, testPlayer2],
);
final players = await database.playerDao.getAllPlayers();
expect(players.length, 2);
for (Player p in players) {
expect(p.nameCount, 0);
}
});
test(
'Seperatly added players nameCount gets increased correctly',
() async {
await database.playerDao.addPlayer(player: testPlayer1);
final player1 = Player(name: testPlayer1.name, description: '');
await database.playerDao.addPlayer(player: player1);
var players = await database.playerDao.getAllPlayers();
expect(players.length, 2);
players.sort((a, b) => a.nameCount.compareTo(b.nameCount));
for (int i = 0; i < players.length - 1; i++) {
expect(players[i].nameCount, i + 1);
}
},
);
test(
'Together added players nameCount gets increased correctly',
() async {
final player1 = Player(name: testPlayer1.name, description: '');
final player2 = Player(name: testPlayer1.name, description: '');
final player3 = Player(name: testPlayer1.name, description: '');
// addPlayersAsList() with multiple players and with one player
await database.playerDao.addPlayersAsList(players: [testPlayer1]);
await database.playerDao.addPlayersAsList(
players: [player1, player2, player3],
);
var players = await database.playerDao.getAllPlayers();
expect(players.length, 4);
players.sort((a, b) => a.nameCount.compareTo(b.nameCount));
for (int i = 0; i < players.length - 1; i++) {
expect(players[i].nameCount, i + 1);
}
},
);
test('getNameCount works correctly', () async {
final player2 = Player(name: testPlayer1.name);
final player3 = Player(name: testPlayer1.name);
await database.playerDao.addPlayersAsList(
players: [testPlayer1, player2, player3],
);
final nameCount = await database.playerDao.getNameCount(
name: testPlayer1.name,
);
expect(nameCount, 3);
});
test('updateNameCount works correctly', () async {
await database.playerDao.addPlayer(player: testPlayer1);
final success = await database.playerDao.updateNameCount(
playerId: testPlayer1.id,
nameCount: 2,
);
expect(success, true);
final player = await database.playerDao.getPlayerById(
playerId: testPlayer1.id,
);
expect(player.nameCount, 2);
});
test('getPlayerWithHighestNameCount works correctly', () async {
final player2 = Player(name: testPlayer1.name, description: '');
final player3 = Player(name: testPlayer1.name, description: '');
await database.playerDao.addPlayersAsList(
players: [testPlayer1, player2, player3],
);
final player = await database.playerDao.getPlayerWithHighestNameCount(
name: testPlayer1.name,
);
expect(player, isNotNull);
expect(player!.nameCount, 3);
});
test('getPlayerWithHighestNameCount with non existing player', () async {
final player = await database.playerDao.getPlayerWithHighestNameCount(
name: 'non-existing-name',
);
expect(player, isNull);
});
test('calculateNameCount works correctly', () async {
// Case 1: No existing players with the name
var count = await database.playerDao.calculateNameCount(
name: testPlayer1.name,
);
expect(count, 0);
// Case 2: One existing player with the name. Should update that
// player's nameCount to 1 and return 2 for the new player
await database.playerDao.addPlayer(player: testPlayer1);
count = await database.playerDao.calculateNameCount(
name: testPlayer1.name,
);
expect(count, 2);
// Case 3: Multiple existing players with the name.
final player2 = Player(name: testPlayer1.name, nameCount: count);
await database.playerDao.addPlayer(player: player2);
count = await database.playerDao.calculateNameCount(
name: testPlayer1.name,
);
expect(count, 3);
});
test('getPlayerWithHighestNameCount with non existing player', () async {
await database.playerDao.addPlayer(player: testPlayer1);
await database.playerDao.initializeNameCount(name: testPlayer1.name);
final player = await database.playerDao.getPlayerById(
playerId: testPlayer1.id,
);
expect(player.nameCount, 1);
});
});
});
}