6 Commits

Author SHA1 Message Date
9c4eff5056 Moved button
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 46s
Pull Request Pipeline / lint (pull_request) Successful in 48s
2026-04-19 16:02:14 +02:00
ad2e4bc398 Added constraint parameter 2026-04-19 15:56:11 +02:00
2ad3698067 Updated documentation 2026-04-19 15:25:22 +02:00
32e1c587d4 Updated popups in views 2026-04-19 15:19:38 +02:00
55437d83c4 Changed popup class structure 2026-04-19 15:19:30 +02:00
15702a108d Add: custom dialog action 2026-04-19 15:18:27 +02:00
17 changed files with 216 additions and 624 deletions

View File

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

View File

@@ -1,5 +1,4 @@
import 'package:drift/drift.dart'; import 'package:drift/drift.dart';
import 'package:flutter/cupertino.dart';
import 'package:tallee/data/db/database.dart'; import 'package:tallee/data/db/database.dart';
import 'package:tallee/data/db/tables/player_table.dart'; import 'package:tallee/data/db/tables/player_table.dart';
import 'package:tallee/data/models/player.dart'; import 'package:tallee/data/models/player.dart';
@@ -21,7 +20,6 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
name: row.name, name: row.name,
description: row.description, description: row.description,
createdAt: row.createdAt, createdAt: row.createdAt,
nameCount: row.nameCount,
), ),
) )
.toList(); .toList();
@@ -36,7 +34,6 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
name: result.name, name: result.name,
description: result.description, description: result.description,
createdAt: result.createdAt, createdAt: result.createdAt,
nameCount: result.nameCount,
); );
} }
@@ -45,15 +42,12 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
/// the new one. /// the new one.
Future<bool> addPlayer({required Player player}) async { Future<bool> addPlayer({required Player player}) async {
if (!await playerExists(playerId: player.id)) { if (!await playerExists(playerId: player.id)) {
final int nameCount = await calculateNameCount(name: player.name);
await into(playerTable).insert( await into(playerTable).insert(
PlayerTableCompanion.insert( PlayerTableCompanion.insert(
id: player.id, id: player.id,
name: player.name, name: player.name,
description: player.description, description: player.description,
createdAt: player.createdAt, createdAt: player.createdAt,
nameCount: Value(nameCount),
), ),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrReplace,
); );
@@ -68,67 +62,20 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
Future<bool> addPlayersAsList({required List<Player> players}) async { Future<bool> addPlayersAsList({required List<Player> players}) async {
if (players.isEmpty) return false; if (players.isEmpty) return false;
// 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( await db.batch(
(b) => b.insertAll( (b) => b.insertAll(
playerTable, playerTable,
playersToInsert, players
mode: InsertMode.insertOrReplace, .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; 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. /// Returns `true` if the player exists, `false` otherwise.
Future<bool> playerExists({required String playerId}) async { Future<bool> playerExists({required String playerId}) async {
final query = select(playerTable)..where((p) => p.id.equals(playerId)); 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 playerId,
required String newName, required String newName,
}) async { }) 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( await (update(playerTable)..where((p) => p.id.equals(playerId))).write(
PlayerTableCompanion(name: Value(newName)), 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. /// Retrieves the total count of players in the database.
@@ -199,76 +117,6 @@ class PlayerDao extends DatabaseAccessor<AppDatabase> with _$PlayerDaoMixin {
return count ?? 0; 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. /// Deletes all players from the database.
/// Returns `true` if more than 0 rows were affected, otherwise `false`. /// Returns `true` if more than 0 rows were affected, otherwise `false`.
Future<bool> deleteAllPlayers() async { Future<bool> deleteAllPlayers() async {

View File

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

View File

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

View File

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

View File

@@ -2,8 +2,8 @@ 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/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/db/database.dart'; import 'package:tallee/data/db/database.dart';
import 'package:tallee/data/models/group.dart'; import 'package:tallee/data/models/group.dart';
import 'package:tallee/data/models/match.dart'; import 'package:tallee/data/models/match.dart';
@@ -11,10 +11,10 @@ import 'package:tallee/data/models/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/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/main_menu_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/colored_icon_container.dart';
import 'package:tallee/presentation/widgets/custom_alert_dialog.dart'; import 'package:tallee/presentation/widgets/dialog/custom_alert_dialog.dart';
import 'package:tallee/presentation/widgets/dialog/custom_dialog_action.dart';
import 'package:tallee/presentation/widgets/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';
@@ -71,23 +71,16 @@ class _GroupDetailViewState extends State<GroupDetailView> {
context: context, context: context,
builder: (context) => CustomAlertDialog( builder: (context) => CustomAlertDialog(
title: '${loc.delete_group}?', title: '${loc.delete_group}?',
content: loc.this_cannot_be_undone, content: Text(loc.this_cannot_be_undone),
actions: [ actions: [
AnimatedDialogButton( CustomDialogAction(
onPressed: () => Navigator.of(context).pop(false),
child: Text(
loc.cancel,
style: const TextStyle(color: CustomTheme.textColor),
),
),
AnimatedDialogButton(
onPressed: () => Navigator.of(context).pop(true), onPressed: () => Navigator.of(context).pop(true),
child: Text( text: loc.delete,
loc.delete,
style: const TextStyle(
color: CustomTheme.secondaryColor,
),
), ),
CustomDialogAction(
onPressed: () => Navigator.of(context).pop(false),
buttonType: ButtonType.secondary,
text: loc.cancel,
), ),
], ],
), ),
@@ -154,7 +147,6 @@ class _GroupDetailViewState extends State<GroupDetailView> {
children: _group.members.map((member) { children: _group.members.map((member) {
return TextIconTile( return TextIconTile(
text: member.name, text: member.name,
suffixText: getNameCountText(member),
iconEnabled: false, iconEnabled: false,
); );
}).toList(), }).toList(),

View File

@@ -4,15 +4,16 @@ import 'package:provider/provider.dart';
import 'package:tallee/core/adaptive_page_route.dart'; import 'package:tallee/core/adaptive_page_route.dart';
import 'package:tallee/core/common.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/db/database.dart'; import 'package:tallee/data/db/database.dart';
import 'package:tallee/data/models/match.dart'; import 'package:tallee/data/models/match.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_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/buttons/main_menu_button.dart';
import 'package:tallee/presentation/widgets/colored_icon_container.dart'; import 'package:tallee/presentation/widgets/colored_icon_container.dart';
import 'package:tallee/presentation/widgets/custom_alert_dialog.dart'; import 'package:tallee/presentation/widgets/dialog/custom_alert_dialog.dart';
import 'package:tallee/presentation/widgets/dialog/custom_dialog_action.dart';
import 'package:tallee/presentation/widgets/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';
@@ -64,23 +65,16 @@ class _MatchDetailViewState extends State<MatchDetailView> {
context: context, context: context,
builder: (context) => CustomAlertDialog( builder: (context) => CustomAlertDialog(
title: '${loc.delete_match}?', title: '${loc.delete_match}?',
content: loc.this_cannot_be_undone, content: Text(loc.this_cannot_be_undone),
actions: [ actions: [
AnimatedDialogButton( CustomDialogAction(
onPressed: () => Navigator.of(context).pop(false),
child: Text(
loc.cancel,
style: const TextStyle(color: CustomTheme.textColor),
),
),
AnimatedDialogButton(
onPressed: () => Navigator.of(context).pop(true), onPressed: () => Navigator.of(context).pop(true),
child: Text( text: loc.delete,
loc.delete,
style: const TextStyle(
color: CustomTheme.secondaryColor,
),
), ),
CustomDialogAction(
onPressed: () => Navigator.of(context).pop(false),
buttonType: ButtonType.secondary,
text: loc.cancel,
), ),
], ],
), ),
@@ -161,7 +155,6 @@ class _MatchDetailViewState extends State<MatchDetailView> {
children: match.players.map((player) { children: match.players.map((player) {
return TextIconTile( return TextIconTile(
text: player.name, text: player.name,
suffixText: getNameCountText(player),
iconEnabled: false, iconEnabled: false,
); );
}).toList(), }).toList(),

View File

@@ -9,8 +9,8 @@ import 'package:tallee/core/custom_theme.dart';
import 'package:tallee/core/enums.dart'; import 'package:tallee/core/enums.dart';
import 'package:tallee/l10n/generated/app_localizations.dart'; import 'package:tallee/l10n/generated/app_localizations.dart';
import 'package:tallee/presentation/views/main_menu/settings_view/licenses_view.dart'; import 'package:tallee/presentation/views/main_menu/settings_view/licenses_view.dart';
import 'package:tallee/presentation/widgets/buttons/animated_dialog_button.dart'; import 'package:tallee/presentation/widgets/dialog/custom_alert_dialog.dart';
import 'package:tallee/presentation/widgets/custom_alert_dialog.dart'; import 'package:tallee/presentation/widgets/dialog/custom_dialog_action.dart';
import 'package:tallee/presentation/widgets/tiles/settings_list_tile.dart'; import 'package:tallee/presentation/widgets/tiles/settings_list_tile.dart';
import 'package:tallee/services/data_transfer_service.dart'; import 'package:tallee/services/data_transfer_service.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
@@ -122,25 +122,16 @@ class _SettingsViewState extends State<SettingsView> {
context: context, context: context,
builder: (context) => CustomAlertDialog( builder: (context) => CustomAlertDialog(
title: '${loc.delete_all_data}?', title: '${loc.delete_all_data}?',
content: loc.this_cannot_be_undone, content: Text(loc.this_cannot_be_undone),
actions: [ actions: [
AnimatedDialogButton( CustomDialogAction(
onPressed: () => Navigator.of(context).pop(false),
child: Text(
loc.cancel,
style: const TextStyle(
color: CustomTheme.textColor,
),
),
),
AnimatedDialogButton(
onPressed: () => Navigator.of(context).pop(true), onPressed: () => Navigator.of(context).pop(true),
child: Text( text: loc.delete,
loc.delete,
style: const TextStyle(
color: CustomTheme.secondaryColor,
),
), ),
CustomDialogAction(
onPressed: () => Navigator.of(context).pop(false),
buttonType: ButtonType.secondary,
text: loc.cancel,
), ),
], ],
), ),

View File

@@ -1,22 +1,28 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:tallee/core/custom_theme.dart'; import 'package:tallee/core/enums.dart';
class AnimatedDialogButton extends StatefulWidget { class AnimatedDialogButton extends StatefulWidget {
/// A custom animated button widget that provides a scaling and opacity effect /// A custom animated button widget that provides a scaling and opacity effect
/// when pressed. /// when pressed.
/// - [onPressed]: Callback function that is triggered when the button is pressed. /// - [onPressed]: Callback function that is triggered when the button is pressed.
/// - [child]: The child widget to be displayed inside the button, typically a text or icon. /// - [buttonText]: The text to be displayed on the button.
/// - [buttonType]: The type of the button, which determines its styling.
/// - [buttonConstraints]: Optional constraints to control the button's size.
const AnimatedDialogButton({ const AnimatedDialogButton({
super.key, super.key,
required this.buttonText,
required this.onPressed, required this.onPressed,
required this.child, this.buttonConstraints,
this.buttonType = ButtonType.primary,
}); });
/// Callback function that is triggered when the button is pressed. final String buttonText;
final VoidCallback onPressed; final VoidCallback onPressed;
/// The child widget to be displayed inside the button, typically a text or icon. final BoxConstraints? buttonConstraints;
final Widget child;
final ButtonType buttonType;
@override @override
State<AnimatedDialogButton> createState() => _AnimatedDialogButtonState(); State<AnimatedDialogButton> createState() => _AnimatedDialogButtonState();
@@ -27,6 +33,29 @@ class _AnimatedDialogButtonState extends State<AnimatedDialogButton> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final textStyling = TextStyle(
color: widget.buttonType == ButtonType.primary
? Colors.black
: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
);
final buttonDecoration = widget.buttonType == ButtonType.primary
// Primary
? BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
)
: widget.buttonType == ButtonType.secondary
// Secondary
? BoxDecoration(
border: BoxBorder.all(color: Colors.white, width: 2),
borderRadius: BorderRadius.circular(12),
)
// Tertiary
: const BoxDecoration();
return GestureDetector( return GestureDetector(
onTapDown: (_) => setState(() => _isPressed = true), onTapDown: (_) => setState(() => _isPressed = true),
onTapUp: (_) => setState(() => _isPressed = false), onTapUp: (_) => setState(() => _isPressed = false),
@@ -38,10 +67,18 @@ class _AnimatedDialogButtonState extends State<AnimatedDialogButton> {
child: AnimatedOpacity( child: AnimatedOpacity(
opacity: _isPressed ? 0.6 : 1.0, opacity: _isPressed ? 0.6 : 1.0,
duration: const Duration(milliseconds: 100), duration: const Duration(milliseconds: 100),
child: Center(
child: Container( child: Container(
decoration: CustomTheme.standardBoxDecoration, constraints: widget.buttonConstraints,
padding: const EdgeInsets.symmetric(horizontal: 26, vertical: 6), decoration: buttonDecoration,
child: widget.child, padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
margin: const EdgeInsets.symmetric(vertical: 8),
child: Text(
widget.buttonText,
style: textStyling,
textAlign: TextAlign.center,
),
),
), ),
), ),
), ),

View File

@@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:tallee/core/custom_theme.dart'; import 'package:tallee/core/custom_theme.dart';
import 'package:tallee/presentation/widgets/dialog/custom_dialog_action.dart';
class CustomAlertDialog extends StatelessWidget { class CustomAlertDialog extends StatelessWidget {
/// A custom alert dialog widget that provides a os unspecific AlertDialog, /// A custom alert dialog widget that provides a os unspecific AlertDialog,
@@ -16,20 +17,23 @@ class CustomAlertDialog extends StatelessWidget {
}); });
final String title; final String title;
final String content; final Widget content;
final List<Widget> actions; final List<CustomDialogAction> actions;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AlertDialog( return AlertDialog(
title: Text(title, style: const TextStyle(color: CustomTheme.textColor)), title: Text(
content: Text( title,
content, style: const TextStyle(
style: const TextStyle(color: CustomTheme.textColor), fontWeight: FontWeight.bold,
color: CustomTheme.textColor,
), ),
),
content: content,
actions: actions, actions: actions,
backgroundColor: CustomTheme.boxColor, backgroundColor: CustomTheme.boxColor,
actionsAlignment: MainAxisAlignment.spaceAround, actionsAlignment: MainAxisAlignment.center,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: CustomTheme.standardBorderRadiusAll, borderRadius: CustomTheme.standardBorderRadiusAll,
side: const BorderSide(color: CustomTheme.boxBorderColor), side: const BorderSide(color: CustomTheme.boxBorderColor),

View File

@@ -0,0 +1,32 @@
import 'package:flutter/cupertino.dart';
import 'package:tallee/core/enums.dart';
import 'package:tallee/presentation/widgets/buttons/animated_dialog_button.dart';
class CustomDialogAction extends StatelessWidget {
/// A custom dialog action widget that represents a button in a dialog.
/// - [text]: The text to be displayed on the button.
/// - [buttonType]: The type of the button, which determines its styling.
/// - [onPressed]: Callback function that is triggered when the button is pressed.
const CustomDialogAction({
super.key,
required this.onPressed,
required this.text,
this.buttonType = ButtonType.primary,
});
final String text;
final ButtonType buttonType;
final VoidCallback onPressed;
@override
Widget build(BuildContext context) {
return AnimatedDialogButton(
onPressed: onPressed,
buttonText: text,
buttonType: buttonType,
buttonConstraints: const BoxConstraints(minWidth: 300),
);
}
}

View File

@@ -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/common.dart';
import 'package:tallee/core/constants.dart'; import 'package:tallee/core/constants.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';
@@ -141,7 +140,6 @@ class _PlayerSelectionState extends State<PlayerSelection> {
padding: const EdgeInsets.only(right: 8.0), padding: const EdgeInsets.only(right: 8.0),
child: TextIconTile( child: TextIconTile(
text: player.name, text: player.name,
suffixText: getNameCountText(player),
onIconTap: () { onIconTap: () {
setState(() { setState(() {
// Removes the player from the selection and notifies the parent. // Removes the player from the selection and notifies the parent.
@@ -195,7 +193,6 @@ class _PlayerSelectionState extends State<PlayerSelection> {
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return TextIconListTile( return TextIconListTile(
text: suggestedPlayers[index].name, text: suggestedPlayers[index].name,
suffixText: getNameCountText(suggestedPlayers[index]),
onPressed: () { onPressed: () {
setState(() { setState(() {
// If the player is not already selected // If the player is not already selected
@@ -285,8 +282,7 @@ class _PlayerSelectionState extends State<PlayerSelection> {
final loc = AppLocalizations.of(context); final loc = AppLocalizations.of(context);
final playerName = _searchBarController.text.trim(); final playerName = _searchBarController.text.trim();
int nameCount = _calculateNameCount(playerName); final createdPlayer = Player(name: playerName, description: '');
final createdPlayer = Player(name: playerName, nameCount: nameCount);
final success = await db.playerDao.addPlayer(player: createdPlayer); final success = await db.playerDao.addPlayer(player: createdPlayer);
if (!context.mounted) return; 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. /// Updates the state after successfully adding a new player.
void _handleSuccessfulPlayerCreation(Player player) { void _handleSuccessfulPlayerCreation(Player player) {
selectedPlayers.insert(0, player); selectedPlayers.insert(0, player);

View File

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

View File

@@ -203,11 +203,7 @@ class _MatchTileState extends State<MatchTile> {
spacing: 6, spacing: 6,
runSpacing: 6, runSpacing: 6,
children: players.map((player) { children: players.map((player) {
return TextIconTile( return TextIconTile(text: player.name, iconEnabled: false);
text: player.name,
suffixText: getNameCountText(player),
iconEnabled: false,
);
}).toList(), }).toList(),
), ),
], ],

View File

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

View File

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

View File

@@ -1,5 +1,5 @@
import 'package:clock/clock.dart'; 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:drift/native.dart';
import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_test/flutter_test.dart';
import 'package:tallee/data/db/database.dart'; import 'package:tallee/data/db/database.dart';
@@ -381,160 +381,5 @@ void main() {
); );
expect(playerExists, true); 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);
});
});
}); });
} }