Merge branch 'development' into enhancement/75-Group-erstellen-nur-möglich-mit-min.-2-spielern
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m13s
Pull Request Pipeline / lint (pull_request) Successful in 2m14s

This commit is contained in:
2025-12-07 14:04:19 +00:00
6 changed files with 317 additions and 130 deletions

View File

@@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart'; import 'package:game_tracker/core/custom_theme.dart';
import 'package:game_tracker/data/db/database.dart'; import 'package:game_tracker/data/db/database.dart';
@@ -5,6 +6,7 @@ import 'package:game_tracker/data/dto/game.dart';
import 'package:game_tracker/data/dto/group.dart'; import 'package:game_tracker/data/dto/group.dart';
import 'package:game_tracker/data/dto/player.dart'; import 'package:game_tracker/data/dto/player.dart';
import 'package:game_tracker/presentation/views/main_menu/create_group_view.dart'; import 'package:game_tracker/presentation/views/main_menu/create_group_view.dart';
import 'package:game_tracker/presentation/views/main_menu/game_result_view.dart';
import 'package:game_tracker/presentation/widgets/app_skeleton.dart'; import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart'; import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
import 'package:game_tracker/presentation/widgets/tiles/game_history_tile.dart'; import 'package:game_tracker/presentation/widgets/tiles/game_history_tile.dart';
@@ -21,24 +23,17 @@ class GameHistoryView extends StatefulWidget {
class _GameHistoryViewState extends State<GameHistoryView> { class _GameHistoryViewState extends State<GameHistoryView> {
late Future<List<Game>> _gameListFuture; late Future<List<Game>> _gameListFuture;
late final AppDatabase db; late final AppDatabase db;
late bool isLoading = true;
late final List<Game> skeletonData = List.filled( late final List<Game> skeletonData = List.filled(
4, 4,
Game( Game(
name: 'Skeleton Game', name: 'Skeleton Gamename',
group: Group( group: Group(
name: 'Skeleton Group', name: 'Groupname',
members: [ members: List.generate(5, (index) => Player(name: 'Player')),
Player(name: 'Player 1'),
Player(name: 'Player 2'),
Player(name: 'Player 3'),
Player(name: 'Long Name Player 4'),
Player(name: 'Player 5'),
],
), ),
winner: Player(name: 'Skeleton Player 1'), winner: Player(name: 'Player'),
players: [Player(name: 'Skeleton Player 6')], players: [Player(name: 'Player')],
), ),
); );
@@ -46,14 +41,10 @@ class _GameHistoryViewState extends State<GameHistoryView> {
void initState() { void initState() {
super.initState(); super.initState();
db = Provider.of<AppDatabase>(context, listen: false); db = Provider.of<AppDatabase>(context, listen: false);
_gameListFuture = db.gameDao.getAllGames(); _gameListFuture = Future.delayed(
const Duration(milliseconds: 250),
Future.wait([_gameListFuture]).then((result) async { () => db.gameDao.getAllGames(),
await Future.delayed(const Duration(milliseconds: 250)); );
setState(() {
isLoading = false;
});
});
} }
@override @override
@@ -81,19 +72,19 @@ class _GameHistoryViewState extends State<GameHistoryView> {
return const Center( return const Center(
child: TopCenteredMessage( child: TopCenteredMessage(
icon: Icons.report, icon: Icons.report,
title: 'Error', title: 'Info',
message: 'No Games Available', message: 'No games created yet',
), ),
); );
} }
final bool isLoading =
snapshot.connectionState == ConnectionState.waiting;
final List<Game> games = final List<Game> games =
(isLoading ? skeletonData : (snapshot.data ?? []) (isLoading ? skeletonData : (snapshot.data ?? [])
..sort( ..sort(
(a, b) => b.createdAt.compareTo(a.createdAt), (a, b) => b.createdAt.compareTo(a.createdAt),
)) ))
.toList(); .toList();
return AppSkeleton( return AppSkeleton(
enabled: isLoading, enabled: isLoading,
child: ListView.builder( child: ListView.builder(
@@ -106,8 +97,21 @@ class _GameHistoryViewState extends State<GameHistoryView> {
); );
} }
return GameHistoryTile( return GameHistoryTile(
onTap: () async {
await Navigator.push(
context,
CupertinoPageRoute(
fullscreenDialog: true,
builder: (context) =>
GameResultView(game: games[index]),
),
);
setState(() {
_gameListFuture = db.gameDao.getAllGames();
});
},
game: games[index], game: games[index],
); // Placeholder );
}, },
), ),
); );

View File

