Added match editing
This commit is contained in:
@@ -20,11 +20,14 @@ import 'package:provider/provider.dart';
|
||||
class CreateMatchView extends StatefulWidget {
|
||||
/// A view that allows creating a new match
|
||||
/// [onWinnerChanged]: Optional callback invoked when the winner is changed
|
||||
const CreateMatchView({super.key, this.onWinnerChanged});
|
||||
const CreateMatchView({super.key, this.onWinnerChanged, this.match});
|
||||
|
||||
/// Optional callback invoked when the winner is changed
|
||||
final VoidCallback? onWinnerChanged;
|
||||
|
||||
/// An optional match to prefill the fields
|
||||
final Match? match;
|
||||
|
||||
@override
|
||||
State<CreateMatchView> createState() => _CreateMatchViewState();
|
||||
}
|
||||
@@ -83,6 +86,19 @@ class _CreateMatchViewState extends State<CreateMatchView> {
|
||||
filteredPlayerList = List.from(playerList);
|
||||
});
|
||||
});
|
||||
|
||||
if (widget.match != null) {
|
||||
final match = widget.match!;
|
||||
_matchNameController.text = match.name;
|
||||
selectedGroup = match.group;
|
||||
selectedGroupId = match.group?.id ?? '';
|
||||
selectedPlayers = match.players ?? [];
|
||||
if (selectedGroup != null) {
|
||||
filteredPlayerList = playerList
|
||||
.where((p) => !selectedGroup!.members.any((m) => m.id == p.id))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -5,6 +5,7 @@ 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';
|
||||
@@ -218,7 +219,17 @@ class _MatchProfileViewState extends State<MatchProfileView> {
|
||||
bottom: MediaQuery.paddingOf(context).bottom,
|
||||
child: Row(
|
||||
children: [
|
||||
MainMenuButton(icon: Icons.edit, onPressed: () {}),
|
||||
MainMenuButton(
|
||||
icon: Icons.edit,
|
||||
onPressed: () => Navigator.push(
|
||||
context,
|
||||
adaptivePageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (context) =>
|
||||
CreateMatchView(match: widget.match),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 15),
|
||||
MainMenuButton(
|
||||
text: loc.enter_results,
|
||||
|
||||
Reference in New Issue
Block a user