Merge branch 'development' into feature/202-live-edit-modus
# Conflicts: # lib/l10n/generated/app_localizations.dart # pubspec.yaml
This commit is contained in:
@@ -197,7 +197,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
/// obsolete. For each such match, the group association is removed by setting
|
||||
/// its [groupId] to null.
|
||||
Future<void> deleteObsoleteMatchGroupRelations() async {
|
||||
final groupMatches = await db.matchDao.getGroupMatches(
|
||||
final groupMatches = await db.matchDao.getMatchesByGroup(
|
||||
groupId: widget.groupToEdit!.id,
|
||||
);
|
||||
|
||||
|
||||
@@ -244,7 +244,9 @@ class _GroupDetailViewState extends State<GroupDetailView> {
|
||||
/// Loads statistics for this group
|
||||
Future<void> _loadStatistics() async {
|
||||
isLoading = true;
|
||||
final groupMatches = await db.matchDao.getGroupMatches(groupId: _group.id);
|
||||
final groupMatches = await db.matchDao.getMatchesByGroup(
|
||||
groupId: _group.id,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
totalMatches = groupMatches.length;
|
||||
|
||||
@@ -1,19 +1,26 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.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/data/db/database.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/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/presentation/widgets/tiles/game_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/top_centered_message.dart';
|
||||
|
||||
class ChooseGameView extends StatefulWidget {
|
||||
/// A view that allows the user to choose a game from a list of available games
|
||||
/// - [games]: A list of tuples containing the game name, description and ruleset
|
||||
/// - [initialGameIndex]: The index of the initially selected game
|
||||
/// - [games]: The list of available games
|
||||
/// - [initialGameId]: The id of the initially selected game
|
||||
/// - [onGamesUpdated]: Optional callback invoked when the games are updated
|
||||
const ChooseGameView({
|
||||
super.key,
|
||||
required this.games,
|
||||
required this.initialGameId,
|
||||
this.onGamesUpdated,
|
||||
});
|
||||
|
||||
/// A list of tuples containing the game name, description and ruleset
|
||||
@@ -22,20 +29,37 @@ class ChooseGameView extends StatefulWidget {
|
||||
/// The id of the initially selected game
|
||||
final String initialGameId;
|
||||
|
||||
/// Optional callback invoked when the games are updated
|
||||
final VoidCallback? onGamesUpdated;
|
||||
|
||||
@override
|
||||
State<ChooseGameView> createState() => _ChooseGameViewState();
|
||||
}
|
||||
|
||||
class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
late final AppDatabase db;
|
||||
|
||||
late List<(Game, int)> gameCounts = [];
|
||||
|
||||
/// Controller for the search bar
|
||||
final TextEditingController searchBarController = TextEditingController();
|
||||
|
||||
/// Currently selected game index
|
||||
late String selectedGameId;
|
||||
|
||||
/// Games filtered according to the current search query
|
||||
late List<Game> filteredGames;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
fetchGameCounts();
|
||||
|
||||
selectedGameId = widget.initialGameId;
|
||||
|
||||
// Start with all games visible
|
||||
filteredGames = List<Game>.from(widget.games);
|
||||
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@@ -58,6 +82,30 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
);
|
||||
},
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: () async {
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) => CreateGameView(
|
||||
onGameChanged: () {
|
||||
widget.onGamesUpdated?.call();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
if (result != null && result.game != null) {
|
||||
setState(() {
|
||||
widget.games.insert(0, result.game);
|
||||
});
|
||||
_refreshFromSource();
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
|
||||
title: Text(loc.choose_game),
|
||||
),
|
||||
body: PopScope(
|
||||
@@ -72,37 +120,101 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
// Search Bar
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
child: CustomSearchBar(
|
||||
controller: searchBarController,
|
||||
hintText: loc.game_name,
|
||||
onChanged: (value) {
|
||||
_applySearchFilter(value);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
|
||||
// Game list
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: widget.games.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
return TitleDescriptionListTile(
|
||||
title: widget.games[index].name,
|
||||
description: widget.games[index].description,
|
||||
badgeText: translateRulesetToString(
|
||||
widget.games[index].ruleset,
|
||||
child: Visibility(
|
||||
visible: filteredGames.isNotEmpty,
|
||||
replacement: Visibility(
|
||||
visible: widget.games.isNotEmpty,
|
||||
replacement: TopCenteredMessage(
|
||||
icon: Icons.info,
|
||||
title: loc.info,
|
||||
message: loc.no_games_created_yet,
|
||||
),
|
||||
child: TopCenteredMessage(
|
||||
icon: Icons.info,
|
||||
title: loc.info,
|
||||
message: AppLocalizations.of(
|
||||
context,
|
||||
),
|
||||
isHighlighted: selectedGameId == widget.games[index].id,
|
||||
onPressed: () async {
|
||||
setState(() {
|
||||
if (selectedGameId != widget.games[index].id) {
|
||||
selectedGameId = widget.games[index].id;
|
||||
} else {
|
||||
selectedGameId = '';
|
||||
).there_are_no_games_matching_your_search,
|
||||
),
|
||||
),
|
||||
child: ListView.builder(
|
||||
itemCount: filteredGames.length,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
final game = filteredGames[index];
|
||||
return GameTile(
|
||||
title: game.name,
|
||||
description: game.description,
|
||||
badgeText: translateRulesetToString(
|
||||
game.ruleset,
|
||||
context,
|
||||
),
|
||||
badgeColor: getColorFromGameColor(game.color),
|
||||
isHighlighted: selectedGameId == game.id,
|
||||
onTap: () async {
|
||||
setState(() {
|
||||
if (selectedGameId == game.id) {
|
||||
selectedGameId = '';
|
||||
} else {
|
||||
selectedGameId = game.id;
|
||||
}
|
||||
});
|
||||
},
|
||||
onLongPress: () async {
|
||||
final result = await Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) => CreateGameView(
|
||||
gameToEdit: game,
|
||||
matchCount: getMatchCount(game),
|
||||
onGameChanged: () {
|
||||
widget.onGamesUpdated?.call();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
if (result != null && result.game != null) {
|
||||
// Find the index in the original list to mutate
|
||||
final originalIndex = widget.games.indexWhere(
|
||||
(g) => g.id == game.id,
|
||||
);
|
||||
if (originalIndex == -1) {
|
||||
return;
|
||||
}
|
||||
if (result.delete) {
|
||||
setState(() {
|
||||
// deselect the game
|
||||
if (selectedGameId == game.id) {
|
||||
selectedGameId = '';
|
||||
}
|
||||
widget.games.removeAt(originalIndex);
|
||||
widget.onGamesUpdated?.call();
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
widget.games[originalIndex] = result.game;
|
||||
});
|
||||
}
|
||||
_refreshFromSource();
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -110,4 +222,39 @@ class _ChooseGameViewState extends State<ChooseGameView> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Applies the search filter to the games list based on [query].
|
||||
void _applySearchFilter(String query) {
|
||||
final q = query.toLowerCase().trim();
|
||||
if (q.isEmpty) {
|
||||
setState(() {
|
||||
filteredGames = List<Game>.from(widget.games);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
filteredGames = widget.games.where((game) {
|
||||
final name = game.name.toLowerCase();
|
||||
final description = game.description.toLowerCase();
|
||||
return name.contains(q) || description.contains(q);
|
||||
}).toList();
|
||||
});
|
||||
}
|
||||
|
||||
/// Re-applies the current filter after the underlying games list changed.
|
||||
void _refreshFromSource() {
|
||||
_applySearchFilter(searchBarController.text);
|
||||
}
|
||||
|
||||
Future<void> fetchGameCounts() async {
|
||||
gameCounts = await db.gameDao.getGameUsage();
|
||||
}
|
||||
|
||||
// Returns the number of matches that use the given [game].
|
||||
int getMatchCount(Game game) {
|
||||
return gameCounts
|
||||
.firstWhere((gc) => gc.$1.id == game.id, orElse: () => (game, 0))
|
||||
.$2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,520 @@
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_popup/flutter_popup.dart';
|
||||
import 'package:provider/provider.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/db/database.dart';
|
||||
import 'package:tallee/data/models/game.dart';
|
||||
import 'package:tallee/data/models/group.dart';
|
||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||
import 'package:tallee/presentation/widgets/buttons/custom_width_button.dart';
|
||||
import 'package:tallee/presentation/widgets/dialog/custom_alert_dialog.dart';
|
||||
import 'package:tallee/presentation/widgets/dialog/custom_dialog_action.dart';
|
||||
import 'package:tallee/presentation/widgets/text_input/text_input_field.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/choose_tile.dart';
|
||||
|
||||
/// A stateful widget for creating or editing a game.
|
||||
/// - [gameToEdit] An optional game to prefill the fields
|
||||
/// - [onGameChanged] Callback to invoke when the game is created or edited
|
||||
class CreateGameView extends StatefulWidget {
|
||||
const CreateGameView({
|
||||
super.key,
|
||||
required this.onGameChanged,
|
||||
this.gameToEdit,
|
||||
this.matchCount = 0,
|
||||
});
|
||||
|
||||
/// Callback to invoke when the game is created or edited
|
||||
final VoidCallback onGameChanged;
|
||||
|
||||
/// An optional game to prefill the fields
|
||||
final Game? gameToEdit;
|
||||
|
||||
final int matchCount;
|
||||
|
||||
@override
|
||||
State<CreateGameView> createState() => _CreateGameViewState();
|
||||
}
|
||||
|
||||
class _CreateGameViewState extends State<CreateGameView> {
|
||||
/// GlobalKey for ScaffoldMessenger to show snackbars
|
||||
final _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
|
||||
|
||||
late final AppDatabase db;
|
||||
|
||||
late List<(Ruleset, String)> _rulesets;
|
||||
Ruleset? selectedRuleset = Ruleset.singleWinner;
|
||||
|
||||
late List<(GameColor, String)> _colors;
|
||||
GameColor? selectedColor = GameColor.orange;
|
||||
|
||||
/// Controller for the game name input field.
|
||||
final _gameNameController = TextEditingController();
|
||||
|
||||
/// Controller for the game description input field.
|
||||
final _descriptionController = TextEditingController();
|
||||
|
||||
/// The ID of the currently selected group.
|
||||
late String selectedGroupId;
|
||||
|
||||
/// A controller for the search bar input field.
|
||||
final TextEditingController controller = TextEditingController();
|
||||
|
||||
/// A list of groups filtered based on the search query.
|
||||
late final List<Group> filteredGroups;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
db = Provider.of<AppDatabase>(context, listen: false);
|
||||
_gameNameController.addListener(() => setState(() {}));
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_rulesets = [
|
||||
(
|
||||
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),
|
||||
),
|
||||
];
|
||||
_colors = [
|
||||
(GameColor.green, translateGameColorToString(GameColor.green, context)),
|
||||
(GameColor.teal, translateGameColorToString(GameColor.teal, context)),
|
||||
(GameColor.blue, translateGameColorToString(GameColor.blue, context)),
|
||||
(GameColor.purple, translateGameColorToString(GameColor.purple, context)),
|
||||
(GameColor.pink, translateGameColorToString(GameColor.pink, context)),
|
||||
(GameColor.red, translateGameColorToString(GameColor.red, context)),
|
||||
(GameColor.orange, translateGameColorToString(GameColor.orange, context)),
|
||||
(GameColor.yellow, translateGameColorToString(GameColor.yellow, context)),
|
||||
];
|
||||
|
||||
if (widget.gameToEdit != null) {
|
||||
_gameNameController.text = widget.gameToEdit!.name;
|
||||
_descriptionController.text = widget.gameToEdit!.description;
|
||||
selectedRuleset = widget.gameToEdit!.ruleset;
|
||||
selectedColor = widget.gameToEdit!.color;
|
||||
selectedRuleset = widget.gameToEdit!.ruleset;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_gameNameController.dispose();
|
||||
_descriptionController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var loc = AppLocalizations.of(context);
|
||||
final isEditing = widget.gameToEdit != null;
|
||||
|
||||
return ScaffoldMessenger(
|
||||
child: Scaffold(
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
appBar: AppBar(
|
||||
title: Text(isEditing ? loc.edit_game : loc.create_game),
|
||||
actions: [
|
||||
if (isEditMode())
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
if (!context.mounted) return;
|
||||
|
||||
// Build the dialog content based on match count
|
||||
final String dialogContent = widget.matchCount > 0
|
||||
? loc.delete_game_with_matches_warning(widget.matchCount)
|
||||
: loc.this_cannot_be_undone;
|
||||
|
||||
showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => CustomAlertDialog(
|
||||
title: loc.delete_game,
|
||||
content: Text(
|
||||
dialogContent,
|
||||
style: const TextStyle(fontSize: 15),
|
||||
),
|
||||
actions: [
|
||||
CustomDialogAction(
|
||||
isDestructive: true,
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
text: loc.delete,
|
||||
),
|
||||
CustomDialogAction(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
buttonType: ButtonType.secondary,
|
||||
text: loc.cancel,
|
||||
),
|
||||
],
|
||||
),
|
||||
).then((confirmed) async {
|
||||
if (confirmed == true && context.mounted) {
|
||||
// Delete assocaited matches
|
||||
if (widget.matchCount > 0) {
|
||||
await db.matchDao.deleteMatchesByGame(
|
||||
gameId: widget.gameToEdit!.id,
|
||||
);
|
||||
}
|
||||
|
||||
// Delete the targetted game
|
||||
bool success = await db.gameDao.deleteGame(
|
||||
gameId: widget.gameToEdit!.id,
|
||||
);
|
||||
|
||||
if (!context.mounted) return;
|
||||
if (success) {
|
||||
widget.onGameChanged.call();
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop((game: widget.gameToEdit, delete: true));
|
||||
} else {
|
||||
if (!mounted) return;
|
||||
showSnackbar(message: loc.error_deleting_game);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
// Game name input field
|
||||
Container(
|
||||
margin: CustomTheme.tileMargin,
|
||||
child: TextInputField(
|
||||
controller: _gameNameController,
|
||||
maxLength: Constants.MAX_MATCH_NAME_LENGTH,
|
||||
hintText: loc.game_name,
|
||||
),
|
||||
),
|
||||
|
||||
// Choose ruleset tile
|
||||
if (!isEditMode())
|
||||
ChooseTile(title: loc.ruleset, trailing: getColorDropdown(loc)),
|
||||
|
||||
// Choose color tile
|
||||
ChooseTile(title: loc.color, trailing: getRulesetDropdown(loc)),
|
||||
|
||||
// Description input field
|
||||
Container(
|
||||
margin: CustomTheme.tileMargin,
|
||||
child: TextInputField(
|
||||
controller: _descriptionController,
|
||||
hintText: loc.description,
|
||||
minLines: 6,
|
||||
maxLines: 6,
|
||||
maxLength: Constants.MAX_GAME_DESCRIPTION_LENGTH,
|
||||
showCounterText: true,
|
||||
),
|
||||
),
|
||||
|
||||
const Spacer(),
|
||||
|
||||
// Create/Edit game button
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(12.0),
|
||||
child: CustomWidthButton(
|
||||
text: isEditing ? loc.edit_game : loc.create_game,
|
||||
sizeRelativeToWidth: 1,
|
||||
buttonType: ButtonType.primary,
|
||||
onPressed:
|
||||
_gameNameController.text.trim().isNotEmpty &&
|
||||
selectedRuleset != null &&
|
||||
selectedColor != null
|
||||
? () async {
|
||||
Game newGame = Game(
|
||||
name: _gameNameController.text.trim(),
|
||||
description: _descriptionController.text.trim(),
|
||||
ruleset: selectedRuleset!,
|
||||
color: selectedColor!,
|
||||
);
|
||||
if (isEditing) {
|
||||
await handleGameUpdate(newGame);
|
||||
} else {
|
||||
await handleGameCreation(newGame);
|
||||
}
|
||||
widget.onGameChanged.call();
|
||||
if (context.mounted) {
|
||||
Navigator.of(
|
||||
context,
|
||||
).pop((game: newGame, delete: false));
|
||||
}
|
||||
}
|
||||
: null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Handles updating an existing game in the database.
|
||||
///
|
||||
/// [newGame] The updated game object.
|
||||
Future<void> handleGameUpdate(Game newGame) async {
|
||||
final oldGame = widget.gameToEdit!;
|
||||
|
||||
if (oldGame.name != newGame.name) {
|
||||
await db.gameDao.updateGameName(gameId: oldGame.id, name: newGame.name);
|
||||
}
|
||||
|
||||
if (oldGame.description != newGame.description) {
|
||||
await db.gameDao.updateGameDescription(
|
||||
gameId: oldGame.id,
|
||||
description: newGame.description,
|
||||
);
|
||||
}
|
||||
|
||||
if (oldGame.ruleset != newGame.ruleset) {
|
||||
await db.gameDao.updateGameRuleset(
|
||||
gameId: oldGame.id,
|
||||
ruleset: newGame.ruleset,
|
||||
);
|
||||
}
|
||||
|
||||
if (oldGame.color != newGame.color) {
|
||||
await db.gameDao.updateGameColor(
|
||||
gameId: oldGame.id,
|
||||
color: newGame.color,
|
||||
);
|
||||
}
|
||||
|
||||
if (oldGame.icon != newGame.icon) {
|
||||
await db.gameDao.updateGameIcon(gameId: oldGame.id, icon: newGame.icon);
|
||||
}
|
||||
}
|
||||
|
||||
/// Handles creating a new game in the database.
|
||||
///
|
||||
/// [newGame] The game object to be created.
|
||||
Future<void> handleGameCreation(Game newGame) async {
|
||||
await db.gameDao.addGame(game: newGame);
|
||||
}
|
||||
|
||||
/// Displays a snackbar with the given message and optional action.
|
||||
///
|
||||
/// [message] The message to display in the snackbar.
|
||||
void showSnackbar({required String message}) {
|
||||
final messenger = _scaffoldMessengerKey.currentState;
|
||||
if (messenger != null) {
|
||||
messenger.hideCurrentSnackBar();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message, style: const TextStyle(color: Colors.white)),
|
||||
backgroundColor: CustomTheme.boxColor,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool isEditMode() {
|
||||
return widget.gameToEdit != null;
|
||||
}
|
||||
|
||||
Widget getRulesetDropdown(AppLocalizations loc) {
|
||||
return CustomPopup(
|
||||
showArrow: true,
|
||||
arrowColor: CustomTheme.boxBorderColor,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 0, vertical: 10),
|
||||
barrierColor: Colors.transparent,
|
||||
contentDecoration: CustomTheme.standardBoxDecoration,
|
||||
content: StatefulBuilder(
|
||||
builder: (context, setPopupState) => SizedBox(
|
||||
width: 280,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: List.generate(
|
||||
_rulesets.length,
|
||||
(index) => GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selectedRuleset = _rulesets[index].$1;
|
||||
});
|
||||
setPopupState(() {});
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(8),
|
||||
),
|
||||
color: selectedRuleset == _rulesets[index].$1
|
||||
? CustomTheme.textColor.withAlpha(20)
|
||||
: Colors.transparent,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 8,
|
||||
horizontal: 16,
|
||||
),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
Icon(getRulesetIcon(_rulesets[index].$1), size: 16),
|
||||
Text(
|
||||
_rulesets[index].$2,
|
||||
style: const TextStyle(
|
||||
color: CustomTheme.textColor,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (index < _rulesets.length - 1)
|
||||
const Divider(indent: 15, endIndent: 15),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
Icon(getRulesetIcon(selectedRuleset!), size: 16),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 5),
|
||||
child: Text(
|
||||
translateRulesetToString(selectedRuleset!, context),
|
||||
textAlign: TextAlign.right,
|
||||
),
|
||||
),
|
||||
Transform.rotate(
|
||||
angle: pi / 2,
|
||||
child: const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget getColorDropdown(AppLocalizations loc) {
|
||||
return CustomPopup(
|
||||
showArrow: true,
|
||||
arrowColor: CustomTheme.boxBorderColor,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 0, vertical: 10),
|
||||
barrierColor: Colors.transparent,
|
||||
contentDecoration: CustomTheme.standardBoxDecoration,
|
||||
content: StatefulBuilder(
|
||||
builder: (context, setPopupState) => SizedBox(
|
||||
width: 150,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: List.generate(
|
||||
_colors.length,
|
||||
(index) => GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
selectedColor = _colors[index].$1;
|
||||
});
|
||||
setPopupState(() {});
|
||||
},
|
||||
child: Column(
|
||||
children: [
|
||||
// Selected Highlighting
|
||||
Container(
|
||||
margin: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(8),
|
||||
),
|
||||
color: selectedColor == _colors[index].$1
|
||||
? CustomTheme.textColor.withAlpha(20)
|
||||
: Colors.transparent,
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 6),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: selectedColor == null
|
||||
? [Text(loc.none)]
|
||||
: [
|
||||
Container(
|
||||
width: 16,
|
||||
height: 16,
|
||||
margin: const EdgeInsets.only(left: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: getColorFromGameColor(
|
||||
_colors[index].$1,
|
||||
),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
_colors[index].$2,
|
||||
style: const TextStyle(
|
||||
color: CustomTheme.textColor,
|
||||
fontSize: 15,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (index < _colors.length - 1)
|
||||
const Divider(indent: 15, endIndent: 15),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
spacing: 8,
|
||||
children: [
|
||||
// Selected Color
|
||||
Container(
|
||||
width: 16,
|
||||
height: 16,
|
||||
decoration: BoxDecoration(
|
||||
color: getColorFromGameColor(selectedColor!),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 5),
|
||||
child: Text(translateGameColorToString(selectedColor!, context)),
|
||||
),
|
||||
Transform.rotate(
|
||||
angle: pi / 2,
|
||||
child: const Icon(Icons.arrow_forward_ios, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,13 @@ class CreateMatchView extends StatefulWidget {
|
||||
this.onWinnerChanged,
|
||||
this.matchToEdit,
|
||||
this.onMatchUpdated,
|
||||
this.onMatchesUpdated,
|
||||
});
|
||||
|
||||
final VoidCallback? onWinnerChanged;
|
||||
|
||||
final VoidCallback? onMatchesUpdated;
|
||||
|
||||
final void Function(Match)? onMatchUpdated;
|
||||
|
||||
/// An optional match to prefill the fields for editing.
|
||||
@@ -115,6 +118,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
// Match name input field.
|
||||
Container(
|
||||
margin: CustomTheme.tileMargin,
|
||||
child: TextInputField(
|
||||
@@ -123,34 +127,40 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
maxLength: Constants.MAX_MATCH_NAME_LENGTH,
|
||||
),
|
||||
),
|
||||
ChooseTile(
|
||||
title: loc.game,
|
||||
trailingText: selectedGame == null
|
||||
? loc.none_group
|
||||
: selectedGame!.name,
|
||||
onPressed: () async {
|
||||
selectedGame = await Navigator.of(context).push(
|
||||
adaptivePageRoute(
|
||||
builder: (context) => ChooseGameView(
|
||||
games: gamesList,
|
||||
initialGameId: selectedGame?.id ?? '',
|
||||
|
||||
// Game selection tile.
|
||||
if (!isEditMode())
|
||||
ChooseTile(
|
||||
title: loc.game,
|
||||
trailing: selectedGame == null
|
||||
? Text(loc.none_group)
|
||||
: Text(selectedGame!.name),
|
||||
onPressed: () async {
|
||||
selectedGame = await Navigator.of(context).push(
|
||||
adaptivePageRoute(
|
||||
builder: (context) => ChooseGameView(
|
||||
games: gamesList,
|
||||
initialGameId: selectedGame?.id ?? '',
|
||||
onGamesUpdated: widget.onMatchesUpdated,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
if (selectedGame != null) {
|
||||
hintText = selectedGame!.name;
|
||||
} else {
|
||||
hintText = loc.match_name;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
setState(() {
|
||||
if (selectedGame != null) {
|
||||
hintText = selectedGame!.name;
|
||||
} else {
|
||||
hintText = loc.match_name;
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
// Group selection tile.
|
||||
ChooseTile(
|
||||
title: loc.group,
|
||||
trailingText: selectedGroup == null
|
||||
? loc.none_group
|
||||
: selectedGroup!.name,
|
||||
trailing: selectedGroup == null
|
||||
? Text(loc.none_group)
|
||||
: Text(selectedGroup!.name),
|
||||
onPressed: () async {
|
||||
// Remove all players from the previously selected group from
|
||||
// the selected players list, in case the user deselects the
|
||||
@@ -181,6 +191,8 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
});
|
||||
},
|
||||
),
|
||||
|
||||
// Player selection widget.
|
||||
Expanded(
|
||||
child: PlayerSelection(
|
||||
key: ValueKey(selectedGroup?.id ?? 'no_group'),
|
||||
@@ -193,6 +205,8 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
// Create or save button.
|
||||
CustomWidthButton(
|
||||
text: buttonText,
|
||||
sizeRelativeToWidth: 0.95,
|
||||
@@ -218,16 +232,16 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
///
|
||||
/// Returns `true` if:
|
||||
/// - A ruleset is selected AND
|
||||
/// - Either a group is selected OR at least 2 players are selected
|
||||
/// - Either a group is selected OR at least 2 players are selected.
|
||||
bool _enableCreateGameButton() {
|
||||
return (selectedGroup != null ||
|
||||
(selectedPlayers.length > 1) && selectedGame != null);
|
||||
}
|
||||
|
||||
// If a match was provided to the view, it updates the match in the database
|
||||
// and navigates back to the previous screen.
|
||||
// If no match was provided, it creates a new match in the database and
|
||||
// navigates to the MatchResultView for the newly created match.
|
||||
/// Handles navigation when the create or save button is pressed.
|
||||
///
|
||||
/// If a match is being edited, updates the match in the database.
|
||||
/// Otherwise, creates a new match and navigates to the MatchResultView.
|
||||
void buttonNavigation(BuildContext context) async {
|
||||
if (isEditMode()) {
|
||||
await updateMatch();
|
||||
@@ -252,8 +266,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Updates attributes of the existing match in the database based on the
|
||||
/// changes made in the edit view.
|
||||
/// Updates the existing match in the database.
|
||||
Future<void> updateMatch() async {
|
||||
final updatedMatch = Match(
|
||||
id: widget.matchToEdit!.id,
|
||||
@@ -262,7 +275,7 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
: _matchNameController.text.trim(),
|
||||
group: selectedGroup,
|
||||
players: selectedPlayers,
|
||||
game: widget.matchToEdit!.game,
|
||||
game: selectedGame!,
|
||||
createdAt: widget.matchToEdit!.createdAt,
|
||||
endedAt: widget.matchToEdit!.endedAt,
|
||||
notes: widget.matchToEdit!.notes,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttericon/rpg_awesome_icons.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:tallee/core/adaptive_page_route.dart';
|
||||
@@ -14,6 +15,7 @@ import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||
import 'package:tallee/presentation/widgets/colored_icon_container.dart';
|
||||
import 'package:tallee/presentation/widgets/dialog/custom_alert_dialog.dart';
|
||||
import 'package:tallee/presentation/widgets/dialog/custom_dialog_action.dart';
|
||||
import 'package:tallee/presentation/widgets/game_label.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/info_tile.dart';
|
||||
import 'package:tallee/presentation/widgets/tiles/text_icon_tile.dart';
|
||||
|
||||
@@ -102,6 +104,7 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
bottom: 100,
|
||||
),
|
||||
children: [
|
||||
// Controller Icon
|
||||
const Center(
|
||||
child: ColoredIconContainer(
|
||||
icon: Icons.sports_esports,
|
||||
@@ -110,6 +113,8 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// Match Name
|
||||
Text(
|
||||
match.name,
|
||||
style: const TextStyle(
|
||||
@@ -120,6 +125,8 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 5),
|
||||
|
||||
// Creation Date
|
||||
Text(
|
||||
'${loc.created_on} ${DateFormat.yMMMd(Localizations.localeOf(context).toString()).format(match.createdAt)}',
|
||||
style: const TextStyle(
|
||||
@@ -129,6 +136,8 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// Group Name
|
||||
if (match.group != null) ...[
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
@@ -143,6 +152,8 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
|
||||
// Players
|
||||
InfoTile(
|
||||
title: loc.players,
|
||||
icon: Icons.people,
|
||||
@@ -162,6 +173,30 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// Game
|
||||
InfoTile(
|
||||
title: loc.game,
|
||||
icon: RpgAwesome.clovers_card,
|
||||
horizontalAlignment: CrossAxisAlignment.start,
|
||||
content: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 4,
|
||||
horizontal: 8,
|
||||
),
|
||||
child: GameLabel(
|
||||
title: match.game.name,
|
||||
description: translateRulesetToString(
|
||||
match.game.ruleset,
|
||||
context,
|
||||
),
|
||||
color: match.game.color,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 15),
|
||||
|
||||
// Results
|
||||
InfoTile(
|
||||
title: loc.results,
|
||||
icon: Icons.emoji_events,
|
||||
|
||||
@@ -126,8 +126,10 @@ class _MatchViewState extends State<MatchView> {
|
||||
Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
builder: (context) =>
|
||||
CreateMatchView(onWinnerChanged: loadMatches),
|
||||
builder: (context) => CreateMatchView(
|
||||
onWinnerChanged: loadMatches,
|
||||
onMatchesUpdated: loadMatches,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -55,6 +55,7 @@ const allDependencies = <Package>[
|
||||
_flutter_lints,
|
||||
_flutter_localizations,
|
||||
_flutter_plugin_android_lifecycle,
|
||||
_flutter_popup,
|
||||
_flutter_test,
|
||||
_flutter_web_plugins,
|
||||
_fluttericon,
|
||||
@@ -168,6 +169,7 @@ const dependencies = <Package>[
|
||||
_file_saver,
|
||||
_flutter,
|
||||
_flutter_localizations,
|
||||
_flutter_popup,
|
||||
_fluttericon,
|
||||
_font_awesome_flutter,
|
||||
_intl,
|
||||
@@ -2628,6 +2630,41 @@ ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.''',
|
||||
);
|
||||
|
||||
/// flutter_popup 3.3.9
|
||||
const _flutter_popup = Package(
|
||||
name: 'flutter_popup',
|
||||
description: 'The flutter_popup package is a versatile tool for creating customizable popups in Flutter apps. Its highlight feature effectively guides user attention to specific areas',
|
||||
homepage: 'https://github.com/herowws/flutter_popup',
|
||||
authors: [],
|
||||
version: '3.3.9',
|
||||
spdxIdentifiers: ['MIT'],
|
||||
isMarkdown: false,
|
||||
isSdk: false,
|
||||
dependencies: [PackageRef('flutter')],
|
||||
devDependencies: [PackageRef('flutter_lints'), PackageRef('flutter_test')],
|
||||
license: '''MIT License
|
||||
|
||||
Copyright (c) 2023 mopriestt
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.''',
|
||||
);
|
||||
|
||||
/// flutter_test null
|
||||
const _flutter_test = Package(
|
||||
name: 'flutter_test',
|
||||
@@ -37676,16 +37713,16 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.''',
|
||||
);
|
||||
|
||||
/// tallee 0.0.27+261
|
||||
/// tallee 0.0.28+262
|
||||
const _tallee = Package(
|
||||
name: 'tallee',
|
||||
description: 'Tracking App for Card Games',
|
||||
authors: [],
|
||||
version: '0.0.27+261',
|
||||
version: '0.0.28+262',
|
||||
spdxIdentifiers: ['LGPL-3.0'],
|
||||
isMarkdown: false,
|
||||
isSdk: false,
|
||||
dependencies: [PackageRef('clock'), PackageRef('collection'), PackageRef('cupertino_icons'), PackageRef('drift'), PackageRef('drift_flutter'), PackageRef('file_picker'), PackageRef('file_saver'), PackageRef('flutter'), PackageRef('flutter_localizations'), PackageRef('fluttericon'), PackageRef('font_awesome_flutter'), PackageRef('intl'), PackageRef('json_schema'), PackageRef('package_info_plus'), PackageRef('path_provider'), PackageRef('provider'), PackageRef('skeletonizer'), PackageRef('url_launcher'), PackageRef('uuid')],
|
||||
dependencies: [PackageRef('clock'), PackageRef('collection'), PackageRef('cupertino_icons'), PackageRef('drift'), PackageRef('drift_flutter'), PackageRef('file_picker'), PackageRef('file_saver'), PackageRef('flutter'), PackageRef('flutter_localizations'), PackageRef('flutter_popup'), PackageRef('fluttericon'), PackageRef('font_awesome_flutter'), PackageRef('intl'), PackageRef('json_schema'), PackageRef('package_info_plus'), PackageRef('path_provider'), PackageRef('provider'), PackageRef('skeletonizer'), PackageRef('url_launcher'), PackageRef('uuid')],
|
||||
devDependencies: [PackageRef('flutter_test'), PackageRef('build_runner'), PackageRef('dart_pubspec_licenses'), PackageRef('drift_dev'), PackageRef('flutter_lints')],
|
||||
license: '''GNU LESSER GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Reference in New Issue
Block a user