MVP #141
@@ -49,8 +49,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_groupNameController.dispose();
|
_groupNameController.dispose();
|
||||||
_searchBarController
|
_searchBarController.dispose();
|
||||||
.dispose(); // Listener entfernen und Controller aufräumen
|
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,12 +122,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
.trim()
|
.trim()
|
||||||
.isNotEmpty,
|
.isNotEmpty,
|
||||||
onTrailingButtonPressed: () async {
|
onTrailingButtonPressed: () async {
|
||||||
addNewPlayerFromSearch(
|
addNewPlayerFromSearch(context: context);
|
||||||
context: context,
|
|
||||||
searchBarController: _searchBarController,
|
|
||||||
db: db,
|
|
||||||
loadPlayerList: loadPlayerList,
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -339,25 +333,24 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// Adds a new player to the database from the search bar input.
|
/// Adds a new player to the database from the search bar input.
|
||||||
/// Shows a snackbar indicating success or failure.
|
/// Shows a snackbar indicating success or failure.
|
||||||
/// [context] - BuildContext to show the snackbar.
|
/// [context] - BuildContext to show the snackbar.
|
||||||
/// [searchBarController] - TextEditingController of the search bar.
|
void addNewPlayerFromSearch({required BuildContext context}) async {
|
||||||
/// [db] - AppDatabase instance to interact with the database.
|
String playerName = _searchBarController.text.trim();
|
||||||
/// [loadPlayerList] - Function to reload the player list after adding.
|
Player createdPlayer = Player(name: playerName);
|
||||||
void addNewPlayerFromSearch({
|
bool success = await db.playerDao.addPlayer(player: createdPlayer);
|
||||||
required BuildContext context,
|
|
||||||
required TextEditingController searchBarController,
|
|
||||||
required AppDatabase db,
|
|
||||||
required Function loadPlayerList,
|
|
||||||
}) async {
|
|
||||||
String playerName = searchBarController.text.trim();
|
|
||||||
bool success = await db.playerDao.addPlayer(player: Player(name: playerName));
|
|
||||||
if (!context.mounted) return;
|
if (!context.mounted) return;
|
||||||
if (success) {
|
if (success) {
|
||||||
loadPlayerList();
|
selectedPlayers.add(createdPlayer);
|
||||||
|
allPlayers.add(createdPlayer);
|
||||||
|
setState(() {
|
||||||
|
_searchBarController.clear();
|
||||||
|
suggestedPlayers = allPlayers.where((player) {
|
||||||
|
return !selectedPlayers.contains(player);
|
||||||
|
}).toList();
|
||||||
|
});
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
backgroundColor: CustomTheme.boxColor,
|
backgroundColor: CustomTheme.boxColor,
|
||||||
@@ -369,7 +362,6 @@ void addNewPlayerFromSearch({
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
searchBarController.clear();
|
|
||||||
} else {
|
} else {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
@@ -383,4 +375,5 @@ void addNewPlayerFromSearch({
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user