HomeView Mock-Daten entfernen #51
@@ -138,66 +138,86 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
padding: const EdgeInsets.symmetric(horizontal: 40.0),
|
padding: const EdgeInsets.symmetric(horizontal: 40.0),
|
||||||
child: FutureBuilder(
|
child: FutureBuilder(
|
||||||
future: _recentGamesFuture,
|
future: _recentGamesFuture,
|
||||||
builder: (context, snapshot) {
|
builder:
|
||||||
if (snapshot.hasError) {
|
(
|
||||||
return const Center(
|
BuildContext context,
|
||||||
heightFactor: 4,
|
AsyncSnapshot<List<Game>> snapshot,
|
||||||
child: Text('Error while loading recent games.'),
|
) {
|
||||||
);
|
if (snapshot.hasError) {
|
||||||
}
|
return const Center(
|
||||||
if (snapshot.connectionState ==
|
|
||||||
ConnectionState.done &&
|
|
||||||
(!snapshot.hasData || snapshot.data!.isEmpty)) {
|
|
||||||
return const Center(
|
|
||||||
heightFactor: 4,
|
|
||||||
child: Text('No recent games available.'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
final List<Game> games =
|
|
||||||
(isLoading ? skeletonData : (snapshot.data ?? [])
|
|
||||||
..sort(
|
|
||||||
(a, b) =>
|
|
||||||
b.createdAt.compareTo(a.createdAt),
|
|
||||||
))
|
|
||||||
.take(2)
|
|
||||||
.toList();
|
|
||||||
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 >= 2) ...[
|
|
||||||
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,
|
heightFactor: 4,
|
||||||
child: Text('No second game available.'),
|
child: Text(
|
||||||
),
|
'Error while loading recent games.',
|
||||||
],
|
),
|
||||||
],
|
);
|
||||||
);
|
}
|
||||||
},
|
if (snapshot.connectionState ==
|
||||||
|
ConnectionState.done &&
|
||||||
|
(!snapshot.hasData ||
|
||||||
|
sneeex marked this conversation as resolved
Outdated
|
|||||||
|
snapshot.data!.isEmpty)) {
|
||||||
|
return const Center(
|
||||||
|
heightFactor: 4,
|
||||||
|
child: Text('No recent games available.'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final List<Game> games =
|
||||||
|
(isLoading
|
||||||
|
? skeletonData
|
||||||
|
: (snapshot.data ?? [])
|
||||||
|
..sort(
|
||||||
|
(a, b) => b.createdAt.compareTo(
|
||||||
|
a.createdAt,
|
||||||
|
),
|
||||||
|
))
|
||||||
|
.take(2)
|
||||||
|
.toList();
|
||||||
|
if (games.length > 0)
|
||||||
|
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(
|
||||||
|
sneeex marked this conversation as resolved
Outdated
flixcoo
commented
Lieber sowas wie Lieber sowas wie `Game in Progress` oder so
|
|||||||
|
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.'),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user
Fehler taucht auf, wenn man die App startet. Könnte an dieser Zeile liegen. Ggf. die Skeleton Daten in der gleichen Variable wie die reelen Daten speichern und dann überhscreiben, wenn diese geladen sind