5 Commits

Author SHA1 Message Date
9efbc12909 moved input widgets to new folder
All checks were successful
Pull Request Pipeline / test (pull_request) Successful in 2m1s
Pull Request Pipeline / lint (pull_request) Successful in 2m9s
2025-11-24 16:23:29 +01:00
7c7676abee Implemented CustomTextInputField 2025-11-24 16:17:15 +01:00
1faa74f026 Removed comment 2025-11-24 15:17:55 +01:00
3afae89234 Added Skeleton Loading 2025-11-24 15:17:46 +01:00
093c527591 Implemented TabView 2025-11-24 15:17:29 +01:00
6 changed files with 261 additions and 153 deletions

View File

@@ -27,37 +27,93 @@ class _ChooseRulesetViewState extends State<ChooseRulesetView> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return DefaultTabController(
backgroundColor: CustomTheme.backgroundColor, length: 2,
appBar: AppBar( initialIndex: 0,
child: Scaffold(
backgroundColor: CustomTheme.backgroundColor, backgroundColor: CustomTheme.backgroundColor,
scrolledUnderElevation: 0, appBar: AppBar(
title: const Text( backgroundColor: CustomTheme.backgroundColor,
'Choose Group', scrolledUnderElevation: 0,
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold), title: const Text(
'Choose Gametype',
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
),
centerTitle: true,
),
body: Column(
children: [
Container(
color: CustomTheme.backgroundColor,
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
child: TabBar(
padding: const EdgeInsets.symmetric(horizontal: 5),
// Label Settings
labelStyle: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
labelColor: Colors.white,
unselectedLabelStyle: const TextStyle(fontSize: 14),
unselectedLabelColor: Colors.white70,
// Indicator Settings
indicator: CustomTheme.standardBoxDecoration,
indicatorSize: TabBarIndicatorSize.tab,
indicatorWeight: 1,
indicatorPadding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 0,
),
// Divider Settings
dividerHeight: 0,
tabs: const [
Tab(text: 'Rulesets'),
Tab(text: 'Gametypes'),
],
),
),
const Divider(
indent: 30,
endIndent: 30,
thickness: 3,
radius: BorderRadius.all(Radius.circular(12)),
),
Expanded(
child: TabBarView(
children: [
ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: widget.rulesets.length,
itemBuilder: (BuildContext context, int index) {
return RulesetListTile(
onPressed: () async {
setState(() {
selectedRulesetIndex = index;
});
Future.delayed(const Duration(milliseconds: 500), () {
if (!context.mounted) return;
Navigator.of(
context,
).pop(widget.rulesets[index].$1);
});
},
title: widget.rulesets[index].$2,
description: widget.rulesets[index].$3,
isHighlighted: selectedRulesetIndex == index,
);
},
),
const Center(
child: Text(
'No gametypes available',
style: TextStyle(color: Colors.white70),
),
),
],
),
),
],
), ),
centerTitle: true,
),
body: ListView.builder(
padding: const EdgeInsets.only(bottom: 85),
itemCount: widget.rulesets.length,
itemBuilder: (BuildContext context, int index) {
return RulesetListTile(
onPressed: () async {
setState(() {
selectedRulesetIndex = index;
});
Future.delayed(const Duration(milliseconds: 500), () {
if (!context.mounted) return;
Navigator.of(context).pop(widget.rulesets[index].$1);
});
},
title: widget.rulesets[index].$2,
description: widget.rulesets[index].$3,
isHighlighted: selectedRulesetIndex == index,
);
},
), ),
); );
} }

View File

