MVP #141
@@ -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,
|
||||||
@@ -175,10 +186,12 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
: 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',
|
||||||
@@ -192,11 +205,18 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
] 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.'),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user