feat: displayCount

This commit is contained in:
2026-05-24 23:09:08 +02:00
parent f65ea09cbe
commit 428f967010
7 changed files with 98 additions and 18 deletions

View File

@@ -20,6 +20,7 @@ class StatisticDao extends DatabaseAccessor<AppDatabase>
id: statistic.id, id: statistic.id,
type: statistic.type.name, type: statistic.type.name,
timeframe: Value(statistic.timeframe?.name), timeframe: Value(statistic.timeframe?.name),
displayCount: Value(statistic.displayCount),
), ),
mode: InsertMode.insertOrReplace, mode: InsertMode.insertOrReplace,
); );
@@ -59,12 +60,13 @@ class StatisticDao extends DatabaseAccessor<AppDatabase>
return Statistic( return Statistic(
type: StatisticType.values.firstWhere((type) => type.name == row.type), type: StatisticType.values.firstWhere((type) => type.name == row.type),
scopes: scopes, scopes: scopes,
id: row.id,
timeframe: Timeframe.values.firstWhereOrNull( timeframe: Timeframe.values.firstWhereOrNull(
(t) => t.name == row.timeframe, (t) => t.name == row.timeframe,
), ),
selectedGroups: groups, selectedGroups: groups,
selectedGames: games, selectedGames: games,
displayCount: row.displayCount,
id: row.id,
); );
} }
return null; return null;
@@ -73,9 +75,9 @@ class StatisticDao extends DatabaseAccessor<AppDatabase>
/// Retrieves all statistics from the database, including their associated groups and games. /// Retrieves all statistics from the database, including their associated groups and games.
Future<List<Statistic>> getAllStatistics() async { Future<List<Statistic>> getAllStatistics() async {
final query = select(statisticTable); final query = select(statisticTable);
final rows = await query.get(); final result = await query.get();
return Future.wait( return Future.wait(
rows.map((row) async { result.map((row) async {
final groups = await db.statisticGroupDao.getGroupsForStatistic(row.id); final groups = await db.statisticGroupDao.getGroupsForStatistic(row.id);
final games = await db.statisticGameDao.getGamesForStatistic(row.id); final games = await db.statisticGameDao.getGamesForStatistic(row.id);
@@ -84,17 +86,29 @@ class StatisticDao extends DatabaseAccessor<AppDatabase>
(type) => type.name == row.type, (type) => type.name == row.type,
), ),
scopes: [], scopes: [],
id: row.id,
timeframe: Timeframe.values.firstWhereOrNull( timeframe: Timeframe.values.firstWhereOrNull(
(t) => t.name == row.timeframe, (t) => t.name == row.timeframe,
), ),
selectedGroups: groups, selectedGroups: groups,
selectedGames: games, selectedGames: games,
displayCount: row.displayCount,
id: row.id,
); );
}), }),
); );
} }
/* Update */
Future<bool> updateDisplayCount(String statisticId, int displayCount) async {
final rowsUpdated =
await (update(statisticTable)
..where((tbl) => tbl.id.equals(statisticId)))
.write(StatisticTableCompanion(displayCount: Value(displayCount)));
return rowsUpdated > 0;
}
/* Delete */ /* Delete */
Future<bool> deleteStatistic(String statisticId) async { Future<bool> deleteStatistic(String statisticId) async {

View File

@@ -2767,8 +2767,20 @@ class $StatisticTableTable extends StatisticTable
type: DriftSqlType.string, type: DriftSqlType.string,
requiredDuringInsert: false, requiredDuringInsert: false,
); );
static const VerificationMeta _displayCountMeta = const VerificationMeta(
'displayCount',
);
@override @override
List<GeneratedColumn> get $columns => [id, type, timeframe]; late final GeneratedColumn<int> displayCount = GeneratedColumn<int>(
'display_count',
aliasedName,
false,
type: DriftSqlType.int,
requiredDuringInsert: false,
defaultValue: const Constant(5),
);
@override
List<GeneratedColumn> get $columns => [id, type, timeframe, displayCount];
@override @override
String get aliasedName => _alias ?? actualTableName; String get aliasedName => _alias ?? actualTableName;
@override @override
@@ -2800,6 +2812,15 @@ class $StatisticTableTable extends StatisticTable
timeframe.isAcceptableOrUnknown(data['timeframe']!, _timeframeMeta), timeframe.isAcceptableOrUnknown(data['timeframe']!, _timeframeMeta),
); );
} }
if (data.containsKey('display_count')) {
context.handle(
_displayCountMeta,
displayCount.isAcceptableOrUnknown(
data['display_count']!,
_displayCountMeta,
),
);
}
return context; return context;
} }
@@ -2821,6 +2842,10 @@ class $StatisticTableTable extends StatisticTable
DriftSqlType.string, DriftSqlType.string,
data['${effectivePrefix}timeframe'], data['${effectivePrefix}timeframe'],
), ),
displayCount: attachedDatabase.typeMapping.read(
DriftSqlType.int,
data['${effectivePrefix}display_count'],
)!,
); );
} }
@@ -2835,10 +2860,12 @@ class StatisticTableData extends DataClass
final String id; final String id;
final String type; final String type;
final String? timeframe; final String? timeframe;
final int displayCount;
const StatisticTableData({ const StatisticTableData({
required this.id, required this.id,
required this.type, required this.type,
this.timeframe, this.timeframe,
required this.displayCount,
}); });
@override @override
Map<String, Expression> toColumns(bool nullToAbsent) { Map<String, Expression> toColumns(bool nullToAbsent) {
@@ -2848,6 +2875,7 @@ class StatisticTableData extends DataClass
if (!nullToAbsent || timeframe != null) { if (!nullToAbsent || timeframe != null) {
map['timeframe'] = Variable<String>(timeframe); map['timeframe'] = Variable<String>(timeframe);
} }
map['display_count'] = Variable<int>(displayCount);
return map; return map;
} }
@@ -2858,6 +2886,7 @@ class StatisticTableData extends DataClass
timeframe: timeframe == null && nullToAbsent timeframe: timeframe == null && nullToAbsent
? const Value.absent() ? const Value.absent()
: Value(timeframe), : Value(timeframe),
displayCount: Value(displayCount),
); );
} }
@@ -2870,6 +2899,7 @@ class StatisticTableData extends DataClass
id: serializer.fromJson<String>(json['id']), id: serializer.fromJson<String>(json['id']),
type: serializer.fromJson<String>(json['type']), type: serializer.fromJson<String>(json['type']),
timeframe: serializer.fromJson<String?>(json['timeframe']), timeframe: serializer.fromJson<String?>(json['timeframe']),
displayCount: serializer.fromJson<int>(json['displayCount']),
); );
} }
@override @override
@@ -2879,6 +2909,7 @@ class StatisticTableData extends DataClass
'id': serializer.toJson<String>(id), 'id': serializer.toJson<String>(id),
'type': serializer.toJson<String>(type), 'type': serializer.toJson<String>(type),
'timeframe': serializer.toJson<String?>(timeframe), 'timeframe': serializer.toJson<String?>(timeframe),
'displayCount': serializer.toJson<int>(displayCount),
}; };
} }
@@ -2886,16 +2917,21 @@ class StatisticTableData extends DataClass
String? id, String? id,
String? type, String? type,
Value<String?> timeframe = const Value.absent(), Value<String?> timeframe = const Value.absent(),
int? displayCount,
}) => StatisticTableData( }) => StatisticTableData(
id: id ?? this.id, id: id ?? this.id,
type: type ?? this.type, type: type ?? this.type,
timeframe: timeframe.present ? timeframe.value : this.timeframe, timeframe: timeframe.present ? timeframe.value : this.timeframe,
displayCount: displayCount ?? this.displayCount,
); );
StatisticTableData copyWithCompanion(StatisticTableCompanion data) { StatisticTableData copyWithCompanion(StatisticTableCompanion data) {
return StatisticTableData( return StatisticTableData(
id: data.id.present ? data.id.value : this.id, id: data.id.present ? data.id.value : this.id,
type: data.type.present ? data.type.value : this.type, type: data.type.present ? data.type.value : this.type,
timeframe: data.timeframe.present ? data.timeframe.value : this.timeframe, timeframe: data.timeframe.present ? data.timeframe.value : this.timeframe,
displayCount: data.displayCount.present
? data.displayCount.value
: this.displayCount,
); );
} }
@@ -2904,37 +2940,42 @@ class StatisticTableData extends DataClass
return (StringBuffer('StatisticTableData(') return (StringBuffer('StatisticTableData(')
..write('id: $id, ') ..write('id: $id, ')
..write('type: $type, ') ..write('type: $type, ')
..write('timeframe: $timeframe') ..write('timeframe: $timeframe, ')
..write('displayCount: $displayCount')
..write(')')) ..write(')'))
.toString(); .toString();
} }
@override @override
int get hashCode => Object.hash(id, type, timeframe); int get hashCode => Object.hash(id, type, timeframe, displayCount);
@override @override
bool operator ==(Object other) => bool operator ==(Object other) =>
identical(this, other) || identical(this, other) ||
(other is StatisticTableData && (other is StatisticTableData &&
other.id == this.id && other.id == this.id &&
other.type == this.type && other.type == this.type &&
other.timeframe == this.timeframe); other.timeframe == this.timeframe &&
other.displayCount == this.displayCount);
} }
class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> { class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> {
final Value<String> id; final Value<String> id;
final Value<String> type; final Value<String> type;
final Value<String?> timeframe; final Value<String?> timeframe;
final Value<int> displayCount;
final Value<int> rowid; final Value<int> rowid;
const StatisticTableCompanion({ const StatisticTableCompanion({
this.id = const Value.absent(), this.id = const Value.absent(),
this.type = const Value.absent(), this.type = const Value.absent(),
this.timeframe = const Value.absent(), this.timeframe = const Value.absent(),
this.displayCount = const Value.absent(),
this.rowid = const Value.absent(), this.rowid = const Value.absent(),
}); });
StatisticTableCompanion.insert({ StatisticTableCompanion.insert({
required String id, required String id,
required String type, required String type,
this.timeframe = const Value.absent(), this.timeframe = const Value.absent(),
this.displayCount = const Value.absent(),
this.rowid = const Value.absent(), this.rowid = const Value.absent(),
}) : id = Value(id), }) : id = Value(id),
type = Value(type); type = Value(type);
@@ -2942,12 +2983,14 @@ class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> {
Expression<String>? id, Expression<String>? id,
Expression<String>? type, Expression<String>? type,
Expression<String>? timeframe, Expression<String>? timeframe,
Expression<int>? displayCount,
Expression<int>? rowid, Expression<int>? rowid,
}) { }) {
return RawValuesInsertable({ return RawValuesInsertable({
if (id != null) 'id': id, if (id != null) 'id': id,
if (type != null) 'type': type, if (type != null) 'type': type,
if (timeframe != null) 'timeframe': timeframe, if (timeframe != null) 'timeframe': timeframe,
if (displayCount != null) 'display_count': displayCount,
if (rowid != null) 'rowid': rowid, if (rowid != null) 'rowid': rowid,
}); });
} }
@@ -2956,12 +2999,14 @@ class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> {
Value<String>? id, Value<String>? id,
Value<String>? type, Value<String>? type,
Value<String?>? timeframe, Value<String?>? timeframe,
Value<int>? displayCount,
Value<int>? rowid, Value<int>? rowid,
}) { }) {
return StatisticTableCompanion( return StatisticTableCompanion(
id: id ?? this.id, id: id ?? this.id,
type: type ?? this.type, type: type ?? this.type,
timeframe: timeframe ?? this.timeframe, timeframe: timeframe ?? this.timeframe,
displayCount: displayCount ?? this.displayCount,
rowid: rowid ?? this.rowid, rowid: rowid ?? this.rowid,
); );
} }
@@ -2978,6 +3023,9 @@ class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> {
if (timeframe.present) { if (timeframe.present) {
map['timeframe'] = Variable<String>(timeframe.value); map['timeframe'] = Variable<String>(timeframe.value);
} }
if (displayCount.present) {
map['display_count'] = Variable<int>(displayCount.value);
}
if (rowid.present) { if (rowid.present) {
map['rowid'] = Variable<int>(rowid.value); map['rowid'] = Variable<int>(rowid.value);
} }
@@ -2990,6 +3038,7 @@ class StatisticTableCompanion extends UpdateCompanion<StatisticTableData> {
..write('id: $id, ') ..write('id: $id, ')
..write('type: $type, ') ..write('type: $type, ')
..write('timeframe: $timeframe, ') ..write('timeframe: $timeframe, ')
..write('displayCount: $displayCount, ')
..write('rowid: $rowid') ..write('rowid: $rowid')
..write(')')) ..write(')'))
.toString(); .toString();
@@ -7516,6 +7565,7 @@ typedef $$StatisticTableTableCreateCompanionBuilder =
required String id, required String id,
required String type, required String type,
Value<String?> timeframe, Value<String?> timeframe,
Value<int> displayCount,
Value<int> rowid, Value<int> rowid,
}); });
typedef $$StatisticTableTableUpdateCompanionBuilder = typedef $$StatisticTableTableUpdateCompanionBuilder =
@@ -7523,6 +7573,7 @@ typedef $$StatisticTableTableUpdateCompanionBuilder =
Value<String> id, Value<String> id,
Value<String> type, Value<String> type,
Value<String?> timeframe, Value<String?> timeframe,
Value<int> displayCount,
Value<int> rowid, Value<int> rowid,
}); });
@@ -7645,6 +7696,11 @@ class $$StatisticTableTableFilterComposer
builder: (column) => ColumnFilters(column), builder: (column) => ColumnFilters(column),
); );
ColumnFilters<int> get displayCount => $composableBuilder(
column: $table.displayCount,
builder: (column) => ColumnFilters(column),
);
Expression<bool> statisticScopeTableRefs( Expression<bool> statisticScopeTableRefs(
Expression<bool> Function($$StatisticScopeTableTableFilterComposer f) f, Expression<bool> Function($$StatisticScopeTableTableFilterComposer f) f,
) { ) {
@@ -7744,6 +7800,11 @@ class $$StatisticTableTableOrderingComposer
column: $table.timeframe, column: $table.timeframe,
builder: (column) => ColumnOrderings(column), builder: (column) => ColumnOrderings(column),
); );
ColumnOrderings<int> get displayCount => $composableBuilder(
column: $table.displayCount,
builder: (column) => ColumnOrderings(column),
);
} }
class $$StatisticTableTableAnnotationComposer class $$StatisticTableTableAnnotationComposer
@@ -7764,6 +7825,11 @@ class $$StatisticTableTableAnnotationComposer
GeneratedColumn<String> get timeframe => GeneratedColumn<String> get timeframe =>
$composableBuilder(column: $table.timeframe, builder: (column) => column); $composableBuilder(column: $table.timeframe, builder: (column) => column);
GeneratedColumn<int> get displayCount => $composableBuilder(
column: $table.displayCount,
builder: (column) => column,
);
Expression<T> statisticScopeTableRefs<T extends Object>( Expression<T> statisticScopeTableRefs<T extends Object>(
Expression<T> Function($$StatisticScopeTableTableAnnotationComposer a) f, Expression<T> Function($$StatisticScopeTableTableAnnotationComposer a) f,
) { ) {
@@ -7880,11 +7946,13 @@ class $$StatisticTableTableTableManager
Value<String> id = const Value.absent(), Value<String> id = const Value.absent(),
Value<String> type = const Value.absent(), Value<String> type = const Value.absent(),
Value<String?> timeframe = const Value.absent(), Value<String?> timeframe = const Value.absent(),
Value<int> displayCount = const Value.absent(),
Value<int> rowid = const Value.absent(), Value<int> rowid = const Value.absent(),
}) => StatisticTableCompanion( }) => StatisticTableCompanion(
id: id, id: id,
type: type, type: type,
timeframe: timeframe, timeframe: timeframe,
displayCount: displayCount,
rowid: rowid, rowid: rowid,
), ),
createCompanionCallback: createCompanionCallback:
@@ -7892,11 +7960,13 @@ class $$StatisticTableTableTableManager
required String id, required String id,
required String type, required String type,
Value<String?> timeframe = const Value.absent(), Value<String?> timeframe = const Value.absent(),
Value<int> displayCount = const Value.absent(),
Value<int> rowid = const Value.absent(), Value<int> rowid = const Value.absent(),
}) => StatisticTableCompanion.insert( }) => StatisticTableCompanion.insert(
id: id, id: id,
type: type, type: type,
timeframe: timeframe, timeframe: timeframe,
displayCount: displayCount,
rowid: rowid, rowid: rowid,
), ),
withReferenceMapper: (p0) => p0 withReferenceMapper: (p0) => p0

