feat: changing display count
This commit is contained in:
@@ -26,4 +26,23 @@ class Statistic {
|
|||||||
String toString() {
|
String toString() {
|
||||||
return 'Statistic(id: $id, type: $type, scopes: $scopes, timeframe: $timeframe, selectedGroups: $selectedGroups, selectedGames: $selectedGames)';
|
return 'Statistic(id: $id, type: $type, scopes: $scopes, timeframe: $timeframe, selectedGroups: $selectedGroups, selectedGames: $selectedGames)';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Statistic copyWith({
|
||||||
|
StatisticType? type,
|
||||||
|
List<StatisticScope>? scopes,
|
||||||
|
Timeframe? timeframe,
|
||||||
|
List<Group>? selectedGroups,
|
||||||
|
List<Game>? selectedGames,
|
||||||
|
int? displayCount,
|
||||||
|
}) {
|
||||||
|
return Statistic(
|
||||||
|
id: id,
|
||||||
|
type: type ?? this.type,
|
||||||
|
scopes: scopes ?? this.scopes,
|
||||||
|
timeframe: timeframe ?? this.timeframe,
|
||||||
|
selectedGroups: selectedGroups ?? this.selectedGroups,
|
||||||
|
selectedGames: selectedGames ?? this.selectedGames,
|
||||||
|
displayCount: displayCount ?? this.displayCount,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
"color_red": "Rot",
|
"color_red": "Rot",
|
||||||
"color_teal": "Türkis",
|
"color_teal": "Türkis",
|
||||||
"color_yellow": "Gelb",
|
"color_yellow": "Gelb",
|
||||||
|
"displayed_entries": "Angezeigte Einträge",
|
||||||
"confirm": "Bestätigen",
|
"confirm": "Bestätigen",
|
||||||
"could_not_add_player": "Spieler:in {playerName} konnte nicht hinzugefügt werden",
|
"could_not_add_player": "Spieler:in {playerName} konnte nicht hinzugefügt werden",
|
||||||
"@could_not_add_player": {
|
"@could_not_add_player": {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
"color_purple": "Purple",
|
"color_purple": "Purple",
|
||||||
"color_red": "Red",
|
"color_red": "Red",
|
||||||
"color_teal": "Teal",
|
"color_teal": "Teal",
|
||||||
|
"displayed_entries": "Displayed entries",
|
||||||
"color_yellow": "Yellow",
|
"color_yellow": "Yellow",
|
||||||
"confirm": "Confirm",
|
"confirm": "Confirm",
|
||||||
"could_not_add_player": "Could not add player {playerName}",
|
"could_not_add_player": "Could not add player {playerName}",
|
||||||
|
|||||||
@@ -206,6 +206,12 @@ abstract class AppLocalizations {
|
|||||||
/// **'Teal'**
|
/// **'Teal'**
|
||||||
String get color_teal;
|
String get color_teal;
|
||||||
|
|
||||||
|
/// No description provided for @displayed_entries.
|
||||||
|
///
|
||||||
|
/// In en, this message translates to:
|
||||||
|
/// **'Displayed entries'**
|
||||||
|
String get displayed_entries;
|
||||||
|
|
||||||
/// No description provided for @color_yellow.
|
/// No description provided for @color_yellow.
|
||||||
///
|
///
|
||||||
/// In en, this message translates to:
|
/// In en, this message translates to:
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ class AppLocalizationsDe extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get color_teal => 'Türkis';
|
String get color_teal => 'Türkis';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get displayed_entries => 'Angezeigte Einträge';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get color_yellow => 'Gelb';
|
String get color_yellow => 'Gelb';
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,9 @@ class AppLocalizationsEn extends AppLocalizations {
|
|||||||
@override
|
@override
|
||||||
String get color_teal => 'Teal';
|
String get color_teal => 'Teal';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get displayed_entries => 'Displayed entries';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get color_yellow => 'Yellow';
|
String get color_yellow => 'Yellow';
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:tallee/data/db/database.dart';
|
||||||
import 'package:tallee/data/models/player.dart';
|
import 'package:tallee/data/models/player.dart';
|
||||||
import 'package:tallee/data/models/statistic.dart';
|
import 'package:tallee/data/models/statistic.dart';
|
||||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/statistics_view/create_statistic_view.dart'
|
import 'package:tallee/presentation/views/main_menu/statistics_view/create_statistic_view.dart';
|
||||||
show
|
|
||||||
translateScopeToString,
|
|
||||||
translateStatisticTypeToString,
|
|
||||||
translateTimeframeToString;
|
|
||||||
import 'package:tallee/presentation/widgets/buttons/haptic_icon_button.dart';
|
import 'package:tallee/presentation/widgets/buttons/haptic_icon_button.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/statistics_tile.dart';
|
import 'package:tallee/presentation/widgets/tiles/statistics_tile.dart';
|
||||||
@@ -30,7 +28,7 @@ class StatisticDetailView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _StatisticDetailViewState extends State<StatisticDetailView> {
|
class _StatisticDetailViewState extends State<StatisticDetailView> {
|
||||||
int displayCount = 0;
|
late int displayCount;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@@ -48,7 +46,13 @@ class _StatisticDetailViewState extends State<StatisticDetailView> {
|
|||||||
const style = TextStyle(fontWeight: FontWeight.bold);
|
const style = TextStyle(fontWeight: FontWeight.bold);
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(title: Text(title)),
|
appBar: AppBar(
|
||||||
|
title: Text(title),
|
||||||
|
leading: HapticIconButton(
|
||||||
|
icon: const Icon(Icons.arrow_back_ios_new),
|
||||||
|
onPressed: () => handleBack(context),
|
||||||
|
),
|
||||||
|
),
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
padding: const EdgeInsets.all(12.0),
|
padding: const EdgeInsets.all(12.0),
|
||||||
child: Column(
|
child: Column(
|
||||||
@@ -141,7 +145,7 @@ class _StatisticDetailViewState extends State<StatisticDetailView> {
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
const Text('Display count', style: style),
|
Text(loc.displayed_entries, style: style),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
HapticIconButton(
|
HapticIconButton(
|
||||||
@@ -175,4 +179,11 @@ class _StatisticDetailViewState extends State<StatisticDetailView> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handles saving the display count and giving it to statistics view
|
||||||
|
Future<void> handleBack(BuildContext context) async {
|
||||||
|
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
|
await db.statisticDao.updateDisplayCount(widget.statistic.id, displayCount);
|
||||||
|
if (context.mounted) Navigator.of(context).pop(displayCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
bool isLoading = true;
|
bool isLoading = true;
|
||||||
List<Match> _allMatches = const [];
|
List<Match> _allMatches = const [];
|
||||||
List<Player> _allPlayers = const [];
|
List<Player> _allPlayers = const [];
|
||||||
|
List<Statistic> _statistics = const [];
|
||||||
List<Widget> statisticTiles = [];
|
List<Widget> statisticTiles = [];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -34,7 +35,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
getStatisticTiles(context);
|
loadStatistics(context);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,15 +85,16 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
context,
|
context,
|
||||||
adaptivePageRoute(
|
adaptivePageRoute(
|
||||||
builder: (context) => CreateStatisticView(
|
builder: (context) => CreateStatisticView(
|
||||||
onStatisticCreated: () => getStatisticTiles(context),
|
onStatisticCreated: () => loadStatistics(context),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
final newTile = _buildStatisticTile(context, newStatistic);
|
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
statisticTiles.add(newTile);
|
_statistics = [..._statistics, newStatistic];
|
||||||
|
statisticTiles = _statistics
|
||||||
|
.map((stat) => _buildStatisticTile(context, stat))
|
||||||
|
.toList();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -103,7 +105,7 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> getStatisticTiles(BuildContext context) async {
|
Future<void> loadStatistics(BuildContext context) async {
|
||||||
setState(() {
|
setState(() {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
statisticTiles = List.generate(
|
statisticTiles = List.generate(
|
||||||
@@ -131,27 +133,26 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
final statistics = results[0] as List<Statistic>;
|
final statistics = results[0] as List<Statistic>;
|
||||||
_allMatches = results[1] as List<Match>;
|
_allMatches = results[1] as List<Match>;
|
||||||
_allPlayers = results[2] as List<Player>;
|
_allPlayers = results[2] as List<Player>;
|
||||||
|
_statistics = statistics;
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
statisticTiles = [
|
statisticTiles = _statistics
|
||||||
for (final statistic in statistics) ...[
|
.map((stat) => _buildStatisticTile(context, stat))
|
||||||
_buildStatisticTile(context, statistic),
|
.toList();
|
||||||
],
|
|
||||||
];
|
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildStatisticTile(BuildContext context, Statistic statistic) {
|
Widget _buildStatisticTile(BuildContext context, Statistic statistic) {
|
||||||
return GestureDetector(
|
|
||||||
onTap: () {
|
|
||||||
final values = computeStatisticValues(
|
final values = computeStatisticValues(
|
||||||
statistic: statistic,
|
statistic: statistic,
|
||||||
matches: _allMatches,
|
matches: _allMatches,
|
||||||
players: _allPlayers,
|
players: _allPlayers,
|
||||||
);
|
);
|
||||||
|
|
||||||
Navigator.push(
|
return GestureDetector(
|
||||||
|
onTap: () async {
|
||||||
|
final newDisplayCount = await Navigator.push(
|
||||||
context,
|
context,
|
||||||
adaptivePageRoute(
|
adaptivePageRoute(
|
||||||
builder: (context) => StatisticDetailView(
|
builder: (context) => StatisticDetailView(
|
||||||
@@ -162,6 +163,21 @@ class _StatisticsViewState extends State<StatisticsView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
if (newDisplayCount != null &&
|
||||||
|
newDisplayCount != statistic.displayCount) {
|
||||||
|
setState(() {
|
||||||
|
_statistics = _statistics
|
||||||
|
.map(
|
||||||
|
(stat) => stat.id == statistic.id
|
||||||
|
? stat.copyWith(displayCount: newDisplayCount)
|
||||||
|
: stat,
|
||||||
|
)
|
||||||
|
.toList();
|
||||||
|
statisticTiles = _statistics
|
||||||
|
.map((stat) => _buildStatisticTile(context, stat))
|
||||||
|
.toList();
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: buildStatisticTile(
|
child: buildStatisticTile(
|
||||||
statistic: statistic,
|
statistic: statistic,
|
||||||
|
|||||||
@@ -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+280
|
version: 0.0.33+281
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.8.1
|
sdk: ^3.8.1
|
||||||
|
|||||||
Reference in New Issue
Block a user