Bearbeiten und Löschen von Gruppen #148
@@ -146,56 +146,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
(_groupNameController.text.isEmpty ||
|
||||
(selectedPlayers.length < 2))
|
||||
? null
|
||||
: () async {
|
||||
Group? updatedGroup;
|
||||
bool successfullNameChange = true;
|
||||
bool successfullMemberChange = true;
|
||||
late bool success;
|
||||
if (widget.groupToEdit == null) {
|
||||
success = await db.groupDao.addGroup(
|
||||
group: Group(
|
||||
name: _groupNameController.text.trim(),
|
||||
description: '',
|
||||
members: selectedPlayers,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
updatedGroup = Group(
|
||||
id: widget.groupToEdit!.id,
|
||||
name: _groupNameController.text.trim(),
|
||||
description: '',
|
||||
members: selectedPlayers,
|
||||
);
|
||||
if (widget.groupToEdit!.name !=
|
||||
_groupNameController.text.trim()) {
|
||||
successfullNameChange = await db.groupDao
|
||||
.updateGroupName(
|
||||
groupId: widget.groupToEdit!.id,
|
||||
newName: _groupNameController.text.trim(),
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.groupToEdit!.members != selectedPlayers) {
|
||||
successfullMemberChange = await db.groupDao
|
||||
.replaceGroupPlayers(
|
||||
groupId: widget.groupToEdit!.id,
|
||||
newPlayers: selectedPlayers,
|
||||
);
|
||||
}
|
||||
success =
|
||||
successfullNameChange && successfullMemberChange;
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
if (success) {
|
||||
Navigator.pop(context, updatedGroup);
|
||||
} else {
|
||||
showSnackbar(
|
||||
message: widget.groupToEdit == null
|
||||
? loc.error_creating_group
|
||||
: loc.error_editing_group,
|
||||
);
|
||||
}
|
||||
},
|
||||
: _saveGroup,
|
||||
),
|
||||
|
sneeex marked this conversation as resolved
Outdated
|
||||
const SizedBox(height: 20),
|
||||
],
|
||||
@@ -205,6 +156,61 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Saves the group by creating a new one or updating the existing one,
|
||||
/// depending on whether the widget is in edit mode.
|
||||
Future<void> _saveGroup() async {
|
||||
|
sneeex marked this conversation as resolved
Outdated
flixcoo
commented
gerne die Methode nochmal aufteilen, wie bei mir in gerne die Methode nochmal aufteilen, wie bei mir in `CreateMatchView`:
```dart
void buttonNavigation(BuildContext context) async {
if (widget.matchToEdit != null) {
await updateMatch();
if (context.mounted) {
Navigator.pop(context);
}
} else {
final match = await createMatch();
if (context.mounted) {
Navigator.pushReplacement(
context,
adaptivePageRoute(
fullscreenDialog: true,
builder: (context) => MatchResultView(
match: match,
onWinnerChanged: widget.onWinnerChanged,
),
),
);
}
}
}
```
sneeex
commented
nö nö
|
||||
final loc = AppLocalizations.of(context);
|
||||
Group? updatedGroup;
|
||||
bool successfullNameChange = true;
|
||||
bool successfullMemberChange = true;
|
||||
late bool success;
|
||||
|
||||
final groupName = _groupNameController.text.trim();
|
||||
|
||||
if (widget.groupToEdit == null) {
|
||||
success = await db.groupDao.addGroup(
|
||||
group: Group(
|
||||
name: groupName,
|
||||
description: '',
|
||||
members: selectedPlayers,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
updatedGroup = Group(
|
||||
id: widget.groupToEdit!.id,
|
||||
name: groupName,
|
||||
description: '',
|
||||
members: selectedPlayers,
|
||||
);
|
||||
if (widget.groupToEdit!.name != groupName) {
|
||||
successfullNameChange = await db.groupDao.updateGroupName(
|
||||
groupId: widget.groupToEdit!.id,
|
||||
newName: groupName,
|
||||
);
|
||||
}
|
||||
|
||||
if (widget.groupToEdit!.members != selectedPlayers) {
|
||||
successfullMemberChange = await db.groupDao.replaceGroupPlayers(
|
||||
|
sneeex marked this conversation as resolved
Outdated
flixcoo
commented
Kurzen doc comment nochmal zu dieser Methode vllt Kurzen doc comment nochmal zu dieser Methode vllt
|
||||
groupId: widget.groupToEdit!.id,
|
||||
|
sneeex marked this conversation as resolved
Outdated
flixcoo
commented
Lieber Methode Lieber Methode `getMatchesToGroup()` in `groupDao.dart`, kann ggf. später auch noch einmal verwendet werden
sneeex
commented
hast das auch so gemacht hast das auch so gemacht
sneeex
commented
habs von dir kopiert habs von dir kopiert
flixcoo
commented
wo hab ich das gemacht? File und Zeile wo hab ich das gemacht? File und Zeile
sneeex
commented
flixcoo
commented
ja aber da diese vorgehensweise jetzt mehr als einmal im code ist machts erst recht sinn dafür ne methode zu schreiben und entsprechende vorkommen zu ersetzen ja aber da diese vorgehensweise jetzt mehr als einmal im code ist machts erst recht sinn dafür ne methode zu schreiben und entsprechende vorkommen zu ersetzen
|
||||
newPlayers: selectedPlayers,
|
||||
);
|
||||
}
|
||||
success = successfullNameChange && successfullMemberChange;
|
||||
}
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (success) {
|
||||
Navigator.pop(context, updatedGroup);
|
||||
} else {
|
||||
showSnackbar(
|
||||
message: widget.groupToEdit == null
|
||||
? loc.error_creating_group
|
||||
: loc.error_editing_group,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Displays a snackbar with the given message and optional action.
|
||||
///
|
||||
/// [message] The message to display in the snackbar.
|
||||
|
||||
Reference in New Issue
Block a user
Kompletten Code hier in mindestens eine Methode auslagern, falls sinnvoll auch mehrere