Compare commits
5 Commits
feature/11
...
4ae1432943
| Author | SHA1 | Date | |
|---|---|---|---|
| 4ae1432943 | |||
| feb2b756bd | |||
| bfad74db22 | |||
| 8e20fe1034 | |||
| 81aad9280c |
@@ -12,3 +12,7 @@ linter:
|
||||
unnecessary_const: true
|
||||
lines_longer_than_80_chars: false
|
||||
constant_identifier_names: false
|
||||
|
||||
analyzer:
|
||||
exclude:
|
||||
- lib/presentation/views/main_menu/settings_view/licenses/oss_licenses.dart
|
||||
|
||||
@@ -205,8 +205,6 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
return rowsAffected > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Retrieves the number of groups in the database.
|
||||
Future<int> getGroupCount() async {
|
||||
final count =
|
||||
@@ -235,10 +233,13 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
/// Replaces all players in a group with the provided list of players.
|
||||
/// Removes all existing players from the group and adds the new players.
|
||||
/// Also adds any new players to the player table if they don't exist.
|
||||
Future<void> replaceGroupPlayers({
|
||||
/// Returns `true` if the group exists and players were replaced, `false` otherwise.
|
||||
Future<bool> replaceGroupPlayers({
|
||||
required String groupId,
|
||||
required List<Player> newPlayers,
|
||||
}) async {
|
||||
if (!await groupExists(groupId: groupId)) return false;
|
||||
|
||||
await db.transaction(() async {
|
||||
// Remove all existing players from the group
|
||||
final deleteQuery = delete(db.playerGroupTable)
|
||||
@@ -270,5 +271,6 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
||||
),
|
||||
);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.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';
|
||||
@@ -122,6 +123,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
child: TextInputField(
|
||||
controller: _groupNameController,
|
||||
hintText: loc.group_name,
|
||||
maxLength: Constants.MAX_GROUP_NAME_LENGTH,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
@@ -145,12 +147,15 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
(selectedPlayers.length < 2))
|
||||
? null
|
||||
: () async {
|
||||
late Group? updatedGroup;
|
||||
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,
|
||||
),
|
||||
);
|
||||
@@ -161,13 +166,24 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
description: '',
|
||||
members: selectedPlayers,
|
||||
);
|
||||
//TODO: Implement group editing in database
|
||||
/*
|
||||
success = await db.groupDao.updateGroup(
|
||||
group: updatedGroup,
|
||||
);
|
||||
*/
|
||||
success = true;
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user