WIP: Bearbeiten und Löschen von Matches #171
@@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:tallee/core/adaptive_page_route.dart';
|
import 'package:tallee/core/adaptive_page_route.dart';
|
||||||
import 'package:tallee/core/custom_theme.dart';
|
import 'package:tallee/core/custom_theme.dart';
|
||||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/group_view/groups_view.dart';
|
import 'package:tallee/presentation/views/main_menu/group_view/group_view.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/home_view.dart';
|
import 'package:tallee/presentation/views/main_menu/home_view.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/match_view/match_view.dart';
|
import 'package:tallee/presentation/views/main_menu/match_view/match_view.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/settings_view/settings_view.dart';
|
import 'package:tallee/presentation/views/main_menu/settings_view/settings_view.dart';
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:tallee/core/constants.dart';
|
|
||||||
import 'package:tallee/core/custom_theme.dart';
|
import 'package:tallee/core/custom_theme.dart';
|
||||||
import 'package:tallee/core/enums.dart';
|
import 'package:tallee/core/enums.dart';
|
||||||
import 'package:tallee/data/db/database.dart';
|
import 'package:tallee/data/db/database.dart';
|
||||||
@@ -66,7 +65,16 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
child: Scaffold(
|
child: Scaffold(
|
||||||
resizeToAvoidBottomInset: false,
|
resizeToAvoidBottomInset: false,
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
appBar: AppBar(title: Text(widget.groupToEdit == null ? loc.create_new_group : loc.edit_group), actions: widget.groupToEdit == null ? [] : [IconButton(icon: const Icon(Icons.delete), onPressed: () async {
|
appBar: AppBar(
|
||||||
|
title: Text(
|
||||||
|
widget.groupToEdit == null ? loc.create_new_group : loc.edit_group,
|
||||||
|
),
|
||||||
|
actions: widget.groupToEdit == null
|
||||||
|
? []
|
||||||
|
: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.delete),
|
||||||
|
onPressed: () async {
|
||||||
if (widget.groupToEdit != null) {
|
if (widget.groupToEdit != null) {
|
||||||
showDialog<bool>(
|
showDialog<bool>(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -75,18 +83,22 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
content: Text(loc.this_cannot_be_undone),
|
content: Text(loc.this_cannot_be_undone),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(false),
|
onPressed: () =>
|
||||||
|
Navigator.of(context).pop(false),
|
||||||
child: Text(loc.cancel),
|
child: Text(loc.cancel),
|
||||||
),
|
),
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(true),
|
onPressed: () =>
|
||||||
|
Navigator.of(context).pop(true),
|
||||||
child: Text(loc.delete),
|
child: Text(loc.delete),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
).then((confirmed) async {
|
).then((confirmed) async {
|
||||||
if (confirmed == true && context.mounted) {
|
if (confirmed == true && context.mounted) {
|
||||||
bool success = await db.groupDao.deleteGroup(groupId: widget.groupToEdit!.id);
|
bool success = await db.groupDao.deleteGroup(
|
||||||
|
groupId: widget.groupToEdit!.id,
|
||||||
|
);
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
if (success) {
|
if (success) {
|
||||||
Navigator.pop(context);
|
Navigator.pop(context);
|
||||||
@@ -97,7 +109,10 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},)],),
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
body: SafeArea(
|
body: SafeArea(
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
@@ -120,7 +135,9 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
CustomWidthButton(
|
CustomWidthButton(
|
||||||
text: widget.groupToEdit == null ? loc.create_group : loc.edit_group,
|
text: widget.groupToEdit == null
|
||||||
|
? loc.create_group
|
||||||
|
: loc.edit_group,
|
||||||
sizeRelativeToWidth: 0.95,
|
sizeRelativeToWidth: 0.95,
|
||||||
buttonType: ButtonType.primary,
|
buttonType: ButtonType.primary,
|
||||||
onPressed:
|
onPressed:
|
||||||
@@ -155,7 +172,11 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
if (success) {
|
if (success) {
|
||||||
Navigator.pop(context, updatedGroup);
|
Navigator.pop(context, updatedGroup);
|
||||||
} else {
|
} else {
|
||||||
showSnackbar(message: widget.groupToEdit == null ? loc.error_creating_group : loc.error_editing_group);
|
showSnackbar(
|
||||||
|
message: widget.groupToEdit == null
|
||||||
|
? loc.error_creating_group
|
||||||
|
: loc.error_editing_group,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@@ -166,12 +187,11 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Displays a snackbar with the given message and optional action.
|
/// Displays a snackbar with the given message and optional action.
|
||||||
///
|
///
|
||||||
/// [message] The message to display in the snackbar.
|
/// [message] The message to display in the snackbar.
|
||||||
void showSnackbar({
|
void showSnackbar({required String message}) {
|
||||||
required String message,
|
|
||||||
}) {
|
|
||||||
final messenger = _scaffoldMessengerKey.currentState;
|
final messenger = _scaffoldMessengerKey.currentState;
|
||||||
if (messenger != null) {
|
if (messenger != null) {
|
||||||
messenger.hideCurrentSnackBar();
|
messenger.hideCurrentSnackBar();
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:tallee/core/adaptive_page_route.dart';
|
||||||
import 'package:tallee/core/custom_theme.dart';
|
import 'package:tallee/core/custom_theme.dart';
|
||||||
import 'package:tallee/data/db/database.dart';
|
import 'package:tallee/data/db/database.dart';
|
||||||
import 'package:tallee/data/dto/group.dart';
|
import 'package:tallee/data/dto/group.dart';
|
||||||
import 'package:tallee/data/dto/match.dart';
|
import 'package:tallee/data/dto/match.dart';
|
||||||
import 'package:tallee/data/dto/player.dart';
|
import 'package:tallee/data/dto/player.dart';
|
||||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||||
|
import 'package:tallee/presentation/views/main_menu/group_view/create_group_view.dart';
|
||||||
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
||||||
import 'package:tallee/presentation/widgets/buttons/animated_dialog_button.dart';
|
import 'package:tallee/presentation/widgets/buttons/animated_dialog_button.dart';
|
||||||
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||||
@@ -189,9 +191,7 @@ class _GroupDetailViewState extends State<GroupDetailView> {
|
|||||||
context,
|
context,
|
||||||
adaptivePageRoute(
|
adaptivePageRoute(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
return CreateGroupView(
|
return CreateGroupView(groupToEdit: _group);
|
||||||
groupToEdit: _group,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -243,8 +243,9 @@ class _GroupDetailViewState extends State<GroupDetailView> {
|
|||||||
/// Loads statistics for this group
|
/// Loads statistics for this group
|
||||||
Future<void> _loadStatistics() async {
|
Future<void> _loadStatistics() async {
|
||||||
final matches = await db.matchDao.getAllMatches();
|
final matches = await db.matchDao.getAllMatches();
|
||||||
final groupMatches =
|
final groupMatches = matches
|
||||||
matches.where((match) => match.group?.id == _group.id).toList();
|
.where((match) => match.group?.id == _group.id)
|
||||||
|
.toList();
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
totalMatches = groupMatches.length;
|
totalMatches = groupMatches.length;
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import 'package:tallee/data/dto/group.dart';
|
|||||||
import 'package:tallee/data/dto/player.dart';
|
import 'package:tallee/data/dto/player.dart';
|
||||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/group_view/create_group_view.dart';
|
import 'package:tallee/presentation/views/main_menu/group_view/create_group_view.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/group_view/group_profile_view.dart';
|
import 'package:tallee/presentation/views/main_menu/group_view/group_detail_view.dart';
|
||||||
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
||||||
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||||
import 'package:tallee/presentation/widgets/tiles/group_tile.dart';
|
import 'package:tallee/presentation/widgets/tiles/group_tile.dart';
|
||||||
|
|||||||
@@ -266,14 +266,4 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines whether the "Create Match" button should be enabled.
|
|
||||||
///
|
|
||||||
/// Returns `true` if:
|
|
||||||
/// - A ruleset is selected AND
|
|
||||||
/// - Either a group is selected OR at least 2 players are selected
|
|
||||||
bool _enableCreateGameButton() {
|
|
||||||
return (selectedGroup != null ||
|
|
||||||
(selectedPlayers != null && selectedPlayers!.length > 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:game_tracker/core/adaptive_page_route.dart';
|
|
||||||
import 'package:game_tracker/core/custom_theme.dart';
|
|
||||||
import 'package:game_tracker/data/db/database.dart';
|
|
||||||
import 'package:game_tracker/data/dto/match.dart';
|
|
||||||
import 'package:game_tracker/data/dto/player.dart';
|
|
||||||
import 'package:game_tracker/l10n/generated/app_localizations.dart';
|
|
||||||
import 'package:game_tracker/presentation/views/main_menu/match_view/create_match/create_match_view.dart';
|
|
||||||
import 'package:game_tracker/presentation/views/main_menu/match_view/match_result_view.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/buttons/animated_dialog_button.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/buttons/main_menu_button.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/colored_icon_container.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/custom_alert_dialog.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/info_tile.dart';
|
|
||||||
import 'package:game_tracker/presentation/widgets/tiles/text_icon_tile.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:tallee/core/adaptive_page_route.dart';
|
||||||
|
import 'package:tallee/core/custom_theme.dart';
|
||||||
|
import 'package:tallee/data/db/database.dart';
|
||||||
|
import 'package:tallee/data/dto/match.dart';
|
||||||
|
import 'package:tallee/data/dto/player.dart';
|
||||||
|
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||||
|
import 'package:tallee/presentation/views/main_menu/match_view/create_match/create_match_view.dart';
|
||||||
|
import 'package:tallee/presentation/views/main_menu/match_view/match_result_view.dart';
|
||||||
|
import 'package:tallee/presentation/widgets/buttons/animated_dialog_button.dart';
|
||||||
|
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||||
|
import 'package:tallee/presentation/widgets/colored_icon_container.dart';
|
||||||
|
import 'package:tallee/presentation/widgets/custom_alert_dialog.dart';
|
||||||
|
import 'package:tallee/presentation/widgets/tiles/info_tile.dart';
|
||||||
|
import 'package:tallee/presentation/widgets/tiles/text_icon_tile.dart';
|
||||||
|
|
||||||
class MatchDetailView extends StatefulWidget {
|
class MatchDetailView extends StatefulWidget {
|
||||||
/// A view that displays the profile of a match
|
/// A view that displays the profile of a match
|
||||||
@@ -81,7 +81,9 @@ class _MatchDetailViewState extends State<MatchDetailView> {
|
|||||||
onPressed: () => Navigator.of(context).pop(true),
|
onPressed: () => Navigator.of(context).pop(true),
|
||||||
child: Text(
|
child: Text(
|
||||||
loc.delete,
|
loc.delete,
|
||||||
style: TextStyle(color: CustomTheme.secondaryColor),
|
style: const TextStyle(
|
||||||
|
color: CustomTheme.secondaryColor,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import 'package:tallee/data/dto/match.dart';
|
|||||||
import 'package:tallee/data/dto/player.dart';
|
import 'package:tallee/data/dto/player.dart';
|
||||||
import 'package:tallee/l10n/generated/app_localizations.dart';
|
import 'package:tallee/l10n/generated/app_localizations.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/match_view/create_match/create_match_view.dart';
|
import 'package:tallee/presentation/views/main_menu/match_view/create_match/create_match_view.dart';
|
||||||
import 'package:tallee/presentation/views/main_menu/match_view/match_result_view.dart';
|
import 'package:tallee/presentation/views/main_menu/match_view/match_detail_view.dart';
|
||||||
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
import 'package:tallee/presentation/widgets/app_skeleton.dart';
|
||||||
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
import 'package:tallee/presentation/widgets/buttons/main_menu_button.dart';
|
||||||
import 'package:tallee/presentation/widgets/tiles/match_tile.dart';
|
import 'package:tallee/presentation/widgets/tiles/match_tile.dart';
|
||||||
|
|||||||
Reference in New Issue
Block a user