Merge branch 'development' into setup/57-provisorisches-app-icon-implementiere
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m31s
Pull Request Pipeline / lint (pull_request) Successful in 2m33s

This commit is contained in:
2025-11-23 19:26:05 +01:00

View File

@@ -1,5 +1,8 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:game_tracker/data/db/database.dart'; import 'package:game_tracker/data/db/database.dart';
import 'package:game_tracker/data/dto/game.dart';
import 'package:game_tracker/data/dto/group.dart';
import 'package:game_tracker/data/dto/player.dart';
import 'package:game_tracker/presentation/widgets/buttons/quick_create_button.dart'; import 'package:game_tracker/presentation/widgets/buttons/quick_create_button.dart';
import 'package:game_tracker/presentation/widgets/tiles/game_tile.dart'; import 'package:game_tracker/presentation/widgets/tiles/game_tile.dart';
import 'package:game_tracker/presentation/widgets/tiles/info_tile.dart'; import 'package:game_tracker/presentation/widgets/tiles/info_tile.dart';
@@ -17,23 +20,42 @@ class HomeView extends StatefulWidget {
class _HomeViewState extends State<HomeView> { class _HomeViewState extends State<HomeView> {
late Future<int> _gameCountFuture; late Future<int> _gameCountFuture;
late Future<int> _groupCountFuture; late Future<int> _groupCountFuture;
late Future<List<Game>> _recentGamesFuture;
bool isLoading = true; bool isLoading = true;
late final List<Game> skeletonData = List.filled(
2,
Game(
name: 'Skeleton Game',
group: Group(
name: 'Skeleton Group',
members: [
Player(name: 'Skeleton Player 1'),
Player(name: 'Skeleton Player 2'),
],
),
winner: Player(name: 'Skeleton Player 1'),
),
);
@override @override
initState() { initState() {
super.initState(); super.initState();
final db = Provider.of<AppDatabase>(context, listen: false); final db = Provider.of<AppDatabase>(context, listen: false);
_gameCountFuture = db.gameDao.getGameCount(); _gameCountFuture = db.gameDao.getGameCount();
_groupCountFuture = db.groupDao.getGroupCount(); _groupCountFuture = db.groupDao.getGroupCount();
_recentGamesFuture = db.gameDao.getAllGames();
Future.wait([_gameCountFuture, _groupCountFuture]).then((_) async { Future.wait([_gameCountFuture, _groupCountFuture, _recentGamesFuture]).then(
await Future.delayed(const Duration(milliseconds: 250)); (_) async {
if (mounted) { await Future.delayed(const Duration(milliseconds: 250));
setState(() { if (mounted) {
isLoading = false; setState(() {
}); isLoading = false;
} });
}); }
},
);
} }
@override @override
@@ -48,12 +70,21 @@ class _HomeViewState extends State<HomeView> {
), ),
enabled: isLoading, enabled: isLoading,
enableSwitchAnimation: true, enableSwitchAnimation: true,
switchAnimationConfig: const SwitchAnimationConfig( switchAnimationConfig: SwitchAnimationConfig(
duration: Duration(milliseconds: 200), duration: const Duration(milliseconds: 200),
switchInCurve: Curves.linear, switchInCurve: Curves.linear,
switchOutCurve: Curves.linear, switchOutCurve: Curves.linear,
transitionBuilder: AnimatedSwitcher.defaultTransitionBuilder, transitionBuilder: AnimatedSwitcher.defaultTransitionBuilder,
layoutBuilder: AnimatedSwitcher.defaultLayoutBuilder, layoutBuilder:
(Widget? currentChild, List<Widget> previousChildren) {
return Stack(
alignment: Alignment.topCenter,
children: [
...previousChildren,
if (currentChild != null) currentChild,
],
);
},
), ),
child: SingleChildScrollView( child: SingleChildScrollView(
child: Column( child: Column(
@@ -103,32 +134,91 @@ class _HomeViewState extends State<HomeView> {
width: constraints.maxWidth * 0.95, width: constraints.maxWidth * 0.95,
title: 'Recent Games', title: 'Recent Games',
icon: Icons.timer, icon: Icons.timer,
content: const Padding( content: Padding(
padding: EdgeInsets.symmetric(horizontal: 40.0), padding: const EdgeInsets.symmetric(horizontal: 40.0),
child: Column( child: FutureBuilder(
mainAxisAlignment: MainAxisAlignment.start, future: _recentGamesFuture,
crossAxisAlignment: CrossAxisAlignment.start, builder:
children: [ (
GameTile( BuildContext context,
gameTitle: 'Gamenight', AsyncSnapshot<List<Game>> snapshot,
gameType: 'Cabo', ) {
ruleset: 'Lowest Points', if (snapshot.hasError) {
players: '5 Players', return const Center(
winner: 'Leonard', heightFactor: 4,
), child: Text(
Padding( 'Error while loading recent games.',
padding: EdgeInsets.symmetric(vertical: 8.0), ),
child: Divider(), );
), }
GameTile( if (snapshot.connectionState ==
gameTitle: 'Schoolbreak', ConnectionState.done &&
gameType: 'Uno', (!snapshot.hasData ||
ruleset: 'Highest Points', snapshot.data!.isEmpty)) {
players: 'The Gang', return const Center(
winner: 'Lina', heightFactor: 4,
), child: Text('No recent games available.'),
SizedBox(height: 8), );
], }
final List<Game> games =
(isLoading
? skeletonData
: (snapshot.data ?? [])
..sort(
(a, b) => b.createdAt.compareTo(
a.createdAt,
),
))
.take(2)
.toList();
if (games.isNotEmpty) {
return Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GameTile(
gameTitle: games[0].name,
gameType: 'Winner',
ruleset: 'Ruleset',
players: _getPlayerText(games[0]),
winner: games[0].winner == null
? 'Game in progress...'
: games[0].winner!.name,
),
const Padding(
padding: EdgeInsets.symmetric(
vertical: 8.0,
),
child: Divider(),
),
if (games.length > 1) ...[
GameTile(
gameTitle: games[1].name,
gameType: 'Winner',
ruleset: 'Ruleset',
players: _getPlayerText(games[1]),
winner: games[1].winner == null
? 'Game in progress...'
: games[1].winner!.name,
),
const SizedBox(height: 8),
] else ...[
const Center(
heightFactor: 4,
child: Text(
'No second game available.',
),
),
],
],
);
} else {
return const Center(
heightFactor: 4,
child: Text('No recent games available.'),
);
}
},
), ),
), ),
), ),
@@ -189,4 +279,15 @@ class _HomeViewState extends State<HomeView> {
}, },
); );
} }
String _getPlayerText(Game game) {
if (game.group == null) {
final playerCount = game.players?.length ?? 0;
return '$playerCount Players';
}
if (game.players == null || game.players!.isEmpty) {
return game.group!.name;
}
return '${game.group!.name} + ${game.players!.length}';
}
} }