@@ -4,12 +4,12 @@ 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/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/presentation/views/main_menu/create_game/choose_group_view.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_ruleset_view.dart'; import 'package:game_tracker/presentation/views/main_menu/create_game/choose_ruleset_view.dart';
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart'; import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
import 'package:game_tracker/presentation/widgets/text_input_field.dart'; import 'package:game_tracker/presentation/widgets/text_input/text_input_field.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:skeletonizer/skeletonizer.dart';
class CreateGameView extends StatefulWidget { class CreateGameView extends StatefulWidget {
const CreateGameView({super.key}); const CreateGameView({super.key});
@@ -19,19 +19,31 @@ class CreateGameView extends StatefulWidget {
} }
class _CreateGameViewState extends State<CreateGameView> { class _CreateGameViewState extends State<CreateGameView> {
final TextEditingController _gameNameController = TextEditingController();
late final AppDatabase db; late final AppDatabase db;
late Future<List<Group>> _allGroupsFuture; late Future<List<Group>> _allGroupsFuture;
final TextEditingController _gameNameController = TextEditingController();
/// List of all groups from the database
late final List<Group> groupsList; late final List<Group> groupsList;
/// The currently selected group
Group? selectedGroup; Group? selectedGroup;
/// The index of the currently selected group in [groupsList] to mark it in
/// the [ChooseGroupView]
int selectedGroupIndex = -1; int selectedGroupIndex = -1;
/// The currently selected ruleset
Ruleset? selectedRuleset; Ruleset? selectedRuleset;
/// The index of the currently selected ruleset in [rulesets] to mark it in
/// the [ChooseRulesetView]
int selectedRulesetIndex = -1; int selectedRulesetIndex = -1;
bool isLoading = true; bool isLoading = true;
/// List of available rulesets with their display names and descriptions
/// as tuples of (Ruleset, String, String)
List<(Ruleset, String, String)> rulesets = [ List<(Ruleset, String, String)> rulesets = [
( (
Ruleset.singleWinner, Ruleset.singleWinner,
@@ -55,24 +67,15 @@ class _CreateGameViewState extends State<CreateGameView> {
), ),
]; ];
late final List<Player> skeletonData = List.filled(
7,
Player(name: 'Player 0'),
);
@override @override
void initState() { void initState() {
super.initState(); super.initState();
db = Provider.of<AppDatabase>(context, listen: false); db = Provider.of<AppDatabase>(context, listen: false);
_gameNameController.addListener(() {
setState(() {});
});
_allGroupsFuture = db.groupDao.getAllGroups(); _allGroupsFuture = db.groupDao.getAllGroups();
Future.wait([_allGroupsFuture]).then((result) async { Future.wait([_allGroupsFuture]).then((result) async {
await Future.delayed(const Duration(milliseconds: 1000)); await Future.delayed(const Duration(milliseconds: 250));
groupsList = result[0]; groupsList = result[0];
if (mounted) { if (mounted) {
@@ -97,126 +100,176 @@ class _CreateGameViewState extends State<CreateGameView> {
centerTitle: true, centerTitle: true,
), ),
body: SafeArea( body: SafeArea(
child: Column( child: Skeletonizer(
mainAxisAlignment: MainAxisAlignment.start, effect: PulseEffect(
children: [ from: Colors.grey[800]!,
Container( to: Colors.grey[600]!,
margin: const EdgeInsets.symmetric(horizontal: 12, vertical: 10), duration: const Duration(milliseconds: 800),
child: TextInputField( ),
controller: _gameNameController, enabled: isLoading,
hintText: 'Game name', enableSwitchAnimation: true,
onChanged: (value) { switchAnimationConfig: const SwitchAnimationConfig(
duration: Duration(milliseconds: 200),
switchInCurve: Curves.linear,
switchOutCurve: Curves.linear,
transitionBuilder: AnimatedSwitcher.defaultTransitionBuilder,
layoutBuilder: AnimatedSwitcher.defaultLayoutBuilder,
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
margin: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 10,
),
child: TextInputField(
controller: _gameNameController,
hintText: 'Game name',
onChanged: (value) {
setState(() {});
},
),
),
GestureDetector(
onTap: () async {
selectedRuleset = await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ChooseRulesetView(
rulesets: rulesets,
initialRulesetIndex: selectedRulesetIndex,
),
),
);
selectedRulesetIndex = rulesets.indexWhere(
(r) => r.$1 == selectedRuleset,
);
setState(() {}); setState(() {});
}, },
), child: Container(
), margin: const EdgeInsets.symmetric(
GestureDetector( horizontal: 12,
onTap: () async { vertical: 5,
selectedRuleset = await Navigator.of(context).push( ),
MaterialPageRoute( padding: const EdgeInsets.symmetric(
builder: (context) => ChooseRulesetView( vertical: 10,
rulesets: rulesets, horizontal: 15,
initialRulesetIndex: selectedRulesetIndex, ),
), decoration: CustomTheme.standardBoxDecoration,
child: Row(
children: [
const Text(
'Ruleset',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
const Spacer(),
Text(
selectedRuleset == null
? 'None'
: translateRulesetToString(selectedRuleset!),
),
const SizedBox(width: 10),
const Icon(Icons.arrow_forward_ios, size: 16),
],
), ),
);
selectedRulesetIndex = rulesets.indexWhere(
(r) => r.$1 == selectedRuleset,
);
setState(() {});
},
child: Container(
margin: const EdgeInsets.symmetric(
horizontal: 12,
vertical: 10,
), ),
padding: const EdgeInsets.symmetric( ),
vertical: 10, GestureDetector(
horizontal: 15, onTap: () async {
), selectedGroup = await Navigator.of(context).push(
decoration: CustomTheme.standardBoxDecoration, MaterialPageRoute(
child: Row( builder: (context) => ChooseGroupView(
children: [ groups: groupsList,
const Text( initialGroupIndex: selectedGroupIndex,
'Ruleset',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
), ),
), ),
const Spacer(), );
Text(selectedRuleset == null ? 'None' : 'Single Winner'), selectedGroupIndex = groupsList.indexWhere(
const SizedBox(width: 10), (g) => g.id == selectedGroup?.id,
const Icon(Icons.arrow_forward_ios, size: 16), );
], setState(() {});
), },
), child: Container(
), margin: const EdgeInsets.symmetric(
GestureDetector( horizontal: 12,
onTap: () async { vertical: 5,
selectedGroup = await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ChooseGroupView(
groups: groupsList,
initialGroupIndex: selectedGroupIndex,
),
), ),
); padding: const EdgeInsets.symmetric(
selectedGroupIndex = groupsList.indexWhere( vertical: 10,
(g) => g.id == selectedGroup?.id, horizontal: 15,
); ),
setState(() {}); decoration: CustomTheme.standardBoxDecoration,
}, child: Row(
child: Container( children: [
margin: const EdgeInsets.symmetric( const Text(
horizontal: 12, 'Group',
vertical: 10, style: TextStyle(
), fontSize: 16,
padding: const EdgeInsets.symmetric( fontWeight: FontWeight.bold,
vertical: 10, ),
horizontal: 15,
),
decoration: CustomTheme.standardBoxDecoration,
child: Row(
children: [
const Text(
'Group',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
), ),
), const Spacer(),
const Spacer(), Text(
Text(selectedGroup == null ? 'None' : selectedGroup!.name), selectedGroup == null ? 'None' : selectedGroup!.name,
const SizedBox(width: 10), ),
const Icon(Icons.arrow_forward_ios, size: 16), const SizedBox(width: 10),
], const Icon(Icons.arrow_forward_ios, size: 16),
],
),
), ),
), ),
), Container(
const Spacer(), decoration: CustomTheme.standardBoxDecoration,
CustomWidthButton( width: MediaQuery.of(context).size.width * 0.95,
text: 'Create game', height: 400,
sizeRelativeToWidth: 0.95, padding: const EdgeInsets.all(12),
buttonType: ButtonType.primary, margin: const EdgeInsets.symmetric(vertical: 10),
onPressed: child: const Center(child: Text('PlayerComponent')),
(_gameNameController.text.isEmpty || ),
selectedGroup == null || const Spacer(),
selectedRuleset == null) CustomWidthButton(
? null text: 'Create game',
: () async { sizeRelativeToWidth: 0.95,
Game game = Game( buttonType: ButtonType.primary,
name: _gameNameController.text.trim(), onPressed:
createdAt: DateTime.now(), (_gameNameController.text.isEmpty ||
group: selectedGroup!, selectedGroup == null ||
); selectedRuleset == null)
print('Creating game: ${game.name}'); ? null
}, : () async {
), Game game = Game(
const SizedBox(height: 20), name: _gameNameController.text.trim(),
], createdAt: DateTime.now(),
group: selectedGroup!,
);
// TODO: Replace with navigation to GameResultView()
print('Created game: $game');
Navigator.pop(context);
},
),
const SizedBox(height: 20),
],
),
), ),
), ),
); );
} }
/// Translates a [Ruleset] enum value to its corresponding string representation.
String translateRulesetToString(Ruleset ruleset) {
switch (ruleset) {
case Ruleset.singleWinner:
return 'Single Winner';
case Ruleset.singleLoser:
return 'Single Loser';
case Ruleset.mostPoints:
return 'Most Points';
case Ruleset.lastPoints:
return 'Least Points';
}
}
} }

View File

@@ -5,8 +5,8 @@ import 'package:game_tracker/data/db/database.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/widgets/buttons/custom_width_button.dart'; import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
import 'package:game_tracker/presentation/widgets/custom_search_bar.dart'; import 'package:game_tracker/presentation/widgets/text_input/custom_search_bar.dart';
import 'package:game_tracker/presentation/widgets/text_input_field.dart'; import 'package:game_tracker/presentation/widgets/text_input/text_input_field.dart';
import 'package:game_tracker/presentation/widgets/tiles/text_icon_list_tile.dart'; import 'package:game_tracker/presentation/widgets/tiles/text_icon_list_tile.dart';
import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart'; import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
import 'package:game_tracker/presentation/widgets/top_centered_message.dart'; import 'package:game_tracker/presentation/widgets/top_centered_message.dart';

View File

@@ -17,7 +17,6 @@ class RulesetListTile extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Use the callback directly so a null onPressed disables taps
return GestureDetector( return GestureDetector(
onTap: onPressed, onTap: onPressed,
child: AnimatedContainer( child: AnimatedContainer(