diff --git a/lib/presentation/views/main_menu/create_game/choose_group_view.dart b/lib/presentation/views/main_menu/create_game/choose_group_view.dart index 168fb99..4eb6eab 100644 --- a/lib/presentation/views/main_menu/create_game/choose_group_view.dart +++ b/lib/presentation/views/main_menu/create_game/choose_group_view.dart @@ -5,14 +5,27 @@ import 'package:game_tracker/presentation/widgets/tiles/group_tile.dart'; class ChooseGroupView extends StatefulWidget { final List groups; + final int? selectedGroupIndex; - const ChooseGroupView({super.key, required this.groups}); + const ChooseGroupView({ + super.key, + required this.groups, + this.selectedGroupIndex, + }); @override State createState() => _ChooseGroupViewState(); } class _ChooseGroupViewState extends State { + late int selectedGroup; + + @override + void initState() { + selectedGroup = widget.selectedGroupIndex ?? -1; + super.initState(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -31,8 +44,19 @@ class _ChooseGroupViewState extends State { itemCount: widget.groups.length, itemBuilder: (BuildContext context, int index) { return GestureDetector( - onTap: () => Navigator.of(context).pop(widget.groups[index]), - child: GroupTile(group: widget.groups[index]), + onTap: () { + 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, + ), ); }, ), diff --git a/lib/presentation/views/main_menu/create_game/create_game_view.dart b/lib/presentation/views/main_menu/create_game/create_game_view.dart index 94a08d5..4c776f9 100644 --- a/lib/presentation/views/main_menu/create_game/create_game_view.dart +++ b/lib/presentation/views/main_menu/create_game/create_game_view.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:game_tracker/core/custom_theme.dart'; import 'package:game_tracker/core/enums.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/player.dart'; import 'package:game_tracker/presentation/views/main_menu/create_game/choose_group_view.dart'; @@ -25,6 +26,7 @@ class _CreateGameViewState extends State { late final List groupsList; Group? selectedGroup; + int selectedGroupIndex = -1; Ruleset? selectedRuleset; bool isLoading = true; @@ -128,9 +130,15 @@ class _CreateGameViewState extends State { onTap: () async { selectedGroup = await Navigator.of(context).push( MaterialPageRoute( - builder: (context) => ChooseGroupView(groups: groupsList), + builder: (context) => ChooseGroupView( + groups: groupsList, + selectedGroupIndex: selectedGroupIndex, + ), ), ); + selectedGroupIndex = groupsList.indexWhere( + (g) => g.id == selectedGroup?.id, + ); setState(() {}); }, child: Container( @@ -175,7 +183,12 @@ class _CreateGameViewState extends State { selectedRuleset == null) ? null : () 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), diff --git a/lib/presentation/widgets/tiles/group_tile.dart b/lib/presentation/widgets/tiles/group_tile.dart index fa91477..8627b0e 100644 --- a/lib/presentation/widgets/tiles/group_tile.dart +++ b/lib/presentation/widgets/tiles/group_tile.dart @@ -4,20 +4,31 @@ import 'package:game_tracker/data/dto/group.dart'; import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart'; 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 bool isHighlighted; @override Widget build(BuildContext context) { - return Container( + return AnimatedContainer( 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), - ), + decoration: isHighlighted + ? BoxDecoration( + color: CustomTheme.boxColor, + 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( crossAxisAlignment: CrossAxisAlignment.start, children: [