@@ -0,0 +1,144 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
import 'package:game_tracker/data/db/database.dart';
import 'package:game_tracker/data/dto/game.dart';
import 'package:game_tracker/data/dto/player.dart';
import 'package:game_tracker/presentation/widgets/tiles/custom_radio_list_tile.dart';
import 'package:provider/provider.dart';
class GameResultView extends StatefulWidget {
final Game game;
const GameResultView({super.key, required this.game});
@override
State<GameResultView> createState() => _GameResultViewState();
}
class _GameResultViewState extends State<GameResultView> {
late final List<Player> allPlayers;
late final AppDatabase db;
Player? _selectedPlayer;
@override
void initState() {
db = Provider.of<AppDatabase>(context, listen: false);
allPlayers = getAllPlayers(widget.game);
if (widget.game.winner != null) {
_selectedPlayer = allPlayers.firstWhere(
(p) => p.id == widget.game.winner!.id,
);
}
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: CustomTheme.backgroundColor,
appBar: AppBar(
backgroundColor: CustomTheme.backgroundColor,
scrolledUnderElevation: 0,
title: Text(
widget.game.name,
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
overflow: TextOverflow.ellipsis,
),
),
centerTitle: true,
),
body: SafeArea(
child: Column(
children: [
Expanded(
child: Container(
margin: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 10,
),
padding: const EdgeInsets.symmetric(
vertical: 10,
horizontal: 10,
),
decoration: BoxDecoration(
color: CustomTheme.boxColor,
border: Border.all(color: CustomTheme.boxBorder),
borderRadius: BorderRadius.circular(12),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Select Winner:',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
),
const SizedBox(height: 10),
Expanded(
child: RadioGroup<Player>(
groupValue: _selectedPlayer,
onChanged: (Player? value) async {
setState(() {
_selectedPlayer = value;
});
await _handleWinnerSaving();
},
child: ListView.builder(
itemCount: allPlayers.length,
itemBuilder: (context, index) {
return CustomRadioListTile(
text: allPlayers[index].name,
value: allPlayers[index],
onContainerTap: (value) async {
setState(() {
// Check if the already selected player is the same as the newly tapped player.
if (_selectedPlayer == value) {
// If yes deselected the player by setting it to null.
_selectedPlayer = null;
} else {
// If no assign the newly tapped player to the selected player.
(_selectedPlayer = value);
}
});
await _handleWinnerSaving();
},
);
},
),
),
),
],
),
),
),
],
),
),
);
}
Future<void> _handleWinnerSaving() async {
if (_selectedPlayer == null) {
await db.gameDao.removeWinner(gameId: widget.game.id);
} else {
await db.gameDao.setWinner(
gameId: widget.game.id,
winnerId: _selectedPlayer!.id,
);
}
}
List<Player> getAllPlayers(Game game) {
if (game.group == null && game.players != null) {
return [...game.players!];
} else if (game.group != null && game.players != null) {
return [...game.players!, ...game.group!.members];
}
return [...game.group!.members];
}
}

View File

@@ -56,7 +56,7 @@ class _GroupsViewState extends State<GroupsView> {
child: TopCenteredMessage( child: TopCenteredMessage(
icon: Icons.report, icon: Icons.report,
title: 'Error', title: 'Error',
message: 'Group data couldn\'t\nbe loaded.', message: 'Group data couldn\'t\nbe loaded',
), ),
); );
} }
@@ -66,7 +66,7 @@ class _GroupsViewState extends State<GroupsView> {
child: TopCenteredMessage( child: TopCenteredMessage(
icon: Icons.info, icon: Icons.info,
title: 'Info', title: 'Info',
message: 'No groups created yet.', message: 'No groups created yet',
), ),
); );
} }

View File

@@ -30,7 +30,7 @@ class CustomSearchBar extends StatelessWidget {
constraints: constraints:
constraints ?? const BoxConstraints(maxHeight: 45, minHeight: 45), constraints ?? const BoxConstraints(maxHeight: 45, minHeight: 45),
hintText: hintText, hintText: hintText,
onChanged: trailingButtonEnabled ? onChanged : null, onChanged: onChanged,
hintStyle: WidgetStateProperty.all(const TextStyle(fontSize: 16)), hintStyle: WidgetStateProperty.all(const TextStyle(fontSize: 16)),
leading: const Icon(Icons.search), leading: const Icon(Icons.search),
trailing: [ trailing: [

View File

@@ -0,0 +1,50 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
class CustomRadioListTile<T> extends StatelessWidget {
final String text;
final T value;
final ValueChanged<T> onContainerTap;
const CustomRadioListTile({
super.key,
required this.text,
required this.value,
required this.onContainerTap,
});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => onContainerTap(value),
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
padding: const EdgeInsets.symmetric(horizontal: 2),
decoration: BoxDecoration(
color: CustomTheme.boxColor,
border: Border.all(color: CustomTheme.boxBorder),
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
Radio<T>(
value: value,
activeColor: CustomTheme.primaryColor,
toggleable: true,
),
Expanded(
child: Text(
text,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
),
],
),
),
);
}
}

