Added seletion highlighting for selected group
This commit is contained in:
@@ -5,14 +5,27 @@ import 'package:game_tracker/presentation/widgets/tiles/group_tile.dart';
|
||||
|
||||
class ChooseGroupView extends StatefulWidget {
|
||||
final List<Group> groups;
|
||||
final int? selectedGroupIndex;
|
||||
|
||||
const ChooseGroupView({super.key, required this.groups});
|
||||
const ChooseGroupView({
|
||||
super.key,
|
||||
required this.groups,
|
||||
this.selectedGroupIndex,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ChooseGroupView> createState() => _ChooseGroupViewState();
|
||||
}
|
||||
|
||||
class _ChooseGroupViewState extends State<ChooseGroupView> {
|
||||
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<ChooseGroupView> {
|
||||
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,
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
|
||||
@@ -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<CreateGameView> {
|
||||
late final List<Group> groupsList;
|
||||
|
||||
Group? selectedGroup;
|
||||
int selectedGroupIndex = -1;
|
||||
Ruleset? selectedRuleset;
|
||||
|
||||
bool isLoading = true;
|
||||
@@ -128,9 +130,15 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
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<CreateGameView> {
|
||||
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),
|
||||
|
||||
@@ -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: [
|
||||
|
||||
Reference in New Issue
Block a user