7 Commits

4 changed files with 315 additions and 173 deletions

View File

@@ -1,6 +1,7 @@
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/db/database.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/widgets/full_width_button.dart'; import 'package:game_tracker/presentation/widgets/full_width_button.dart';
import 'package:game_tracker/presentation/widgets/top_centered_message.dart'; import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
@@ -15,24 +16,30 @@ class CreateGroupView extends StatefulWidget {
} }
class _CreateGroupViewState extends State<CreateGroupView> { class _CreateGroupViewState extends State<CreateGroupView> {
List<Player> selectedPlayers = [ List<Player> selectedPlayers = [];
Player(id: '0', name: 'Player 0'), List<Player> suggestedPlayers = [];
Player(id: '0', name: 'Player 0'), List<Player> allPlayers = [];
Player(id: '0', name: 'Player 0'), late final AppDatabase db;
Player(id: '0', name: 'Player 0'),
];
late Future<List<Player>> _allPlayersFuture; late Future<List<Player>> _allPlayersFuture;
late final List<Player> skeletonData = List.filled( late final List<Player> skeletonData = List.filled(
7, 7,
Player(id: '0', name: 'Player 0'), Player(id: '0', name: 'Player 0'),
); );
final _groupNameController = TextEditingController();
final _searchBarController = TextEditingController();
@override @override
@override @override
void initState() { void initState() {
super.initState(); super.initState();
final db = Provider.of<AppDatabase>(context, listen: false); db = Provider.of<AppDatabase>(context, listen: false);
_allPlayersFuture = db.playerDao.getAllPlayers(); _allPlayersFuture = db.playerDao.getAllPlayers();
_allPlayersFuture.then((loadedPlayers) {
setState(() {
allPlayers = loadedPlayers;
suggestedPlayers = loadedPlayers;
});
});
} }
@override @override
@@ -55,6 +62,10 @@ class _CreateGroupViewState extends State<CreateGroupView> {
Container( Container(
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10), margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
child: TextField( child: TextField(
controller: _groupNameController,
onChanged: (value) {
setState(() {});
},
decoration: InputDecoration( decoration: InputDecoration(
filled: true, filled: true,
fillColor: CustomTheme.boxColor, fillColor: CustomTheme.boxColor,
@@ -90,6 +101,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SearchBar( SearchBar(
controller: _searchBarController,
constraints: BoxConstraints(maxHeight: 45, minHeight: 45), constraints: BoxConstraints(maxHeight: 45, minHeight: 45),
hintText: "Search for players", hintText: "Search for players",
hintStyle: WidgetStateProperty.all( hintStyle: WidgetStateProperty.all(
@@ -107,10 +119,23 @@ class _CreateGroupViewState extends State<CreateGroupView> {
borderRadius: BorderRadius.circular(12), borderRadius: BorderRadius.circular(12),
), ),
), ),
onChanged: (value) {
setState(() {
if (value.isEmpty) {
suggestedPlayers = allPlayers;
} else {
suggestedPlayers = allPlayers.where((player) {
return player.name.toLowerCase().contains(
value.toLowerCase(),
);
}).toList();
}
});
},
), ),
SizedBox(height: 10), SizedBox(height: 10),
Text( Text(
"Ausgewählte Spieler: (X)", "Ausgewählte Spieler: (${selectedPlayers.length})",
style: TextStyle( style: TextStyle(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
@@ -123,7 +148,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
spacing: 8.0, spacing: 8.0,
runSpacing: 8.0, runSpacing: 8.0,
children: <Widget>[ children: <Widget>[
for (var player in selectedPlayers) for (var selectedPlayer in selectedPlayers)
Container( Container(
padding: EdgeInsets.all(5), padding: EdgeInsets.all(5),
decoration: BoxDecoration( decoration: BoxDecoration(
@@ -136,7 +161,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
children: [ children: [
SizedBox(width: 12), SizedBox(width: 12),
Text( Text(
player.name, selectedPlayer.name,
style: const TextStyle( style: const TextStyle(
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
@@ -147,7 +172,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
child: const Icon(Icons.close, size: 20), child: const Icon(Icons.close, size: 20),
onTap: () { onTap: () {
setState(() { setState(() {
selectedPlayers.remove(player); selectedPlayers.remove(selectedPlayer);
}); });
}, },
), ),
@@ -183,7 +208,10 @@ class _CreateGroupViewState extends State<CreateGroupView> {
} }
if (snapshot.connectionState == if (snapshot.connectionState ==
ConnectionState.done && ConnectionState.done &&
(!snapshot.hasData || snapshot.data!.isEmpty)) { (!snapshot.hasData ||
snapshot.data!.isEmpty ||
(suggestedPlayers.isEmpty &&
allPlayers.isEmpty))) {
return const Center( return const Center(
child: TopCenteredMessage( child: TopCenteredMessage(
icon: Icons.info, icon: Icons.info,
@@ -195,9 +223,6 @@ class _CreateGroupViewState extends State<CreateGroupView> {
final bool isLoading = final bool isLoading =
snapshot.connectionState == snapshot.connectionState ==
ConnectionState.waiting; ConnectionState.waiting;
final List<Player> players = isLoading
? skeletonData
: (snapshot.data ?? []);
return Expanded( return Expanded(
child: Skeletonizer( child: Skeletonizer(
effect: PulseEffect( effect: PulseEffect(
@@ -217,48 +242,69 @@ class _CreateGroupViewState extends State<CreateGroupView> {
layoutBuilder: layoutBuilder:
AnimatedSwitcher.defaultLayoutBuilder, AnimatedSwitcher.defaultLayoutBuilder,
), ),
child: ListView.builder( child:
itemCount: players.length, (suggestedPlayers.isEmpty &&
itemBuilder: !allPlayers.isEmpty)
(BuildContext context, int index) { ? TopCenteredMessage(
return Container( icon: Icons.info,
margin: const EdgeInsets.symmetric( title: 'Info',
horizontal: 5, message:
vertical: 5, 'No players found with that name.',
), )
padding: const EdgeInsets.symmetric( : ListView.builder(
horizontal: 10, itemCount: suggestedPlayers.length,
), itemBuilder: (BuildContext context, int index) {
decoration: BoxDecoration( return Container(
color: CustomTheme.boxColor, margin: const EdgeInsets.symmetric(
border: Border.all( horizontal: 5,
color: CustomTheme.boxBorder, vertical: 5,
), ),
borderRadius: BorderRadius.circular( padding: const EdgeInsets.symmetric(
12, horizontal: 10,
), ),
), decoration: BoxDecoration(
child: Row( color: CustomTheme.boxColor,
mainAxisAlignment: border: Border.all(
MainAxisAlignment.spaceBetween, color: CustomTheme.boxBorder,
mainAxisSize: MainAxisSize.max, ),
children: [ borderRadius:
Text( BorderRadius.circular(12),
players[index].name, ),
style: TextStyle( child: Row(
fontSize: 16, mainAxisAlignment:
fontWeight: FontWeight.w500, MainAxisAlignment
.spaceBetween,
mainAxisSize: MainAxisSize.max,
children: [
Text(
suggestedPlayers[index].name,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
),
), ),
), IconButton(
IconButton( icon: Icon(
icon: Icon(Icons.add, size: 20), Icons.add,
onPressed: () {}, size: 20,
), ),
], onPressed: () {
), setState(() {
); //GroupTile(group: groups[index]); if (!selectedPlayers.contains(
}, suggestedPlayers[index],
), )) {
selectedPlayers.add(
suggestedPlayers[index],
);
}
});
},
),
],
),
);
},
),
), ),
); );
}, },
@@ -271,14 +317,39 @@ class _CreateGroupViewState extends State<CreateGroupView> {
text: "Create group", text: "Create group",
infillColor: CustomTheme.primaryColor, infillColor: CustomTheme.primaryColor,
borderColor: CustomTheme.primaryColor, borderColor: CustomTheme.primaryColor,
disabledInfillColor: CustomTheme.boxColor,
sizeRelativeToWidth: 0.95, sizeRelativeToWidth: 0.95,
onPressed: () {}, onPressed:
(_groupNameController.text.isEmpty || selectedPlayers.isEmpty)
? null
: () {
String id = "ID_" + _groupNameController.text;
String name = _groupNameController.text;
List<Player> members = selectedPlayers;
db.groupDao.addGroup(
group: Group(id: id, name: name, members: members),
);
print(name);
print(id);
for (int i = 0; i < members.length; i++) {
print(members[i].name);
print(members[i].id);
}
if (true) {
//eigentlich wenn create group erfolgreich
_groupNameController.clear();
_searchBarController.clear();
selectedPlayers.clear();
}
setState(() {});
},
), ),
SizedBox(height: 10), SizedBox(height: 10),
FullWidthButton( FullWidthButton(
text: "Cancel", text: "Cancel",
infillColor: CustomTheme.boxColor, infillColor: CustomTheme.boxColor,
borderColor: CustomTheme.primaryColor, borderColor: CustomTheme.primaryColor,
disabledInfillColor: CustomTheme.boxColor,
sizeRelativeToWidth: 0.95, sizeRelativeToWidth: 0.95,
onPressed: () { onPressed: () {
Navigator.pop(context); Navigator.pop(context);
@@ -293,6 +364,22 @@ class _CreateGroupViewState extends State<CreateGroupView> {
Future<void> addSamplePlayers(BuildContext context) async { Future<void> addSamplePlayers(BuildContext context) async {
final db = Provider.of<AppDatabase>(context, listen: false); final db = Provider.of<AppDatabase>(context, listen: false);
/*await db.groupDao.addGroup(
group: Group(
id: "dg1",
name: "Debug Gruppe 1",
members: [
Player(id: '1', name: 'Spieler 1'),
Player(id: '2', name: 'Spieler 2'),
Player(id: '3', name: 'Spieler 3'),
],
),
);
final group = await db.groupDao.getGroupById(groupId: "dg1");
print(group.name);
print(group.id);
print(group.members.length);
*/
final playerCount = await db.playerDao.getPlayerCount(); final playerCount = await db.playerDao.getPlayerCount();
if (playerCount == 0) { if (playerCount == 0) {
for (int i = 1; i <= 10; i++) { for (int i = 1; i <= 10; i++) {

View File

@@ -5,6 +5,7 @@ import 'package:game_tracker/presentation/widgets/quick_create_button.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:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:skeletonizer/skeletonizer.dart';
class HomeView extends StatefulWidget { class HomeView extends StatefulWidget {
const HomeView({super.key}); const HomeView({super.key});
@@ -16,6 +17,7 @@ class HomeView extends StatefulWidget {
class _HomeViewState extends State<HomeView> { class _HomeViewState extends State<HomeView> {
late Future<int> _gameCountFuture; late Future<int> _gameCountFuture;
late Future<int> _groupCountFuture; late Future<int> _groupCountFuture;
bool isLoading = true;
@override @override
initState() { initState() {
@@ -23,120 +25,165 @@ class _HomeViewState extends State<HomeView> {
final db = Provider.of<AppDatabase>(context, listen: false); final db = Provider.of<AppDatabase>(context, listen: false);
_gameCountFuture = db.gameDao.getGameCount(); _gameCountFuture = db.gameDao.getGameCount();
_groupCountFuture = db.groupDao.getGroupCount(); _groupCountFuture = db.groupDao.getGroupCount();
Future.wait([_gameCountFuture, _groupCountFuture]).then((_) async {
await Future.delayed(const Duration(milliseconds: 50));
if (mounted) {
setState(() {
isLoading = false;
});
}
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return LayoutBuilder( return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) { builder: (BuildContext context, BoxConstraints constraints) {
return SingleChildScrollView( return Skeletonizer(
child: Column( effect: PulseEffect(
crossAxisAlignment: CrossAxisAlignment.center, from: Colors.grey[800]!,
children: [ to: Colors.grey[600]!,
Row( duration: const Duration(milliseconds: 800),
mainAxisAlignment: MainAxisAlignment.center, ),
children: [ enabled: isLoading,
FutureBuilder<int>( enableSwitchAnimation: true,
future: _gameCountFuture, switchAnimationConfig: const SwitchAnimationConfig(
builder: (context, snapshot) { duration: Duration(milliseconds: 200),
final int count = (snapshot.hasData) ? snapshot.data! : 0; switchInCurve: Curves.linear,
return QuickInfoTile( switchOutCurve: Curves.linear,
width: constraints.maxWidth * 0.45, transitionBuilder: AnimatedSwitcher.defaultTransitionBuilder,
height: constraints.maxHeight * 0.15, layoutBuilder: AnimatedSwitcher.defaultLayoutBuilder,
title: 'Games', ),
icon: Icons.groups_rounded, child: SingleChildScrollView(
value: count, child: Column(
); crossAxisAlignment: CrossAxisAlignment.center,
}, children: [
), Row(
SizedBox(width: constraints.maxWidth * 0.05), mainAxisAlignment: MainAxisAlignment.center,
FutureBuilder<int>(
future: _groupCountFuture,
builder: (context, snapshot) {
final int count =
(snapshot.connectionState == ConnectionState.done &&
snapshot.hasData)
? snapshot.data!
: 0;
return QuickInfoTile(
width: constraints.maxWidth * 0.45,
height: constraints.maxHeight * 0.15,
title: 'Groups',
icon: Icons.groups_rounded,
value: count,
);
},
),
],
),
Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: InfoTile(
width: constraints.maxWidth * 0.95,
title: 'Recent Games',
icon: Icons.timer,
content: const Padding(
padding: EdgeInsets.symmetric(horizontal: 40.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GameTile(
gameTitle: 'Gamenight',
gameType: 'Cabo',
ruleset: 'Lowest Points',
players: '5 Players',
winner: 'Leonard',
),
Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Divider(),
),
GameTile(
gameTitle: 'Schoolbreak',
gameType: 'Uno',
ruleset: 'Highest Points',
players: 'The Gang',
winner: 'Lina',
),
SizedBox(height: 8),
],
),
),
),
),
InfoTile(
width: constraints.maxWidth * 0.95,
title: 'Quick Create',
icon: Icons.add_box_rounded,
content: Column(
spacing: 8,
children: [ children: [
Row( FutureBuilder<int>(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, future: _gameCountFuture,
children: [ builder: (context, snapshot) {
QuickCreateButton(text: 'Category 1', onPressed: () {}), final int count = (snapshot.hasData)
QuickCreateButton(text: 'Category 2', onPressed: () {}), ? snapshot.data!
], : 0;
return QuickInfoTile(
width: constraints.maxWidth * 0.45,
height: constraints.maxHeight * 0.15,
title: 'Games',
icon: Icons.groups_rounded,
value: count,
);
},
), ),
Row( SizedBox(width: constraints.maxWidth * 0.05),
mainAxisAlignment: MainAxisAlignment.spaceEvenly, FutureBuilder<int>(
children: [ future: _groupCountFuture,
QuickCreateButton(text: 'Category 3', onPressed: () {}), builder: (context, snapshot) {
QuickCreateButton(text: 'Category 4', onPressed: () {}), final int count =
], (snapshot.connectionState == ConnectionState.done &&
), snapshot.hasData)
Row( ? snapshot.data!
mainAxisAlignment: MainAxisAlignment.spaceEvenly, : 0;
children: [ return QuickInfoTile(
QuickCreateButton(text: 'Category 5', onPressed: () {}), width: constraints.maxWidth * 0.45,
QuickCreateButton(text: 'Category 6', onPressed: () {}), height: constraints.maxHeight * 0.15,
], title: 'Groups',
icon: Icons.groups_rounded,
value: count,
);
},
), ),
], ],
), ),
), Padding(
], padding: const EdgeInsets.symmetric(vertical: 16.0),
child: InfoTile(
width: constraints.maxWidth * 0.95,
title: 'Recent Games',
icon: Icons.timer,
content: const Padding(
padding: EdgeInsets.symmetric(horizontal: 40.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
GameTile(
gameTitle: 'Gamenight',
gameType: 'Cabo',
ruleset: 'Lowest Points',
players: '5 Players',
winner: 'Leonard',
),
Padding(
padding: EdgeInsets.symmetric(vertical: 8.0),
child: Divider(),
),
GameTile(
gameTitle: 'Schoolbreak',
gameType: 'Uno',
ruleset: 'Highest Points',
players: 'The Gang',
winner: 'Lina',
),
SizedBox(height: 8),
],
),
),
),
),
InfoTile(
width: constraints.maxWidth * 0.95,
title: 'Quick Create',
icon: Icons.add_box_rounded,
content: Column(
spacing: 8,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
QuickCreateButton(
text: 'Category 1',
onPressed: () {},
),
QuickCreateButton(
text: 'Category 2',
onPressed: () {},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
QuickCreateButton(
text: 'Category 3',
onPressed: () {},
),
QuickCreateButton(
text: 'Category 4',
onPressed: () {},
),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
QuickCreateButton(
text: 'Category 5',
onPressed: () {},
),
QuickCreateButton(
text: 'Category 6',
onPressed: () {},
),
],
),
],
),
),
],
),
), ),
); );
}, },

View File

@@ -6,6 +6,7 @@ class FullWidthButton extends StatelessWidget {
required this.text, required this.text,
required this.borderColor, required this.borderColor,
required this.infillColor, required this.infillColor,
this.disabledInfillColor,
required this.sizeRelativeToWidth, required this.sizeRelativeToWidth,
required this.onPressed, required this.onPressed,
}); });
@@ -13,6 +14,7 @@ class FullWidthButton extends StatelessWidget {
final String text; final String text;
final Color borderColor; final Color borderColor;
final Color infillColor; final Color infillColor;
final Color? disabledInfillColor;
final double sizeRelativeToWidth; final double sizeRelativeToWidth;
final VoidCallback? onPressed; final VoidCallback? onPressed;
@@ -21,6 +23,7 @@ class FullWidthButton extends StatelessWidget {
return ElevatedButton( return ElevatedButton(
onPressed: onPressed, onPressed: onPressed,
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
disabledBackgroundColor: disabledInfillColor,
minimumSize: Size( minimumSize: Size(
MediaQuery.sizeOf(context).width * sizeRelativeToWidth, MediaQuery.sizeOf(context).width * sizeRelativeToWidth,
60, 60,

View File

@@ -1,5 +1,6 @@
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:skeletonizer/skeletonizer.dart';
class GameTile extends StatefulWidget { class GameTile extends StatefulWidget {
final String gameTitle; final String gameTitle;
@@ -48,9 +49,11 @@ class _GameTileState extends State<GameTile> {
borderRadius: BorderRadius.circular(4), borderRadius: BorderRadius.circular(4),
color: CustomTheme.primaryColor, color: CustomTheme.primaryColor,
), ),
child: Text( child: Skeleton.ignore(
widget.ruleset, child: Text(
style: const TextStyle(fontWeight: FontWeight.bold), widget.ruleset,
style: const TextStyle(fontWeight: FontWeight.bold),
),
), ),
), ),
Center( Center(
@@ -68,19 +71,21 @@ class _GameTileState extends State<GameTile> {
borderRadius: BorderRadius.circular(4), borderRadius: BorderRadius.circular(4),
color: Colors.yellow.shade300, color: Colors.yellow.shade300,
), ),
child: Row( child: Skeleton.ignore(
mainAxisAlignment: MainAxisAlignment.center, child: Row(
children: [ mainAxisAlignment: MainAxisAlignment.center,
const Icon(Icons.emoji_events, color: Colors.black, size: 20), children: [
Text( const Icon(Icons.emoji_events, color: Colors.black, size: 20),
widget.winner, Text(
textAlign: TextAlign.center, widget.winner,
style: const TextStyle( textAlign: TextAlign.center,
fontWeight: FontWeight.bold, style: const TextStyle(
color: Colors.black87, fontWeight: FontWeight.bold,
color: Colors.black87,
),
), ),
), ],
], ),
), ),
), ),
), ),