Fehlende Methoden für Games Datenbank inplementieren #76
@@ -5,14 +5,27 @@ import 'package:game_tracker/presentation/widgets/tiles/group_tile.dart';
|
|||||||
|
|
||||||
class ChooseGroupView extends StatefulWidget {
|
class ChooseGroupView extends StatefulWidget {
|
||||||
final List<Group> groups;
|
final List<Group> groups;
|
||||||
|
final int? selectedGroupIndex;
|
||||||
|
|
||||||
const ChooseGroupView({super.key, required this.groups});
|
const ChooseGroupView({
|
||||||
|
super.key,
|
||||||
|
required this.groups,
|
||||||
|
this.selectedGroupIndex,
|
||||||
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<ChooseGroupView> createState() => _ChooseGroupViewState();
|
State<ChooseGroupView> createState() => _ChooseGroupViewState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ChooseGroupViewState extends State<ChooseGroupView> {
|
class _ChooseGroupViewState extends State<ChooseGroupView> {
|
||||||
|
late int selectedGroup;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
selectedGroup = widget.selectedGroupIndex ?? -1;
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -31,8 +44,19 @@ class _ChooseGroupViewState extends State<ChooseGroupView> {
|
|||||||
itemCount: widget.groups.length,
|
itemCount: widget.groups.length,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => Navigator.of(context).pop(widget.groups[index]),
|
onTap: () {
|
||||||
child: GroupTile(group: widget.groups[index]),
|
setState(() {
|
||||||
|
selectedGroup = index;
|
||||||
|
});
|
||||||
|
|
||||||
|
Future.delayed(const Duration(milliseconds: 500), () {
|
||||||
|
Navigator.of(context).pop(widget.groups[index]);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: GroupTile(
|
||||||
|
group: widget.groups[index],
|
||||||
|
isHighlighted: selectedGroup == index,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ 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/core/enums.dart';
|
import 'package:game_tracker/core/enums.dart';
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
import 'package:game_tracker/data/db/database.dart';
|
||||||
|
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_game/choose_group_view.dart';
|
import 'package:game_tracker/presentation/views/main_menu/create_game/choose_group_view.dart';
|
||||||
@@ -25,6 +26,7 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
late final List<Group> groupsList;
|
late final List<Group> groupsList;
|
||||||
|
|
||||||
Group? selectedGroup;
|
Group? selectedGroup;
|
||||||
|
int selectedGroupIndex = -1;
|
||||||
Ruleset? selectedRuleset;
|
Ruleset? selectedRuleset;
|
||||||
|
|
||||||
bool isLoading = true;
|
bool isLoading = true;
|
||||||
@@ -128,9 +130,15 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
onTap: () async {
|
onTap: () async {
|
||||||
selectedGroup = await Navigator.of(context).push(
|
selectedGroup = await Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => ChooseGroupView(groups: groupsList),
|
builder: (context) => ChooseGroupView(
|
||||||
|
groups: groupsList,
|
||||||
|
selectedGroupIndex: selectedGroupIndex,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
selectedGroupIndex = groupsList.indexWhere(
|
||||||
|
(g) => g.id == selectedGroup?.id,
|
||||||
|
);
|
||||||
setState(() {});
|
setState(() {});
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
@@ -175,7 +183,12 @@ class _CreateGameViewState extends State<CreateGameView> {
|
|||||||
selectedRuleset == null)
|
selectedRuleset == null)
|
||||||
? null
|
? null
|
||||||
: () async {
|
: () async {
|
||||||
print('Create game pressed');
|
Game game = Game(
|
||||||
|
name: _gameNameController.text.trim(),
|
||||||
|
createdAt: DateTime.now(),
|
||||||
|
group: selectedGroup!,
|
||||||
|
);
|
||||||
|
print('Creating game: ${game.name}');
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
|
|||||||
@@ -4,20 +4,31 @@ import 'package:game_tracker/data/dto/group.dart';
|
|||||||
import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
|
import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
|
||||||
|
|
||||||
class GroupTile extends StatelessWidget {
|
class GroupTile extends StatelessWidget {
|
||||||
const GroupTile({super.key, required this.group});
|
const GroupTile({super.key, required this.group, this.isHighlighted = false});
|
||||||
|
|
||||||
final Group group;
|
final Group group;
|
||||||
|
final bool isHighlighted;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return AnimatedContainer(
|
||||||
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
|
padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 10),
|
||||||
decoration: BoxDecoration(
|
decoration: isHighlighted
|
||||||
color: CustomTheme.boxColor,
|
? BoxDecoration(
|
||||||
border: Border.all(color: CustomTheme.boxBorder),
|
color: CustomTheme.boxColor,
|
||||||
borderRadius: BorderRadius.circular(12),
|
border: Border.all(color: Colors.blue),
|
||||||
),
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(color: Colors.blue.withAlpha(120), blurRadius: 12),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
: BoxDecoration(
|
||||||
|
color: CustomTheme.boxColor,
|
||||||
|
border: Border.all(color: CustomTheme.boxBorder),
|
||||||
|
borderRadius: BorderRadius.circular(12),
|
||||||
|
),
|
||||||
|
duration: const Duration(milliseconds: 150),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
Reference in New Issue
Block a user