merge & implement choose_color_view.dart
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/game_view/create_game_view.dart';
|
||||
import 'package:tallee/presentation/widgets/text_input/custom_search_bar.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/title_description_list_tile.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/game_view/create_game_view.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
|
||||
class ChooseGameView extends StatefulWidget {
|
||||
/// A view that allows the user to choose a game from a list of available games
|
||||
@@ -55,17 +55,21 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
Navigator.of(context).pop(selectedGameIndex);
|
||||
},
|
||||
),
|
||||
actions: [IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () async {
|
||||
await Navigator.push(context, adaptivePageRoute(
|
||||
builder: (context) => CreateGameView(
|
||||
callback: () {}, //TODO: implement callback
|
||||
),
|
||||
)
|
||||
);
|
||||
},
|
||||
)],
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () async {
|
||||
await Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) => CreateGameView(
|
||||
callback: () {}, //TODO: implement callback
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
title: Text(loc.choose_game),
|
||||
),
|
||||
body: PopScope(
|
||||
@@ -110,13 +114,22 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
});
|
||||
},
|
||||
onLongPress: () async {
|
||||
await Navigator.push(context, adaptivePageRoute(
|
||||
builder: (context) => CreateGameView(
|
||||
//TODO: implement callback & giving real game to create game view
|
||||
gameToEdit: Game(name: 'Cabo', description: '', ruleset: 'Highest Points'),
|
||||
callback: () {},
|
||||
await Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) => CreateGameView(
|
||||
//TODO: implement callback & giving real game to create game view
|
||||
gameToEdit: Game(
|
||||
name: 'Cabo',
|
||||
description:
|
||||
'Test Beschreibung mit sehr viel Inhalt',
|
||||
ruleset: Ruleset.highestScore,
|
||||
color: GameColor.blue,
|
||||
icon: '',
|
||||
),
|
||||
callback: () {},
|
||||
),
|
||||
),
|
||||
)
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/title_description_list_tile.dart';
|
||||
|
||||
class ChooseColorView extends StatefulWidget {
|
||||
/// A view that allows the user to choose a color from a list of available game colors
|
||||
/// - [initialColor]: The initially selected color
|
||||
const ChooseColorView({super.key, this.initialColor});
|
||||
|
||||
/// The initially selected color
|
||||
final GameColor? initialColor;
|
||||
|
||||
@override
|
||||
State<ChooseColorView> createState() => _ChooseColorViewState();
|
||||
}
|
||||
|
||||
class _ChooseColorViewState extends State<ChooseColorView> {
|
||||
/// Currently selected color
|
||||
GameColor? selectedColor;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
selectedColor = widget.initialColor;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
const colors = GameColor.values;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
appBar: AppBar(
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(selectedColor);
|
||||
},
|
||||
),
|
||||
title: Text(loc.choose_color),
|
||||
),
|
||||
body: PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (bool didPop, Object? result) {
|
||||
if (didPop) return;
|
||||
Navigator.of(context).pop(selectedColor);
|
||||
},
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.only(bottom: 85),
|
||||
itemCount: colors.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final color = colors[index];
|
||||
return TitleDescriptionListTile(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
if (selectedColor == color) {
|
||||
selectedColor = null;
|
||||
} else {
|
||||
selectedColor = color;
|
||||
}
|
||||
});
|
||||
},
|
||||
title: translateGameColorToString(color, context),
|
||||
description: '',
|
||||
isHighlighted: selectedColor == color,
|
||||
badgeText: ' ', //Breite für Color Badge
|
||||
badgeColor: getColorFromGameColor(color),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:game_tracker/core/custom_theme.dart';
|
||||
import 'package:game_tracker/core/enums.dart';
|
||||
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||
import 'package:game_tracker/presentation/widgets/tiles/title_description_list_tile.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/title_description_list_tile.dart';
|
||||
|
||||
class ChooseRulesetView extends StatefulWidget {
|
||||
/// A view that allows the user to choose a ruleset from a list of available rulesets
|
||||
/// - [rulesets]: A list of tuples containing the ruleset and its description
|
||||
@@ -12,13 +14,16 @@ class ChooseRulesetView extends StatefulWidget {
|
||||
required this.rulesets,
|
||||
required this.initialRulesetIndex,
|
||||
});
|
||||
|
||||
/// A list of tuples containing the ruleset and its description
|
||||
final List<(Ruleset, String)> rulesets;
|
||||
|
||||
/// The index of the initially selected ruleset
|
||||
final int initialRulesetIndex;
|
||||
@override
|
||||
State<ChooseRulesetView> createState() => _ChooseRulesetViewState();
|
||||
}
|
||||
|
||||
class _ChooseRulesetViewState extends State<ChooseRulesetView> {
|
||||
/// Currently selected ruleset index
|
||||
late int selectedRulesetIndex;
|
||||
@@ -28,6 +33,7 @@ class _ChooseRulesetViewState extends State<ChooseRulesetView> {
|
||||
selectedRulesetIndex = widget.initialRulesetIndex;
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final loc = AppLocalizations.of(context);
|
||||
@@ -90,4 +96,4 @@ class _ChooseRulesetViewState extends State<ChooseRulesetView> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:game_tracker/core/adaptive_page_route.dart';
|
||||
import 'package:game_tracker/core/constants.dart';
|
||||
import 'package:game_tracker/core/custom_theme.dart';
|
||||
import 'package:game_tracker/core/enums.dart';
|
||||
import 'package:game_tracker/data/dto/game.dart';
|
||||
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
||||
import 'package:game_tracker/presentation/views/main_menu/match_view/create_match/game_view/choose_ruleset_view.dart';
|
||||
import 'package:game_tracker/presentation/widgets/buttons/custom_width_button.dart';
|
||||
import 'package:game_tracker/presentation/widgets/text_input/text_input_field.dart';
|
||||
import 'package:game_tracker/presentation/widgets/tiles/choose_tile.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
import 'package:tallee/core/common.dart';
|
||||
import 'package:tallee/core/constants.dart';
|
||||
import 'package:tallee/core/custom_theme.dart';
|
||||
import 'package:tallee/core/enums.dart';
|
||||
import 'package:tallee/data/dto/game.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/game_view/choose_color_view.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/game_view/choose_ruleset_view.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/custom_width_button.dart';
|
||||
import 'package:tallee/presentation/widgets/text_input/text_input_field.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/choose_tile.dart';
|
||||
|
||||
class CreateGameView extends StatefulWidget {
|
||||
const CreateGameView({super.key, this.gameToEdit, required this.callback});
|
||||
@@ -26,6 +28,8 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
int selectedRulesetIndex = -1;
|
||||
late List<(Ruleset, String)> _rulesets;
|
||||
|
||||
GameColor? selectedColor;
|
||||
|
||||
final _gameNameController = TextEditingController();
|
||||
final _descriptionController = TextEditingController();
|
||||
|
||||
@@ -38,18 +42,38 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
final loc = AppLocalizations.of(context);
|
||||
_rulesets = [
|
||||
(Ruleset.singleWinner, loc.ruleset_single_winner),
|
||||
(Ruleset.singleLoser, loc.ruleset_single_loser),
|
||||
(Ruleset.mostPoints, loc.ruleset_most_points),
|
||||
(Ruleset.leastPoints, loc.ruleset_least_points),
|
||||
(
|
||||
Ruleset.singleWinner,
|
||||
translateRulesetToString(Ruleset.singleWinner, context),
|
||||
),
|
||||
(
|
||||
Ruleset.singleLoser,
|
||||
translateRulesetToString(Ruleset.singleLoser, context),
|
||||
),
|
||||
(
|
||||
Ruleset.highestScore,
|
||||
translateRulesetToString(Ruleset.highestScore, context),
|
||||
),
|
||||
(
|
||||
Ruleset.lowestScore,
|
||||
translateRulesetToString(Ruleset.lowestScore, context),
|
||||
),
|
||||
(
|
||||
Ruleset.multipleWinners,
|
||||
translateRulesetToString(Ruleset.multipleWinners, context),
|
||||
),
|
||||
];
|
||||
|
||||
if (widget.gameToEdit != null) {
|
||||
_gameNameController.text = widget.gameToEdit!.name;
|
||||
_descriptionController.text = widget.gameToEdit!.description ?? '';
|
||||
// TODO: Handle ruleset initialization from gameToEdit
|
||||
_descriptionController.text = widget.gameToEdit!.description;
|
||||
selectedRuleset = widget.gameToEdit!.ruleset;
|
||||
selectedColor = widget.gameToEdit!.color;
|
||||
|
||||
selectedRulesetIndex = _rulesets.indexWhere(
|
||||
(r) => r.$1 == selectedRuleset,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,8 +123,28 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
selectedRuleset = result;
|
||||
selectedRulesetIndex =
|
||||
result == null ? -1 : _rulesets.indexWhere((r) => r.$1 == result);
|
||||
selectedRulesetIndex = result == null
|
||||
? -1
|
||||
: _rulesets.indexWhere((r) => r.$1 == result);
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
ChooseTile(
|
||||
title: loc.color,
|
||||
trailingText: selectedColor == null
|
||||
? loc.none
|
||||
: translateGameColorToString(selectedColor!, context),
|
||||
onPressed: () async {
|
||||
final result = await Navigator.of(context).push<GameColor?>(
|
||||
adaptivePageRoute(
|
||||
builder: (context) =>
|
||||
ChooseColorView(initialColor: selectedColor),
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
selectedColor = result;
|
||||
});
|
||||
}
|
||||
},
|
||||
@@ -120,10 +164,13 @@ class _CreateGameViewState extends State<CreateGameView> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: CustomWidthButton(
|
||||
text: isEditing ? loc.edit_group : loc.create_game,
|
||||
text: isEditing ? loc.edit_game : loc.create_game,
|
||||
sizeRelativeToWidth: 1,
|
||||
buttonType: ButtonType.primary,
|
||||
onPressed: _gameNameController.text.trim().isNotEmpty && selectedRulesetIndex != -1
|
||||
onPressed:
|
||||
_gameNameController.text.trim().isNotEmpty &&
|
||||
selectedRulesetIndex != -1 &&
|
||||
selectedColor != null
|
||||
? () {
|
||||
//TODO: Handle saving to db & updating game selection view
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@@ -19,7 +19,7 @@ class TextInputField extends StatelessWidget {
|
||||
this.maxLength,
|
||||
this.maxLines = 1,
|
||||
this.minLines = 1,
|
||||
this.showCounterText = false
|
||||
this.showCounterText = false,
|
||||
});
|
||||
|
||||
/// The controller for the text input field.
|
||||
@@ -58,9 +58,9 @@ class TextInputField extends StatelessWidget {
|
||||
hintText: hintText,
|
||||
hintStyle: const TextStyle(fontSize: 18),
|
||||
counterText: showCounterText ? null : '',
|
||||
enabledBorder: OutlineInputBorder(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||
borderSide: BorderSide(color: CustomTheme.boxBorder),
|
||||
enabledBorder: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||
borderSide: BorderSide(color: CustomTheme.boxBorderColor),
|
||||
),
|
||||
focusedBorder: const OutlineInputBorder(
|
||||
borderRadius: BorderRadius.all(Radius.circular(12)),
|
||||
|
||||
Reference in New Issue
Block a user