Merge branch 'development' into feature/2-gamehistoryview-anpassen
# Conflicts: # lib/presentation/views/main_menu/game_history_view.dart
This commit is contained in:
@@ -1,10 +1,111 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:game_tracker/core/custom_theme.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/presentation/widgets/full_width_button.dart';
|
||||
import 'package:game_tracker/presentation/widgets/tiles/group_tile.dart';
|
||||
import 'package:game_tracker/presentation/widgets/top_centered_message.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
|
||||
class GroupsView extends StatelessWidget {
|
||||
class GroupsView extends StatefulWidget {
|
||||
const GroupsView({super.key});
|
||||
|
||||
@override
|
||||
State<GroupsView> createState() => _GroupsViewState();
|
||||
}
|
||||
|
||||
class _GroupsViewState extends State<GroupsView> {
|
||||
late Future<List<Group>> _allGroupsFuture;
|
||||
|
||||
final player = Player(name: 'Skeleton Player');
|
||||
late final List<Group> skeletonData = List.filled(
|
||||
7,
|
||||
Group(
|
||||
name: 'Skeleton Game',
|
||||
members: [player, player, player, player, player, player],
|
||||
),
|
||||
);
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||
_allGroupsFuture = db.groupDao.getAllGroups();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const Center(child: Text('Groups View'));
|
||||
return Scaffold(
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
body: Stack(
|
||||
alignment: Alignment.center,
|
||||
children: [
|
||||
FutureBuilder<List<Group>>(
|
||||
future: _allGroupsFuture,
|
||||
builder:
|
||||
(BuildContext context, AsyncSnapshot<List<Group>> snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return const Center(
|
||||
child: TopCenteredMessage(
|
||||
icon: Icons.report,
|
||||
title: 'Error',
|
||||
message: 'Group data couldn\'t\nbe loaded.',
|
||||
),
|
||||
);
|
||||
}
|
||||
if (snapshot.connectionState == ConnectionState.done &&
|
||||
(!snapshot.hasData || snapshot.data!.isEmpty)) {
|
||||
return const Center(
|
||||
child: TopCenteredMessage(
|
||||
icon: Icons.info,
|
||||
title: 'Info',
|
||||
message: 'No groups created yet.',
|
||||
),
|
||||
);
|
||||
}
|
||||
final bool isLoading =
|
||||
snapshot.connectionState == ConnectionState.waiting;
|
||||
final List<Group> groups = isLoading
|
||||
? skeletonData
|
||||
: (snapshot.data ?? []);
|
||||
return Skeletonizer(
|
||||
effect: PulseEffect(
|
||||
from: Colors.grey[800]!,
|
||||
to: Colors.grey[600]!,
|
||||
duration: const Duration(milliseconds: 800),
|
||||
),
|
||||
enabled: isLoading,
|
||||
enableSwitchAnimation: true,
|
||||
switchAnimationConfig: const SwitchAnimationConfig(
|
||||
duration: Duration(milliseconds: 200),
|
||||
switchInCurve: Curves.linear,
|
||||
switchOutCurve: Curves.linear,
|
||||
transitionBuilder:
|
||||
AnimatedSwitcher.defaultTransitionBuilder,
|
||||
layoutBuilder: AnimatedSwitcher.defaultLayoutBuilder,
|
||||
),
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.only(bottom: 85),
|
||||
itemCount: groups.length + 1,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
if (index == groups.length) {
|
||||
return const SizedBox(height: 60);
|
||||
}
|
||||
return GroupTile(group: groups[index]);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
Positioned(
|
||||
bottom: 80,
|
||||
child: FullWidthButton(text: 'Create Group', onPressed: () {}),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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/quick_info_tile.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
|
||||
class HomeView extends StatefulWidget {
|
||||
const HomeView({super.key});
|
||||
@@ -16,6 +17,7 @@ class HomeView extends StatefulWidget {
|
||||
class _HomeViewState extends State<HomeView> {
|
||||
late Future<int> _gameCountFuture;
|
||||
late Future<int> _groupCountFuture;
|
||||
bool isLoading = true;
|
||||
|
||||
@override
|
||||
initState() {
|
||||
@@ -23,120 +25,165 @@ class _HomeViewState extends State<HomeView> {
|
||||
final db = Provider.of<AppDatabase>(context, listen: false);
|
||||
_gameCountFuture = db.gameDao.getGameCount();
|
||||
_groupCountFuture = db.groupDao.getGroupCount();
|
||||
|
||||
Future.wait([_gameCountFuture, _groupCountFuture]).then((_) async {
|
||||
await Future.delayed(const Duration(milliseconds: 50));
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
return SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
FutureBuilder<int>(
|
||||
future: _gameCountFuture,
|
||||
builder: (context, snapshot) {
|
||||
final int count = (snapshot.hasData) ? snapshot.data! : 0;
|
||||
return QuickInfoTile(
|
||||
width: constraints.maxWidth * 0.45,
|
||||
height: constraints.maxHeight * 0.15,
|
||||
title: 'Games',
|
||||
icon: Icons.groups_rounded,
|
||||
value: count,
|
||||
);
|
||||
},
|
||||
),
|
||||
SizedBox(width: constraints.maxWidth * 0.05),
|
||||
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,
|
||||
return Skeletonizer(
|
||||
effect: PulseEffect(
|
||||
from: Colors.grey[800]!,
|
||||
to: Colors.grey[600]!,
|
||||
duration: const Duration(milliseconds: 800),
|
||||
),
|
||||
enabled: isLoading,
|
||||
enableSwitchAnimation: true,
|
||||
switchAnimationConfig: const SwitchAnimationConfig(
|
||||
duration: Duration(milliseconds: 200),
|
||||
switchInCurve: Curves.linear,
|
||||
switchOutCurve: Curves.linear,
|
||||
transitionBuilder: AnimatedSwitcher.defaultTransitionBuilder,
|
||||
layoutBuilder: AnimatedSwitcher.defaultLayoutBuilder,
|
||||
),
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
QuickCreateButton(text: 'Category 1', onPressed: () {}),
|
||||
QuickCreateButton(text: 'Category 2', onPressed: () {}),
|
||||
],
|
||||
FutureBuilder<int>(
|
||||
future: _gameCountFuture,
|
||||
builder: (context, snapshot) {
|
||||
final int count = (snapshot.hasData)
|
||||
? snapshot.data!
|
||||
: 0;
|
||||
return QuickInfoTile(
|
||||
width: constraints.maxWidth * 0.45,
|
||||
height: constraints.maxHeight * 0.15,
|
||||
title: 'Games',
|
||||
icon: Icons.groups_rounded,
|
||||
value: count,
|
||||
);
|
||||
},
|
||||
),
|
||||
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: () {}),
|
||||
],
|
||||
SizedBox(width: constraints.maxWidth * 0.05),
|
||||
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: [
|
||||
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: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
29
lib/presentation/widgets/full_width_button.dart
Normal file
29
lib/presentation/widgets/full_width_button.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:game_tracker/core/custom_theme.dart';
|
||||
|
||||
class FullWidthButton extends StatelessWidget {
|
||||
const FullWidthButton({super.key, required this.text, this.onPressed});
|
||||
|
||||
final String text;
|
||||
final VoidCallback? onPressed;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(
|
||||
onPressed: onPressed,
|
||||
style: ElevatedButton.styleFrom(
|
||||
minimumSize: Size(MediaQuery.sizeOf(context).width * 0.9, 60),
|
||||
backgroundColor: CustomTheme.primaryColor,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
child: Text(
|
||||
text,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 22,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:game_tracker/core/custom_theme.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
|
||||
class GameTile extends StatefulWidget {
|
||||
final String gameTitle;
|
||||
@@ -48,9 +49,11 @@ class _GameTileState extends State<GameTile> {
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: CustomTheme.primaryColor,
|
||||
),
|
||||
child: Text(
|
||||
widget.ruleset,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
child: Skeleton.ignore(
|
||||
child: Text(
|
||||
widget.ruleset,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
@@ -68,19 +71,21 @@ class _GameTileState extends State<GameTile> {
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
color: Colors.yellow.shade300,
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.emoji_events, color: Colors.black, size: 20),
|
||||
Text(
|
||||
widget.winner,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
child: Skeleton.ignore(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Icon(Icons.emoji_events, color: Colors.black, size: 20),
|
||||
Text(
|
||||
widget.winner,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black87,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
81
lib/presentation/widgets/tiles/group_tile.dart
Normal file
81
lib/presentation/widgets/tiles/group_tile.dart
Normal file
@@ -0,0 +1,81 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:game_tracker/core/custom_theme.dart';
|
||||
import 'package:game_tracker/data/dto/group.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
|
||||
class GroupTile extends StatelessWidget {
|
||||
const GroupTile({super.key, required this.group});
|
||||
|
||||
final Group group;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.boxColor,
|
||||
border: Border.all(color: CustomTheme.boxBorder),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
group.name,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
'${group.members.length}',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.w900,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 3),
|
||||
const Icon(Icons.group, size: 22),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
Wrap(
|
||||
alignment: WrapAlignment.start,
|
||||
crossAxisAlignment: WrapCrossAlignment.start,
|
||||
spacing: 12.0,
|
||||
runSpacing: 8.0,
|
||||
children: <Widget>[
|
||||
for (var member in group.members)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 5,
|
||||
horizontal: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: CustomTheme.onBoxColor,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Skeleton.ignore(
|
||||
child: Text(
|
||||
member.name,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2.5),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,39 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
Widget TopCenteredMessage(String message) {
|
||||
return Container(
|
||||
padding: EdgeInsets.only(top: 100),
|
||||
margin: EdgeInsets.only(left: 10, right: 10),
|
||||
alignment: Alignment.topCenter,
|
||||
child: Text(
|
||||
"$message",
|
||||
style: TextStyle(fontSize: 20),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
);
|
||||
class TopCenteredMessage extends StatelessWidget {
|
||||
const TopCenteredMessage({
|
||||
super.key,
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.message,
|
||||
});
|
||||
|
||||
final String title;
|
||||
final String message;
|
||||
final IconData icon;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.only(top: 100),
|
||||
margin: const EdgeInsets.symmetric(horizontal: 10),
|
||||
alignment: Alignment.topCenter,
|
||||
child: Column(
|
||||
children: [
|
||||
Icon(icon, size: 45),
|
||||
const SizedBox(height: 10),
|
||||
Text(
|
||||
title,
|
||||
style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Text(
|
||||
message,
|
||||
style: const TextStyle(fontSize: 16),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user