Implemented ruleset list tile with highlighting

This commit is contained in:
2025-11-24 13:49:53 +01:00
parent c284d10943
commit e182c815a1
3 changed files with 118 additions and 63 deletions

View File

@@ -1,37 +1,29 @@
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/core/enums.dart'; import 'package:game_tracker/core/enums.dart';
import 'package:game_tracker/presentation/widgets/tiles/ruleset_list_tile.dart';
class ChooseRulesetView extends StatefulWidget { class ChooseRulesetView extends StatefulWidget {
const ChooseRulesetView({super.key}); final List<(Ruleset, String, String)> rulesets;
final int initialRulesetIndex;
const ChooseRulesetView({
super.key,
required this.rulesets,
required this.initialRulesetIndex,
});
@override @override
State<ChooseRulesetView> createState() => _ChooseRulesetViewState(); State<ChooseRulesetView> createState() => _ChooseRulesetViewState();
} }
class _ChooseRulesetViewState extends State<ChooseRulesetView> { class _ChooseRulesetViewState extends State<ChooseRulesetView> {
List<(Ruleset, String, String)> rulesets = [ late int selectedRulesetIndex;
(
Ruleset.singleWinner, @override
'Single Winner', void initState() {
'Exactly one winner is chosen; ties are resolved by a predefined tiebreaker.', selectedRulesetIndex = widget.initialRulesetIndex;
), super.initState();
( }
Ruleset.singleLoser,
'Single Loser',
'Exactly one loser is determined; last place receives the penalty or consequence.',
),
(
Ruleset.mostPoints,
'Most Points',
'Traditional ruleset: the player with the most points wins.',
),
(
Ruleset.lastPoints,
'Least Points',
'Inverse scoring: the player with the fewest points wins.',
),
];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@@ -48,45 +40,22 @@ class _ChooseRulesetViewState extends State<ChooseRulesetView> {
), ),
body: ListView.builder( body: ListView.builder(
padding: const EdgeInsets.only(bottom: 85), padding: const EdgeInsets.only(bottom: 85),
itemCount: rulesets.length, itemCount: widget.rulesets.length,
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
return GestureDetector( return RulesetListTile(
onTap: () => Navigator.of(context).pop(rulesets[index].$1), onPressed: () async {
child: Container( setState(() {
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10), selectedRulesetIndex = index;
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12), });
decoration: BoxDecoration(
color: CustomTheme.boxColor, Future.delayed(const Duration(milliseconds: 500), () {
border: Border.all(color: CustomTheme.boxBorder), if (!context.mounted) return;
borderRadius: BorderRadius.circular(12), Navigator.of(context).pop(widget.rulesets[index].$1);
), });
child: Column( },
crossAxisAlignment: CrossAxisAlignment.start, title: widget.rulesets[index].$2,
children: [ description: widget.rulesets[index].$3,
Row( isHighlighted: selectedRulesetIndex == index,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text(
rulesets[index].$2,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
],
),
const SizedBox(height: 5),
Text(
rulesets[index].$3,
style: const TextStyle(fontSize: 14),
),
const SizedBox(height: 2.5),
],
),
),
); );
}, },
), ),

View File

@@ -28,9 +28,33 @@ class _CreateGameViewState extends State<CreateGameView> {
Group? selectedGroup; Group? selectedGroup;
int selectedGroupIndex = -1; int selectedGroupIndex = -1;
Ruleset? selectedRuleset; Ruleset? selectedRuleset;
int selectedRulesetIndex = -1;
bool isLoading = true; bool isLoading = true;
List<(Ruleset, String, String)> rulesets = [
(
Ruleset.singleWinner,
'Single Winner',
'Exactly one winner is chosen; ties are resolved by a predefined tiebreaker.',
),
(
Ruleset.singleLoser,
'Single Loser',
'Exactly one loser is determined; last place receives the penalty or consequence.',
),
(
Ruleset.mostPoints,
'Most Points',
'Traditional ruleset: the player with the most points wins.',
),
(
Ruleset.lastPoints,
'Least Points',
'Inverse scoring: the player with the fewest points wins.',
),
];
late final List<Player> skeletonData = List.filled( late final List<Player> skeletonData = List.filled(
7, 7,
Player(name: 'Player 0'), Player(name: 'Player 0'),
@@ -90,8 +114,14 @@ class _CreateGameViewState extends State<CreateGameView> {
onTap: () async { onTap: () async {
selectedRuleset = await Navigator.of(context).push( selectedRuleset = await Navigator.of(context).push(
MaterialPageRoute( MaterialPageRoute(
builder: (context) => const ChooseRulesetView(), builder: (context) => ChooseRulesetView(
rulesets: rulesets,
initialRulesetIndex: selectedRulesetIndex,
), ),
),
);
selectedRulesetIndex = rulesets.indexWhere(
(r) => r.$1 == selectedRuleset,
); );
setState(() {}); setState(() {});
}, },
@@ -132,7 +162,7 @@ class _CreateGameViewState extends State<CreateGameView> {
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChooseGroupView( builder: (context) => ChooseGroupView(
groups: groupsList, groups: groupsList,
selectedGroupIndex: selectedGroupIndex, initialGroupIndex: selectedGroupIndex,
), ),
), ),
); );

View File

@@ -0,0 +1,56 @@
import 'package:flutter/material.dart';
import 'package:game_tracker/core/custom_theme.dart';
class RulesetListTile extends StatelessWidget {
final String title;
final String description;
final VoidCallback? onPressed;
final bool isHighlighted;
const RulesetListTile({
super.key,
required this.title,
required this.description,
this.onPressed,
this.isHighlighted = false,
});
@override
Widget build(BuildContext context) {
// Use the callback directly so a null onPressed disables taps
return GestureDetector(
onTap: onPressed,
child: AnimatedContainer(
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12),
decoration: isHighlighted
? CustomTheme.highlightedBoxDecoration
: CustomTheme.standardBoxDecoration,
duration: const Duration(milliseconds: 200),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Text(
title,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontWeight: FontWeight.bold,
fontSize: 18,
),
),
),
],
),
const SizedBox(height: 5),
Text(description, style: const TextStyle(fontSize: 14)),
const SizedBox(height: 2.5),
],
),
),
);
}
}