View File

@@ -6,142 +6,132 @@ import 'package:intl/intl.dart';
class GameHistoryTile extends StatefulWidget { class GameHistoryTile extends StatefulWidget {
final Game game; final Game game;
final VoidCallback onTap;
const GameHistoryTile({ const GameHistoryTile({super.key, required this.game, required this.onTap});
super.key,
required this.game,
});
@override @override
State<GameHistoryTile> createState() => _GameHistoryTileState(); State<GameHistoryTile> createState() => _GameHistoryTileState();
} }
class _GameHistoryTileState extends State<GameHistoryTile> { class _GameHistoryTileState extends State<GameHistoryTile> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final group = widget.game.group; final group = widget.game.group;
final winner = widget.game.winner; final winner = widget.game.winner;
final allPlayers = _getAllPlayers(); final allPlayers = _getAllPlayers();
return Container( return GestureDetector(
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), onTap: widget.onTap,
padding: const EdgeInsets.all(16), child: Container(
decoration: BoxDecoration( margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
color: CustomTheme.boxColor, padding: const EdgeInsets.all(16),
border: Border.all(color: CustomTheme.boxBorder), decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12), color: CustomTheme.boxColor,
), border: Border.all(color: CustomTheme.boxBorder),
child: Column( borderRadius: BorderRadius.circular(12),
crossAxisAlignment: CrossAxisAlignment.start, ),
children: [ child: Column(
Row( crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
children: [
Expanded(
child: Text(
widget.game.name,
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
),
),
Text(
_formatDate(widget.game.createdAt),
style: const TextStyle(
fontSize: 12,
color: Colors.grey,
),
),
],
),
const SizedBox(height: 8),
if (group != null) ...[
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
const Icon(
Icons.group,
size: 16,
color: Colors.grey,
),
const SizedBox(width: 6),
Expanded( Expanded(
child: Text( child: Text(
group.name, widget.game.name,
style: const TextStyle( style: const TextStyle(
fontSize: 14, fontSize: 18,
color: Colors.grey, fontWeight: FontWeight.bold,
), ),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ),
Text(
_formatDate(widget.game.createdAt),
style: const TextStyle(fontSize: 12, color: Colors.grey),
),
], ],
), ),
const SizedBox(height: 12),
],
if (winner != null) ...[ const SizedBox(height: 8),
Container(
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12), if (group != null) ...[
decoration: BoxDecoration( Row(
color: Colors.green.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Colors.green.withValues(alpha: 0.3),
width: 1,
),
),
child: Row(
children: [ children: [
const Icon( const Icon(Icons.group, size: 16, color: Colors.grey),
Icons.emoji_events, const SizedBox(width: 6),
size: 20,
color: Colors.amber,
),
const SizedBox(width: 8),
Expanded( Expanded(
child: Text( child: Text(
'Winner: ${winner.name}', group.name,
style: const TextStyle( style: const TextStyle(fontSize: 14, color: Colors.grey),
fontSize: 14,
fontWeight: FontWeight.w600,
color: Colors.white,
),
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
), ),
), ),
], ],
), ),
), const SizedBox(height: 12),
const SizedBox(height: 12), ],
],
if (allPlayers.isNotEmpty) ...[ if (winner != null) ...[
const Text( Container(
'Players', padding: const EdgeInsets.symmetric(
style: TextStyle( vertical: 8,
fontSize: 13, horizontal: 12,
color: Colors.grey, ),
fontWeight: FontWeight.w500, decoration: BoxDecoration(
color: Colors.green.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: Colors.green.withValues(alpha: 0.3),
width: 1,
),
),
child: Row(
children: [
const Icon(
Icons.emoji_events,
size: 20,
color: Colors.amber,
),
const SizedBox(width: 8),
Expanded(
child: Text(
'Winner: ${winner.name}',
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Colors.white,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
), ),
), const SizedBox(height: 12),
const SizedBox(height: 6), ],
Wrap(
spacing: 6, if (allPlayers.isNotEmpty) ...[
runSpacing: 6, const Text(
children: allPlayers.map((player) { 'Players',
return TextIconTile( style: TextStyle(
text: player.name, fontSize: 13,
iconEnabled: false, color: Colors.grey,
); fontWeight: FontWeight.w500,
}).toList(), ),
), ),
const SizedBox(height: 6),
Wrap(
spacing: 6,
runSpacing: 6,
children: allPlayers.map((player) {
return TextIconTile(text: player.name, iconEnabled: false);
}).toList(),
),
],
], ],
], ),
), ),
); );
} }
@@ -187,5 +177,4 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
return allPlayers; return allPlayers;
} }
}
}