Compare commits
7 Commits
dd2024e96e
...
e3ac91bf48
| Author | SHA1 | Date | |
|---|---|---|---|
| e3ac91bf48 | |||
| dba448b9c1 | |||
| d8551b3a27 | |||
| 8f2c7493d0 | |||
| f7f97fcdcb | |||
| 9ac6b6e04c | |||
| e77896c1d4 |
@@ -1,12 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
|
||||||
import 'package:game_tracker/data/dto/group.dart';
|
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
|
||||||
import 'package:game_tracker/presentation/views/main_menu/game_history_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/game_history_view.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/game_result_view.dart';
|
|
||||||
import 'package:game_tracker/presentation/views/main_menu/groups_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/groups_view.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/home_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/home_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/views/main_menu/settings_view.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/statistics_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/statistics_view.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/navbar_item.dart';
|
import 'package:game_tracker/presentation/widgets/navbar_item.dart';
|
||||||
|
|
||||||
@@ -59,26 +56,7 @@ class _CustomNavigationBarState extends State<CustomNavigationBar>
|
|||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await Navigator.push(
|
await Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(builder: (_) => const SettingsView()),
|
||||||
builder: (_) => GameResultView(
|
|
||||||
game: Game(
|
|
||||||
name: 'Test Game',
|
|
||||||
players: [
|
|
||||||
Player(name: 'Petrus'),
|
|
||||||
Player(name: 'Peter'),
|
|
||||||
Player(name: 'Petra'),
|
|
||||||
],
|
|
||||||
group: Group(
|
|
||||||
name: 'Die Petris',
|
|
||||||
members: [
|
|
||||||
Player(name: 'Petralia'),
|
|
||||||
Player(name: 'Petrenlia'),
|
|
||||||
Player(name: 'Petrumlia'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
), //TODO Replace with Settingsview
|
|
||||||
);
|
);
|
||||||
setState(() {
|
setState(() {
|
||||||
tabKeyCount++;
|
tabKeyCount++;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import 'package:game_tracker/data/dto/game.dart';
|
|||||||
import 'package:game_tracker/data/dto/group.dart';
|
import 'package:game_tracker/data/dto/group.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
import 'package:game_tracker/presentation/views/main_menu/create_group_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/create_group_view.dart';
|
||||||
|
import 'package:game_tracker/presentation/views/main_menu/game_result_view.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
import 'package:game_tracker/presentation/widgets/app_skeleton.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/game_history_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/game_history_tile.dart';
|
||||||
@@ -21,7 +22,6 @@ class GameHistoryView extends StatefulWidget {
|
|||||||
class _GameHistoryViewState extends State<GameHistoryView> {
|
class _GameHistoryViewState extends State<GameHistoryView> {
|
||||||
late Future<List<Game>> _gameListFuture;
|
late Future<List<Game>> _gameListFuture;
|
||||||
late final AppDatabase db;
|
late final AppDatabase db;
|
||||||
late bool isLoading = true;
|
|
||||||
|
|
||||||
late final List<Game> skeletonData = List.filled(
|
late final List<Game> skeletonData = List.filled(
|
||||||
4,
|
4,
|
||||||
@@ -50,9 +50,6 @@ class _GameHistoryViewState extends State<GameHistoryView> {
|
|||||||
|
|
||||||
Future.wait([_gameListFuture]).then((result) async {
|
Future.wait([_gameListFuture]).then((result) async {
|
||||||
await Future.delayed(const Duration(milliseconds: 250));
|
await Future.delayed(const Duration(milliseconds: 250));
|
||||||
setState(() {
|
|
||||||
isLoading = false;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,14 +83,14 @@ class _GameHistoryViewState extends State<GameHistoryView> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
final bool isLoading =
|
||||||
|
snapshot.connectionState == ConnectionState.waiting;
|
||||||
final List<Game> games =
|
final List<Game> games =
|
||||||
(isLoading ? skeletonData : (snapshot.data ?? [])
|
(isLoading ? skeletonData : (snapshot.data ?? [])
|
||||||
..sort(
|
..sort(
|
||||||
(a, b) => b.createdAt.compareTo(a.createdAt),
|
(a, b) => b.createdAt.compareTo(a.createdAt),
|
||||||
))
|
))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return AppSkeleton(
|
return AppSkeleton(
|
||||||
enabled: isLoading,
|
enabled: isLoading,
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
@@ -106,8 +103,20 @@ class _GameHistoryViewState extends State<GameHistoryView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
return GameHistoryTile(
|
return GameHistoryTile(
|
||||||
|
onTap: () async {
|
||||||
|
await Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (context) =>
|
||||||
|
GameResultView(game: games[index]),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
_gameListFuture = db.gameDao.getAllGames();
|
||||||
|
});
|
||||||
|
},
|
||||||
game: games[index],
|
game: games[index],
|
||||||
); // Placeholder
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
import 'package:game_tracker/core/custom_theme.dart';
|
||||||
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
import 'package:game_tracker/data/dto/game.dart';
|
import 'package:game_tracker/data/dto/game.dart';
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
import 'package:game_tracker/data/dto/player.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/custom_radio_list_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/custom_radio_list_tile.dart';
|
||||||
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class GameResultView extends StatefulWidget {
|
class GameResultView extends StatefulWidget {
|
||||||
final Game game;
|
final Game game;
|
||||||
@@ -17,11 +19,16 @@ class GameResultView extends StatefulWidget {
|
|||||||
|
|
||||||
class _GameResultViewState extends State<GameResultView> {
|
class _GameResultViewState extends State<GameResultView> {
|
||||||
late final List<Player> allPlayers;
|
late final List<Player> allPlayers;
|
||||||
Player? _player; //TODO: Set last winner as selected
|
late final AppDatabase db;
|
||||||
|
Player? _player;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
allPlayers = getAllPlayers(widget.game);
|
allPlayers = getAllPlayers(widget.game);
|
||||||
|
if (widget.game.winner != null) {
|
||||||
|
_player = allPlayers.firstWhere((p) => p.id == widget.game.winner!.id);
|
||||||
|
}
|
||||||
super.initState();
|
super.initState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,11 +119,29 @@ class _GameResultViewState extends State<GameResultView> {
|
|||||||
text: 'Save',
|
text: 'Save',
|
||||||
sizeRelativeToWidth: 0.95,
|
sizeRelativeToWidth: 0.95,
|
||||||
onPressed: _player != null
|
onPressed: _player != null
|
||||||
? () {
|
? () async {
|
||||||
print(
|
print('Selected Winner: ${_player!.name}');
|
||||||
'Selected Winner: ${_player!.name}',
|
bool success = await db.gameDao.setWinner(
|
||||||
); //TODO: Add winner to db
|
gameId: widget.game.id,
|
||||||
Navigator.pop(context);
|
winnerId: _player!.id,
|
||||||
|
);
|
||||||
|
if (!context.mounted) return;
|
||||||
|
if (success) {
|
||||||
|
Navigator.pop(context);
|
||||||
|
} else {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
backgroundColor: CustomTheme.boxColor,
|
||||||
|
content: const Center(
|
||||||
|
child: Text(
|
||||||
|
'Error while setting winner, please try again',
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
setState(() {});
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -6,142 +6,132 @@ import 'package:intl/intl.dart';
|
|||||||
|
|
||||||
class GameHistoryTile extends StatefulWidget {
|
class GameHistoryTile extends StatefulWidget {
|
||||||
final Game game;
|
final Game game;
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
const GameHistoryTile({
|
const GameHistoryTile({super.key, required this.game, required this.onTap});
|
||||||
super.key,
|
|
||||||
required this.game,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<GameHistoryTile> createState() => _GameHistoryTileState();
|
State<GameHistoryTile> createState() => _GameHistoryTileState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _GameHistoryTileState extends State<GameHistoryTile> {
|
class _GameHistoryTileState extends State<GameHistoryTile> {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final group = widget.game.group;
|
final group = widget.game.group;
|
||||||
final winner = widget.game.winner;
|
final winner = widget.game.winner;
|
||||||
final allPlayers = _getAllPlayers();
|
final allPlayers = _getAllPlayers();
|
||||||
|
|
||||||
return Container(
|
return GestureDetector(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
onTap: widget.onTap,
|
||||||
padding: const EdgeInsets.all(16),
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
||||||
color: CustomTheme.boxColor,
|
padding: const EdgeInsets.all(16),
|
||||||
border: Border.all(color: CustomTheme.boxBorder),
|
decoration: BoxDecoration(
|
||||||
borderRadius: BorderRadius.circular(12),
|
color: CustomTheme.boxColor,
|
||||||
),
|
border: Border.all(color: CustomTheme.boxBorder),
|
||||||
child: Column(
|
borderRadius: BorderRadius.circular(12),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
),
|
||||||
children: [
|
child: Column(
|
||||||
Row(
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
children: [
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: Text(
|
|
||||||
widget.game.name,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Text(
|
|
||||||
_formatDate(widget.game.createdAt),
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 12,
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
|
|
||||||
if (group != null) ...[
|
|
||||||
Row(
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
const Icon(
|
|
||||||
Icons.group,
|
|
||||||
size: 16,
|
|
||||||
color: Colors.grey,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
group.name,
|
widget.game.name,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 18,
|
||||||
color: Colors.grey,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Text(
|
||||||
|
_formatDate(widget.game.createdAt),
|
||||||
|
style: const TextStyle(fontSize: 12, color: Colors.grey),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
|
||||||
],
|
|
||||||
|
|
||||||
if (winner != null) ...[
|
const SizedBox(height: 8),
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 12),
|
if (group != null) ...[
|
||||||
decoration: BoxDecoration(
|
Row(
|
||||||
color: Colors.green.withValues(alpha: 0.1),
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
border: Border.all(
|
|
||||||
color: Colors.green.withValues(alpha: 0.3),
|
|
||||||
width: 1,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
children: [
|
||||||
const Icon(
|
const Icon(Icons.group, size: 16, color: Colors.grey),
|
||||||
Icons.emoji_events,
|
const SizedBox(width: 6),
|
||||||
size: 20,
|
|
||||||
color: Colors.amber,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
'Winner: ${winner.name}',
|
group.name,
|
||||||
style: const TextStyle(
|
style: const TextStyle(fontSize: 14, color: Colors.grey),
|
||||||
fontSize: 14,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
color: Colors.white,
|
|
||||||
),
|
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 12),
|
||||||
const SizedBox(height: 12),
|
],
|
||||||
],
|
|
||||||
|
|
||||||
if (allPlayers.isNotEmpty) ...[
|
if (winner != null) ...[
|
||||||
const Text(
|
Container(
|
||||||
'Players',
|
padding: const EdgeInsets.symmetric(
|
||||||
style: TextStyle(
|
vertical: 8,
|
||||||
fontSize: 13,
|
horizontal: 12,
|
||||||
color: Colors.grey,
|
),
|
||||||
fontWeight: FontWeight.w500,
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.green.withValues(alpha: 0.1),
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
border: Border.all(
|
||||||
|
color: Colors.green.withValues(alpha: 0.3),
|
||||||
|
width: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.emoji_events,
|
||||||
|
size: 20,
|
||||||
|
color: Colors.amber,
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
'Winner: ${winner.name}',
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 12),
|
||||||
const SizedBox(height: 6),
|
],
|
||||||
Wrap(
|
|
||||||
spacing: 6,
|
if (allPlayers.isNotEmpty) ...[
|
||||||
runSpacing: 6,
|
const Text(
|
||||||
children: allPlayers.map((player) {
|
'Players',
|
||||||
return TextIconTile(
|
style: TextStyle(
|
||||||
text: player.name,
|
fontSize: 13,
|
||||||
iconEnabled: false,
|
color: Colors.grey,
|
||||||
);
|
fontWeight: FontWeight.w500,
|
||||||
}).toList(),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 6),
|
||||||
|
Wrap(
|
||||||
|
spacing: 6,
|
||||||
|
runSpacing: 6,
|
||||||
|
children: allPlayers.map((player) {
|
||||||
|
return TextIconTile(text: player.name, iconEnabled: false);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -187,5 +177,4 @@ class _GameHistoryTileState extends State<GameHistoryTile> {
|
|||||||
|
|
||||||
return allPlayers;
|
return allPlayers;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user