View File

@@ -4,6 +4,7 @@ class StatisticTable extends Table {
TextColumn get id => text()(); TextColumn get id => text()();
TextColumn get type => text()(); TextColumn get type => text()();
TextColumn get timeframe => text().nullable()(); TextColumn get timeframe => text().nullable()();
IntColumn get displayCount => integer().withDefault(const Constant(5))();
@override @override
Set<Column<Object>> get primaryKey => {id}; Set<Column<Object>> get primaryKey => {id};

View File

@@ -10,14 +10,16 @@ class Statistic {
final Timeframe? timeframe; final Timeframe? timeframe;
final List<Group>? selectedGroups; final List<Group>? selectedGroups;
final List<Game>? selectedGames; final List<Game>? selectedGames;
final int displayCount;
Statistic({ Statistic({
required this.type, required this.type,
required this.scopes, required this.scopes,
String? id,
this.timeframe, this.timeframe,
this.selectedGroups, this.selectedGroups,
this.selectedGames, this.selectedGames,
this.displayCount = 5,
String? id,
}) : id = id ?? const Uuid().v4(); }) : id = id ?? const Uuid().v4();
@override @override

View File

@@ -21,7 +21,6 @@ Widget buildStatisticTile({
required List<Player> players, required List<Player> players,
required BuildContext context, required BuildContext context,
double? width, double? width,
int itemCount = 5,
}) { }) {
final filteredMatches = _getFilterMatches(statistic, matches); final filteredMatches = _getFilterMatches(statistic, matches);
final filteredPlayers = _getFilteredPlayers( final filteredPlayers = _getFilteredPlayers(
@@ -46,7 +45,6 @@ Widget buildStatisticTile({
title: translateStatisticTypeToString(statistic.type, context), title: translateStatisticTypeToString(statistic.type, context),
width: width ?? MediaQuery.sizeOf(context).width * 0.95, width: width ?? MediaQuery.sizeOf(context).width * 0.95,
values: values, values: values,
itemCount: itemCount,
barColor: _getStatisticColor(statistic), barColor: _getStatisticColor(statistic),
statistic: statistic, statistic: statistic,
); );
@@ -297,7 +295,6 @@ Widget buildSkeletonStatisticTile({required BuildContext context}) {
title: 'Skeleton title', title: 'Skeleton title',
width: MediaQuery.sizeOf(context).width * 0.95, width: MediaQuery.sizeOf(context).width * 0.95,
values: values, values: values,
itemCount: count,
barColor: _colorPalette[Random().nextInt(_colorPalette.length)], barColor: _colorPalette[Random().nextInt(_colorPalette.length)],
statistic: Statistic( statistic: Statistic(
type: StatisticType.totalMatches, type: StatisticType.totalMatches,

View File

@@ -26,7 +26,6 @@ class StatisticsTile extends StatelessWidget {
required this.title, required this.title,
required this.width, required this.width,
required this.values, required this.values,
required this.itemCount,
required this.barColor, required this.barColor,
required this.statistic, required this.statistic,
}); });
@@ -43,9 +42,6 @@ class StatisticsTile extends StatelessWidget {
/// A list of tuples containing labels and their corresponding numeric values. /// A list of tuples containing labels and their corresponding numeric values.
final List<(Player, num)> values; final List<(Player, num)> values;
/// The maximum number of items to display.
final int itemCount;
/// The color of the bars representing the values. /// The color of the bars representing the values.
final Color barColor; final Color barColor;
@@ -74,7 +70,7 @@ class StatisticsTile extends StatelessWidget {
child: LayoutBuilder( child: LayoutBuilder(
builder: (context, constraints) { builder: (context, constraints) {
final maxBarWidth = constraints.maxWidth * 0.8; final maxBarWidth = constraints.maxWidth * 0.8;
final displayCount = min(values.length, itemCount); final displayCount = min(values.length, statistic.displayCount);
final displayValues = values.take(displayCount).toList(); final displayValues = values.take(displayCount).toList();
final maxVal = displayValues.isNotEmpty final maxVal = displayValues.isNotEmpty
? displayValues.fold<num>( ? displayValues.fold<num>(

View File

@@ -1,7 +1,7 @@
name: tallee name: tallee
description: "Tracking App for Card Games" description: "Tracking App for Card Games"
publish_to: 'none' publish_to: 'none'
version: 0.0.33+274 version: 0.0.33+276
environment: environment:
sdk: ^3.8.1 sdk: ^3.8.1