Compare commits
3 Commits
feature/11
...
bfad74db22
| Author | SHA1 | Date | |
|---|---|---|---|
| bfad74db22 | |||
| 8e20fe1034 | |||
| 81aad9280c |
@@ -205,8 +205,6 @@ class GroupDao extends DatabaseAccessor<AppDatabase> with _$GroupDaoMixin {
|
|||||||
return rowsAffected > 0;
|
return rowsAffected > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Retrieves the number of groups in the database.
|
/// Retrieves the number of groups in the database.
|
||||||
Future<int> getGroupCount() async {
|
Future<int> getGroupCount() async {
|
||||||
final count =
|
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.
|
/// Replaces all players in a group with the provided list of players.
|
||||||
/// Removes all existing players from the group and adds the new 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.
|
/// 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 String groupId,
|
||||||
required List<Player> newPlayers,
|
required List<Player> newPlayers,
|
||||||
}) async {
|
}) async {
|
||||||
|
if (!await groupExists(groupId: groupId)) return false;
|
||||||
|
|
||||||
await db.transaction(() async {
|
await db.transaction(() async {
|
||||||
// Remove all existing players from the group
|
// Remove all existing players from the group
|
||||||
final deleteQuery = delete(db.playerGroupTable)
|
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: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';
|
||||||
@@ -122,6 +123,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
child: TextInputField(
|
child: TextInputField(
|
||||||
controller: _groupNameController,
|
controller: _groupNameController,
|
||||||
hintText: loc.group_name,
|
hintText: loc.group_name,
|
||||||
|
maxLength: Constants.MAX_GROUP_NAME_LENGTH,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -145,12 +147,15 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
(selectedPlayers.length < 2))
|
(selectedPlayers.length < 2))
|
||||||
? null
|
? null
|
||||||
: () async {
|
: () async {
|
||||||
late Group? updatedGroup;
|
Group? updatedGroup;
|
||||||
|
bool successfullNameChange = true;
|
||||||
|
bool successfullMemberChange = true;
|
||||||
late bool success;
|
late bool success;
|
||||||
if (widget.groupToEdit == null) {
|
if (widget.groupToEdit == null) {
|
||||||
success = await db.groupDao.addGroup(
|
success = await db.groupDao.addGroup(
|
||||||
group: Group(
|
group: Group(
|
||||||
name: _groupNameController.text.trim(),
|
name: _groupNameController.text.trim(),
|
||||||
|
description: '',
|
||||||
members: selectedPlayers,
|
members: selectedPlayers,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -161,13 +166,24 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
description: '',
|
description: '',
|
||||||
members: selectedPlayers,
|
members: selectedPlayers,
|
||||||
);
|
);
|
||||||
//TODO: Implement group editing in database
|
if (widget.groupToEdit!.name !=
|
||||||
/*
|
_groupNameController.text.trim()) {
|
||||||
success = await db.groupDao.updateGroup(
|
successfullNameChange = await db.groupDao
|
||||||
group: updatedGroup,
|
.updateGroupName(
|
||||||
);
|
groupId: widget.groupToEdit!.id,
|
||||||
*/
|
newName: _groupNameController.text.trim(),
|
||||||
success = true;
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (widget.groupToEdit!.members != selectedPlayers) {
|
||||||
|
successfullMemberChange = await db.groupDao
|
||||||
|
.replaceGroupPlayers(
|
||||||
|
groupId: widget.groupToEdit!.id,
|
||||||
|
newPlayers: selectedPlayers,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
success =
|
||||||
|
successfullNameChange && successfullMemberChange;
|
||||||
}
|
}
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
if (success) {
|
if (success) {
|
||||||
|
|||||||
Reference in New Issue
Block a user