From 428f9670103b47e40c969c7bd40b076d6a1158a3 Mon Sep 17 00:00:00 2001 From: Felix Kirchner Date: Sun, 24 May 2026 23:09:08 +0200 Subject: [PATCH] feat: displayCount --- lib/data/dao/statistic_dao.dart | 22 +++++- lib/data/db/database.g.dart | 78 ++++++++++++++++++- lib/data/db/tables/statistic_table.dart | 1 + lib/data/models/statistic.dart | 4 +- .../statistic_tile_factory.dart | 3 - .../widgets/tiles/statistics_tile.dart | 6 +- pubspec.yaml | 2 +- 7 files changed, 98 insertions(+), 18 deletions(-) diff --git a/lib/data/dao/statistic_dao.dart b/lib/data/dao/statistic_dao.dart index 39904fc..7bdebde 100644 --- a/lib/data/dao/statistic_dao.dart +++ b/lib/data/dao/statistic_dao.dart @@ -20,6 +20,7 @@ class StatisticDao extends DatabaseAccessor id: statistic.id, type: statistic.type.name, timeframe: Value(statistic.timeframe?.name), + displayCount: Value(statistic.displayCount), ), mode: InsertMode.insertOrReplace, ); @@ -59,12 +60,13 @@ class StatisticDao extends DatabaseAccessor return Statistic( type: StatisticType.values.firstWhere((type) => type.name == row.type), scopes: scopes, - id: row.id, timeframe: Timeframe.values.firstWhereOrNull( (t) => t.name == row.timeframe, ), selectedGroups: groups, selectedGames: games, + displayCount: row.displayCount, + id: row.id, ); } return null; @@ -73,9 +75,9 @@ class StatisticDao extends DatabaseAccessor /// Retrieves all statistics from the database, including their associated groups and games. Future> getAllStatistics() async { final query = select(statisticTable); - final rows = await query.get(); + final result = await query.get(); return Future.wait( - rows.map((row) async { + result.map((row) async { final groups = await db.statisticGroupDao.getGroupsForStatistic(row.id); final games = await db.statisticGameDao.getGamesForStatistic(row.id); @@ -84,17 +86,29 @@ class StatisticDao extends DatabaseAccessor (type) => type.name == row.type, ), scopes: [], - id: row.id, timeframe: Timeframe.values.firstWhereOrNull( (t) => t.name == row.timeframe, ), selectedGroups: groups, selectedGames: games, + displayCount: row.displayCount, + id: row.id, ); }), ); } + /* Update */ + + Future 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 */ Future deleteStatistic(String statisticId) async { diff --git a/lib/data/db/database.g.dart b/lib/data/db/database.g.dart index 489b890..3a9d277 100644 --- a/lib/data/db/database.g.dart +++ b/lib/data/db/database.g.dart @@ -2767,8 +2767,20 @@ class $StatisticTableTable extends StatisticTable type: DriftSqlType.string, requiredDuringInsert: false, ); + static const VerificationMeta _displayCountMeta = const VerificationMeta( + 'displayCount', + ); @override - List get $columns => [id, type, timeframe]; + late final GeneratedColumn displayCount = GeneratedColumn( + 'display_count', + aliasedName, + false, + type: DriftSqlType.int, + requiredDuringInsert: false, + defaultValue: const Constant(5), + ); + @override + List get $columns => [id, type, timeframe, displayCount]; @override String get aliasedName => _alias ?? actualTableName; @override @@ -2800,6 +2812,15 @@ class $StatisticTableTable extends StatisticTable timeframe.isAcceptableOrUnknown(data['timeframe']!, _timeframeMeta), ); } + if (data.containsKey('display_count')) { + context.handle( + _displayCountMeta, + displayCount.isAcceptableOrUnknown( + data['display_count']!, + _displayCountMeta, + ), + ); + } return context; } @@ -2821,6 +2842,10 @@ class $StatisticTableTable extends StatisticTable DriftSqlType.string, 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 type; final String? timeframe; + final int displayCount; const StatisticTableData({ required this.id, required this.type, this.timeframe, + required this.displayCount, }); @override Map toColumns(bool nullToAbsent) { @@ -2848,6 +2875,7 @@ class StatisticTableData extends DataClass if (!nullToAbsent || timeframe != null) { map['timeframe'] = Variable(timeframe); } + map['display_count'] = Variable(displayCount); return map; } @@ -2858,6 +2886,7 @@ class StatisticTableData extends DataClass timeframe: timeframe == null && nullToAbsent ? const Value.absent() : Value(timeframe), + displayCount: Value(displayCount), ); } @@ -2870,6 +2899,7 @@ class StatisticTableData extends DataClass id: serializer.fromJson(json['id']), type: serializer.fromJson(json['type']), timeframe: serializer.fromJson(json['timeframe']), + displayCount: serializer.fromJson(json['displayCount']), ); } @override @@ -2879,6 +2909,7 @@ class StatisticTableData extends DataClass 'id': serializer.toJson(id), 'type': serializer.toJson(type), 'timeframe': serializer.toJson(timeframe), + 'displayCount': serializer.toJson(displayCount), }; } @@ -2886,16 +2917,21 @@ class StatisticTableData extends DataClass String? id, String? type, Value timeframe = const Value.absent(), + int? displayCount, }) => StatisticTableData( id: id ?? this.id, type: type ?? this.type, timeframe: timeframe.present ? timeframe.value : this.timeframe, + displayCount: displayCount ?? this.displayCount, ); StatisticTableData copyWithCompanion(StatisticTableCompanion data) { return StatisticTableData( id: data.id.present ? data.id.value : this.id, type: data.type.present ? data.type.value : this.type, 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(') ..write('id: $id, ') ..write('type: $type, ') - ..write('timeframe: $timeframe') + ..write('timeframe: $timeframe, ') + ..write('displayCount: $displayCount') ..write(')')) .toString(); } @override - int get hashCode => Object.hash(id, type, timeframe); + int get hashCode => Object.hash(id, type, timeframe, displayCount); @override bool operator ==(Object other) => identical(this, other) || (other is StatisticTableData && other.id == this.id && other.type == this.type && - other.timeframe == this.timeframe); + other.timeframe == this.timeframe && + other.displayCount == this.displayCount); } class StatisticTableCompanion extends UpdateCompanion { final Value id; final Value type; final Value timeframe; + final Value displayCount; final Value rowid; const StatisticTableCompanion({ this.id = const Value.absent(), this.type = const Value.absent(), this.timeframe = const Value.absent(), + this.displayCount = const Value.absent(), this.rowid = const Value.absent(), }); StatisticTableCompanion.insert({ required String id, required String type, this.timeframe = const Value.absent(), + this.displayCount = const Value.absent(), this.rowid = const Value.absent(), }) : id = Value(id), type = Value(type); @@ -2942,12 +2983,14 @@ class StatisticTableCompanion extends UpdateCompanion { Expression? id, Expression? type, Expression? timeframe, + Expression? displayCount, Expression? rowid, }) { return RawValuesInsertable({ if (id != null) 'id': id, if (type != null) 'type': type, if (timeframe != null) 'timeframe': timeframe, + if (displayCount != null) 'display_count': displayCount, if (rowid != null) 'rowid': rowid, }); } @@ -2956,12 +2999,14 @@ class StatisticTableCompanion extends UpdateCompanion { Value? id, Value? type, Value? timeframe, + Value? displayCount, Value? rowid, }) { return StatisticTableCompanion( id: id ?? this.id, type: type ?? this.type, timeframe: timeframe ?? this.timeframe, + displayCount: displayCount ?? this.displayCount, rowid: rowid ?? this.rowid, ); } @@ -2978,6 +3023,9 @@ class StatisticTableCompanion extends UpdateCompanion { if (timeframe.present) { map['timeframe'] = Variable(timeframe.value); } + if (displayCount.present) { + map['display_count'] = Variable(displayCount.value); + } if (rowid.present) { map['rowid'] = Variable(rowid.value); } @@ -2990,6 +3038,7 @@ class StatisticTableCompanion extends UpdateCompanion { ..write('id: $id, ') ..write('type: $type, ') ..write('timeframe: $timeframe, ') + ..write('displayCount: $displayCount, ') ..write('rowid: $rowid') ..write(')')) .toString(); @@ -7516,6 +7565,7 @@ typedef $$StatisticTableTableCreateCompanionBuilder = required String id, required String type, Value timeframe, + Value displayCount, Value rowid, }); typedef $$StatisticTableTableUpdateCompanionBuilder = @@ -7523,6 +7573,7 @@ typedef $$StatisticTableTableUpdateCompanionBuilder = Value id, Value type, Value timeframe, + Value displayCount, Value rowid, }); @@ -7645,6 +7696,11 @@ class $$StatisticTableTableFilterComposer builder: (column) => ColumnFilters(column), ); + ColumnFilters get displayCount => $composableBuilder( + column: $table.displayCount, + builder: (column) => ColumnFilters(column), + ); + Expression statisticScopeTableRefs( Expression Function($$StatisticScopeTableTableFilterComposer f) f, ) { @@ -7744,6 +7800,11 @@ class $$StatisticTableTableOrderingComposer column: $table.timeframe, builder: (column) => ColumnOrderings(column), ); + + ColumnOrderings get displayCount => $composableBuilder( + column: $table.displayCount, + builder: (column) => ColumnOrderings(column), + ); } class $$StatisticTableTableAnnotationComposer @@ -7764,6 +7825,11 @@ class $$StatisticTableTableAnnotationComposer GeneratedColumn get timeframe => $composableBuilder(column: $table.timeframe, builder: (column) => column); + GeneratedColumn get displayCount => $composableBuilder( + column: $table.displayCount, + builder: (column) => column, + ); + Expression statisticScopeTableRefs( Expression Function($$StatisticScopeTableTableAnnotationComposer a) f, ) { @@ -7880,11 +7946,13 @@ class $$StatisticTableTableTableManager Value id = const Value.absent(), Value type = const Value.absent(), Value timeframe = const Value.absent(), + Value displayCount = const Value.absent(), Value rowid = const Value.absent(), }) => StatisticTableCompanion( id: id, type: type, timeframe: timeframe, + displayCount: displayCount, rowid: rowid, ), createCompanionCallback: @@ -7892,11 +7960,13 @@ class $$StatisticTableTableTableManager required String id, required String type, Value timeframe = const Value.absent(), + Value displayCount = const Value.absent(), Value rowid = const Value.absent(), }) => StatisticTableCompanion.insert( id: id, type: type, timeframe: timeframe, + displayCount: displayCount, rowid: rowid, ), withReferenceMapper: (p0) => p0 diff --git a/lib/data/db/tables/statistic_table.dart b/lib/data/db/tables/statistic_table.dart index d627894..ef368a5 100644 --- a/lib/data/db/tables/statistic_table.dart +++ b/lib/data/db/tables/statistic_table.dart @@ -4,6 +4,7 @@ class StatisticTable extends Table { TextColumn get id => text()(); TextColumn get type => text()(); TextColumn get timeframe => text().nullable()(); + IntColumn get displayCount => integer().withDefault(const Constant(5))(); @override Set> get primaryKey => {id}; diff --git a/lib/data/models/statistic.dart b/lib/data/models/statistic.dart index 3d118f7..4fdbb05 100644 --- a/lib/data/models/statistic.dart +++ b/lib/data/models/statistic.dart @@ -10,14 +10,16 @@ class Statistic { final Timeframe? timeframe; final List? selectedGroups; final List? selectedGames; + final int displayCount; Statistic({ required this.type, required this.scopes, - String? id, this.timeframe, this.selectedGroups, this.selectedGames, + this.displayCount = 5, + String? id, }) : id = id ?? const Uuid().v4(); @override diff --git a/lib/presentation/views/main_menu/statistics_view/statistic_tile_factory.dart b/lib/presentation/views/main_menu/statistics_view/statistic_tile_factory.dart index 8461f6d..fd43390 100644 --- a/lib/presentation/views/main_menu/statistics_view/statistic_tile_factory.dart +++ b/lib/presentation/views/main_menu/statistics_view/statistic_tile_factory.dart @@ -21,7 +21,6 @@ Widget buildStatisticTile({ required List players, required BuildContext context, double? width, - int itemCount = 5, }) { final filteredMatches = _getFilterMatches(statistic, matches); final filteredPlayers = _getFilteredPlayers( @@ -46,7 +45,6 @@ Widget buildStatisticTile({ title: translateStatisticTypeToString(statistic.type, context), width: width ?? MediaQuery.sizeOf(context).width * 0.95, values: values, - itemCount: itemCount, barColor: _getStatisticColor(statistic), statistic: statistic, ); @@ -297,7 +295,6 @@ Widget buildSkeletonStatisticTile({required BuildContext context}) { title: 'Skeleton title', width: MediaQuery.sizeOf(context).width * 0.95, values: values, - itemCount: count, barColor: _colorPalette[Random().nextInt(_colorPalette.length)], statistic: Statistic( type: StatisticType.totalMatches, diff --git a/lib/presentation/widgets/tiles/statistics_tile.dart b/lib/presentation/widgets/tiles/statistics_tile.dart index ad850dd..24d51fc 100644 --- a/lib/presentation/widgets/tiles/statistics_tile.dart +++ b/lib/presentation/widgets/tiles/statistics_tile.dart @@ -26,7 +26,6 @@ class StatisticsTile extends StatelessWidget { required this.title, required this.width, required this.values, - required this.itemCount, required this.barColor, required this.statistic, }); @@ -43,9 +42,6 @@ class StatisticsTile extends StatelessWidget { /// A list of tuples containing labels and their corresponding numeric values. final List<(Player, num)> values; - /// The maximum number of items to display. - final int itemCount; - /// The color of the bars representing the values. final Color barColor; @@ -74,7 +70,7 @@ class StatisticsTile extends StatelessWidget { child: LayoutBuilder( builder: (context, constraints) { 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 maxVal = displayValues.isNotEmpty ? displayValues.fold( diff --git a/pubspec.yaml b/pubspec.yaml index b6563cc..d6fd994 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: tallee description: "Tracking App for Card Games" publish_to: 'none' -version: 0.0.33+274 +version: 0.0.33+276 environment: sdk: ^3.8.1