Compare commits
2 Commits
def37aa640
...
2616f7c113
| Author | SHA1 | Date | |
|---|---|---|---|
| 2616f7c113 | |||
| 963edaf1d1 |
@@ -138,29 +138,40 @@ 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:
|
||||||
|
(
|
||||||
|
BuildContext context,
|
||||||
|
AsyncSnapshot<List<Game>> snapshot,
|
||||||
|
) {
|
||||||
if (snapshot.hasError) {
|
if (snapshot.hasError) {
|
||||||
return const Center(
|
return const Center(
|
||||||
heightFactor: 4,
|
heightFactor: 4,
|
||||||
child: Text('Error while loading recent games.'),
|
child: Text(
|
||||||
|
'Error while loading recent games.',
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (snapshot.connectionState ==
|
if (snapshot.connectionState ==
|
||||||
ConnectionState.done &&
|
ConnectionState.done &&
|
||||||
(!snapshot.hasData || snapshot.data!.isEmpty)) {
|
(!snapshot.hasData ||
|
||||||
|
snapshot.data!.isEmpty)) {
|
||||||
return const Center(
|
return const Center(
|
||||||
heightFactor: 4,
|
heightFactor: 4,
|
||||||
child: Text('No recent games available.'),
|
child: Text('No recent games available.'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
final List<Game> games =
|
final List<Game> games =
|
||||||
(isLoading ? skeletonData : (snapshot.data ?? [])
|
(isLoading
|
||||||
|
? skeletonData
|
||||||
|
: (snapshot.data ?? [])
|
||||||
..sort(
|
..sort(
|
||||||
(a, b) =>
|
(a, b) => b.createdAt.compareTo(
|
||||||
b.createdAt.compareTo(a.createdAt),
|
a.createdAt,
|
||||||
|
),
|
||||||
))
|
))
|
||||||
.take(2)
|
.take(2)
|
||||||
.toList();
|
.toList();
|
||||||
|
if (games.length > 0)
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@@ -171,32 +182,41 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
ruleset: 'Ruleset',
|
ruleset: 'Ruleset',
|
||||||
players: _getPlayerText(games[0]),
|
players: _getPlayerText(games[0]),
|
||||||
winner: games[0].winner == null
|
winner: games[0].winner == null
|
||||||
? 'No winner set.'
|
? 'Game in progress...'
|
||||||
: games[0].winner!.name,
|
: games[0].winner!.name,
|
||||||
),
|
),
|
||||||
const Padding(
|
const Padding(
|
||||||
padding: EdgeInsets.symmetric(vertical: 8.0),
|
padding: EdgeInsets.symmetric(
|
||||||
|
vertical: 8.0,
|
||||||
|
),
|
||||||
child: Divider(),
|
child: Divider(),
|
||||||
),
|
),
|
||||||
if (games.length >= 2) ...[
|
if (games.length > 1) ...[
|
||||||
GameTile(
|
GameTile(
|
||||||
gameTitle: games[1].name,
|
gameTitle: games[1].name,
|
||||||
gameType: 'Winner',
|
gameType: 'Winner',
|
||||||
ruleset: 'Ruleset',
|
ruleset: 'Ruleset',
|
||||||
players: _getPlayerText(games[1]),
|
players: _getPlayerText(games[1]),
|
||||||
winner: games[1].winner == null
|
winner: games[1].winner == null
|
||||||
? 'No winner set.'
|
? 'Game in progress...'
|
||||||
: games[1].winner!.name,
|
: games[1].winner!.name,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
] else ...[
|
] else ...[
|
||||||
const Center(
|
const Center(
|
||||||
heightFactor: 4,
|
heightFactor: 4,
|
||||||
child: Text('No second game available.'),
|
child: Text(
|
||||||
|
'No second game available.',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
else
|
||||||
|
return const Center(
|
||||||
|
heightFactor: 4,
|
||||||
|
child: Text('No recent games available.'),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -262,7 +282,7 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
String _getPlayerText(Game game) {
|
String _getPlayerText(Game game) {
|
||||||
if (game.group == null) {
|
if (game.group == null) {
|
||||||
final playerCount = game.players?.length ?? 0;
|
final playerCount = game.players?.length ?? 0;
|
||||||
return '$playerCount Player(s)';
|
return '$playerCount Players';
|
||||||
}
|
}
|
||||||
if (game.players == null || game.players!.isEmpty) {
|
if (game.players == null || game.players!.isEmpty) {
|
||||||
return game.group!.name;
|
return game.group!.name;
|
||||||
|
|||||||
Reference in New Issue
Block a user