HomeView Mock-Daten entfernen #51
@@ -7,7 +7,6 @@ import 'package:game_tracker/presentation/widgets/buttons/quick_create_button.da
|
|||||||
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';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/quick_info_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/quick_info_tile.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:skeletonizer/skeletonizer.dart';
|
import 'package:skeletonizer/skeletonizer.dart';
|
||||||
|
|
||||||
@@ -35,8 +34,7 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
Player(name: 'Skeleton Player 2'),
|
Player(name: 'Skeleton Player 2'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
winner:
|
winner: Player(name: 'Skeleton Player 1'),
|
||||||
"Winner ID", //TODO: Should be player object, but isnt yet, waiting for pr
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -73,7 +71,7 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
enabled: isLoading,
|
enabled: isLoading,
|
||||||
enableSwitchAnimation: true,
|
enableSwitchAnimation: true,
|
||||||
switchAnimationConfig: 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,
|
||||||
@@ -130,70 +128,79 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
FutureBuilder(
|
Padding(
|
||||||
future: _recentGamesFuture,
|
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
||||||
builder: (context, snapshot) {
|
child: InfoTile(
|
||||||
if (snapshot.hasError) {
|
width: constraints.maxWidth * 0.95,
|
||||||
return const Center(
|
title: 'Recent Games',
|
||||||
child: TopCenteredMessage(
|
icon: Icons.timer,
|
||||||
icon: Icons.report,
|
content: Padding(
|
||||||
title: 'Error',
|
padding: const EdgeInsets.symmetric(horizontal: 40.0),
|
||||||
message: 'Group data couldn\'t\nbe loaded.',
|
child: FutureBuilder(
|
||||||
),
|
future: _recentGamesFuture,
|
||||||
);
|
builder: (context, snapshot) {
|
||||||
}
|
if (snapshot.hasError) {
|
||||||
if (snapshot.connectionState == ConnectionState.done &&
|
return const Center(
|
||||||
(!snapshot.hasData || snapshot.data!.isEmpty)) {
|
heightFactor: 4,
|
||||||
return const Center(
|
child: Text('Error while loading recent games.'),
|
||||||
child: TopCenteredMessage(
|
);
|
||||||
icon: Icons.info,
|
}
|
||||||
title: 'Info',
|
if (snapshot.connectionState ==
|
||||||
message: 'No games created yet.',
|
ConnectionState.done &&
|
||||||
),
|
(!snapshot.hasData || snapshot.data!.isEmpty)) {
|
||||||
);
|
return const Center(
|
||||||
}
|
heightFactor: 4,
|
||||||
final List<Game> games =
|
child: Text('No recent games available.'),
|
||||||
isLoading ? skeletonData : (snapshot.data ?? [])
|
);
|
||||||
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
}
|
||||||
return Padding(
|
final List<Game> games =
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16.0),
|
(isLoading ? skeletonData : (snapshot.data ?? [])
|
||||||
child: InfoTile(
|
..sort(
|
||||||
width: constraints.maxWidth * 0.95,
|
(a, b) =>
|
||||||
title: 'Recent Games',
|
b.createdAt.compareTo(a.createdAt),
|
||||||
icon: Icons.timer,
|
))
|
||||||
content: Padding(
|
.take(2)
|
||||||
padding: EdgeInsets.symmetric(horizontal: 40.0),
|
.toList();
|
||||||
child: Column(
|
return Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
GameTile(
|
GameTile(
|
||||||
gameTitle: games[0].name,
|
gameTitle: games[0].name,
|
||||||
gameType: "Gametype",
|
gameType: 'Winner',
|
||||||
ruleset: 'Ruleset',
|
ruleset: 'Ruleset',
|
||||||
players: _getPlayerText(games[0]),
|
players: _getPlayerText(games[0]),
|
||||||
winner:
|
winner: games[0].winner == null
|
||||||
'Leonard', //TODO: Replace Winner with real Winner
|
? 'No winner set.'
|
||||||
|
: games[0].winner!.name,
|
||||||
),
|
),
|
||||||
Padding(
|
const Padding(
|
||||||
padding: EdgeInsets.symmetric(vertical: 8.0),
|
padding: EdgeInsets.symmetric(vertical: 8.0),
|
||||||
child: Divider(),
|
child: Divider(),
|
||||||
),
|
),
|
||||||
GameTile(
|
if (games.length >= 2) ...[
|
||||||
gameTitle: games[1].name,
|
GameTile(
|
||||||
gameType: 'Gametype',
|
gameTitle: games[1].name,
|
||||||
ruleset: 'Ruleset',
|
gameType: 'Winner',
|
||||||
players: _getPlayerText(games[1]),
|
ruleset: 'Ruleset',
|
||||||
winner:
|
players: _getPlayerText(games[1]),
|
||||||
'Lina', //TODO: Replace Winner with real Winner
|
winner: games[1].winner == null
|
||||||
),
|
? 'No winner set.'
|
||||||
SizedBox(height: 8),
|
: games[1].winner!.name,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
] else ...[
|
||||||
|
const Center(
|
||||||
|
heightFactor: 4,
|
||||||
|
child: Text('No second game available.'),
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
),
|
);
|
||||||
),
|
},
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
),
|
||||||
),
|
),
|
||||||
InfoTile(
|
InfoTile(
|
||||||
width: constraints.maxWidth * 0.95,
|
width: constraints.maxWidth * 0.95,
|
||||||
@@ -254,7 +261,8 @@ class _HomeViewState extends State<HomeView> {
|
|||||||
|
|
||||||
String _getPlayerText(Game game) {
|
String _getPlayerText(Game game) {
|
||||||
if (game.group == null) {
|
if (game.group == null) {
|
||||||
return game.players?.map((p) => p.name).join(', ') ?? 'No Players';
|
final playerCount = game.players?.length ?? 0;
|
||||||
|
return '$playerCount Player(s)';
|
||||||
}
|
}
|
||||||
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