Compare commits
7 Commits
feature/11
...
e3c39521a0
| Author | SHA1 | Date | |
|---|---|---|---|
| e3c39521a0 | |||
| b83719f16d | |||
| 4ae1432943 | |||
| feb2b756bd | |||
| bfad74db22 | |||
| 8e20fe1034 | |||
| 81aad9280c |
@@ -12,3 +12,7 @@ linter:
|
|||||||
unnecessary_const: true
|
unnecessary_const: true
|
||||||
lines_longer_than_80_chars: false
|
lines_longer_than_80_chars: false
|
||||||
constant_identifier_names: 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;
|
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(
|
||||||
@@ -144,32 +146,60 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
(_groupNameController.text.isEmpty ||
|
(_groupNameController.text.isEmpty ||
|
||||||
(selectedPlayers.length < 2))
|
(selectedPlayers.length < 2))
|
||||||
? null
|
? null
|
||||||
: () async {
|
: _saveGroup,
|
||||||
late Group? updatedGroup;
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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 {
|
||||||
|
final loc = AppLocalizations.of(context);
|
||||||
|
Group? updatedGroup;
|
||||||
|
bool successfullNameChange = true;
|
||||||
|
bool successfullMemberChange = true;
|
||||||
late bool success;
|
late bool success;
|
||||||
|
|
||||||
|
final groupName = _groupNameController.text.trim();
|
||||||
|
|
||||||
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: groupName,
|
||||||
|
description: '',
|
||||||
members: selectedPlayers,
|
members: selectedPlayers,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
updatedGroup = Group(
|
updatedGroup = Group(
|
||||||
id: widget.groupToEdit!.id,
|
id: widget.groupToEdit!.id,
|
||||||
name: _groupNameController.text.trim(),
|
name: groupName,
|
||||||
description: '',
|
description: '',
|
||||||
members: selectedPlayers,
|
members: selectedPlayers,
|
||||||
);
|
);
|
||||||
//TODO: Implement group editing in database
|
if (widget.groupToEdit!.name != groupName) {
|
||||||
/*
|
successfullNameChange = await db.groupDao.updateGroupName(
|
||||||
success = await db.groupDao.updateGroup(
|
groupId: widget.groupToEdit!.id,
|
||||||
group: updatedGroup,
|
newName: groupName,
|
||||||
);
|
);
|
||||||
*/
|
|
||||||
success = true;
|
|
||||||
}
|
}
|
||||||
if (!context.mounted) return;
|
|
||||||
|
if (widget.groupToEdit!.members != selectedPlayers) {
|
||||||
|
successfullMemberChange = await db.groupDao.replaceGroupPlayers(
|
||||||
|
groupId: widget.groupToEdit!.id,
|
||||||
|
newPlayers: selectedPlayers,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
success = successfullNameChange && successfullMemberChange;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mounted) return;
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
Navigator.pop(context, updatedGroup);
|
Navigator.pop(context, updatedGroup);
|
||||||
} else {
|
} else {
|
||||||
@@ -179,14 +209,6 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
: loc.error_editing_group,
|
: loc.error_editing_group,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Displays a snackbar with the given message and optional action.
|
/// Displays a snackbar with the given message and optional action.
|
||||||
|
|||||||
Reference in New Issue
Block a user