Merge branch 'development' into bug/94-choosegroupview-zeigt-keine-group-entspricht-der-suche-obwohl-nur-gruppen-leer

This commit is contained in:
2025-12-29 18:25:30 +01:00
7 changed files with 261 additions and 352 deletions

View File

@@ -28,12 +28,6 @@ class _CreateMatchViewState extends State<CreateMatchView> {
/// Reference to the app database
late final AppDatabase db;
/// Futures to load all groups and players from the database
late Future<List<Group>> _allGroupsFuture;
/// Future to load all players from the database
late Future<List<Player>> _allPlayersFuture;
/// Controller for the game name input field
final TextEditingController _gameNameController = TextEditingController();
@@ -107,14 +101,13 @@ class _CreateMatchViewState extends State<CreateMatchView> {
db = Provider.of<AppDatabase>(context, listen: false);
_allGroupsFuture = db.groupDao.getAllGroups();
_allPlayersFuture = db.playerDao.getAllPlayers();
Future.wait([_allGroupsFuture, _allPlayersFuture]).then((result) async {
Future.wait([
db.groupDao.getAllGroups(),
db.playerDao.getAllPlayers(),
]).then((result) async {
groupsList = result[0] as List<Group>;
playerList = result[1] as List<Player>;
});
filteredPlayerList = List.from(playerList);
}

View File

@@ -2,6 +2,7 @@ import 'dart:core' hide Match;
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:game_tracker/core/constants.dart';
import 'package:game_tracker/core/custom_theme.dart';
import 'package:game_tracker/data/db/database.dart';
import 'package:game_tracker/data/dto/group.dart';
@@ -23,16 +24,16 @@ class MatchView extends StatefulWidget {
}
class _MatchViewState extends State<MatchView> {
late Future<List<Match>> _gameListFuture;
late final AppDatabase db;
bool isLoading = true;
late final List<Match> skeletonData = List.filled(
List<Match> matches = List.filled(
4,
Match(
name: 'Skeleton Gamename',
group: Group(
name: 'Groupname',
members: List.generate(5, (index) => Player(name: 'Player')),
members: List.filled(5, Player(name: 'Player')),
),
winner: Player(name: 'Player'),
players: [Player(name: 'Player')],
@@ -43,10 +44,7 @@ class _MatchViewState extends State<MatchView> {
void initState() {
super.initState();
db = Provider.of<AppDatabase>(context, listen: false);
_gameListFuture = Future.delayed(
const Duration(milliseconds: 250),
() => db.matchDao.getAllMatches(),
);
loadGames();
}
@override
@@ -56,67 +54,44 @@ class _MatchViewState extends State<MatchView> {
body: Stack(
alignment: Alignment.center,
children: [
FutureBuilder<List<Match>>(
future: _gameListFuture,
builder:
(BuildContext context, AsyncSnapshot<List<Match>> snapshot) {
if (snapshot.hasError) {
return const Center(
child: TopCenteredMessage(
icon: Icons.report,
title: 'Error',
message: 'Game data could not be loaded',
),
AppSkeleton(
enabled: isLoading,
child: Visibility(
visible: matches.isNotEmpty,
replacement: const Center(
child: TopCenteredMessage(
icon: Icons.report,
title: 'Info',
message: 'No games created yet',
),
),
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: matches.length + 1,
itemBuilder: (BuildContext context, int index) {
if (index == matches.length) {
return SizedBox(
height: MediaQuery.paddingOf(context).bottom - 80,
);
}
if (snapshot.connectionState == ConnectionState.done &&
(!snapshot.hasData || snapshot.data!.isEmpty)) {
return const Center(
child: TopCenteredMessage(
icon: Icons.report,
title: 'Info',
message: 'No games created yet',
),
);
}
final bool isLoading =
snapshot.connectionState == ConnectionState.waiting;
final List<Match> matches =
(isLoading ? skeletonData : (snapshot.data ?? [])
..sort(
(a, b) => b.createdAt.compareTo(a.createdAt),
))
.toList();
return AppSkeleton(
enabled: isLoading,
child: ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: matches.length + 1,
itemBuilder: (BuildContext context, int index) {
if (index == matches.length) {
return SizedBox(
height: MediaQuery.paddingOf(context).bottom - 20,
);
}
return GameHistoryTile(
onTap: () async {
Navigator.push(
context,
CupertinoPageRoute(
fullscreenDialog: true,
builder: (context) => GameResultView(
match: matches[index],
onWinnerChanged: refreshGameList,
),
),
);
},
match: matches[index],
);
},
),
return GameHistoryTile(
onTap: () async {
Navigator.push(
context,
CupertinoPageRoute(
fullscreenDialog: true,
builder: (context) => GameResultView(
match: matches[index],
onWinnerChanged: loadGames,
),
),
);
},
match: matches[index],
);
},
),
),
),
Positioned(
bottom: MediaQuery.paddingOf(context).bottom,
@@ -128,7 +103,7 @@ class _MatchViewState extends State<MatchView> {
context,
MaterialPageRoute(
builder: (context) =>
CreateMatchView(onWinnerChanged: refreshGameList),
CreateMatchView(onWinnerChanged: loadGames),
),
);
},
@@ -139,9 +114,19 @@ class _MatchViewState extends State<MatchView> {
);
}
void refreshGameList() {
setState(() {
_gameListFuture = db.matchDao.getAllMatches();
void loadGames() {
Future.wait([
db.matchDao.getAllMatches(),
Future.delayed(minimumSkeletonDuration),
]).then((results) {
if (mounted) {
setState(() {
final loadedMatches = results[0] as List<Match>;
matches = loadedMatches
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
isLoading = false;
});
}
});
}
}