Erstelle Spieler direkt zu ausgewählten Spielern, Gruppen Sortierung nach Timestamp + Bugfixes #49
@@ -49,8 +49,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
@override
|
||||
void dispose() {
|
||||
_groupNameController.dispose();
|
||||
_searchBarController
|
||||
.dispose(); // Listener entfernen und Controller aufräumen
|
||||
_searchBarController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -67,19 +66,19 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: Scaffold(
|
||||
return Scaffold(
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
appBar: AppBar(
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
appBar: AppBar(
|
||||
backgroundColor: CustomTheme.backgroundColor,
|
||||
scrolledUnderElevation: 0,
|
||||
title: const Text(
|
||||
'Create new group',
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
centerTitle: true,
|
||||
scrolledUnderElevation: 0,
|
||||
title: const Text(
|
||||
'Create new group',
|
||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||
),
|
||||
body: Column(
|
||||
centerTitle: true,
|
||||
),
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
@@ -123,12 +122,7 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
.trim()
|
||||
.isNotEmpty,
|
||||
onTrailingButtonPressed: () async {
|
||||
addNewPlayerFromSearch(
|
||||
context: context,
|
||||
searchBarController: _searchBarController,
|
||||
db: db,
|
||||
loadPlayerList: loadPlayerList,
|
||||
);
|
||||
addNewPlayerFromSearch(context: context);
|
||||
},
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
@@ -339,48 +333,47 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Adds a new player to the database from the search bar input.
|
||||
/// Shows a snackbar indicating success or failure.
|
||||
/// [context] - BuildContext to show the snackbar.
|
||||
/// [searchBarController] - TextEditingController of the search bar.
|
||||
/// [db] - AppDatabase instance to interact with the database.
|
||||
/// [loadPlayerList] - Function to reload the player list after adding.
|
||||
void addNewPlayerFromSearch({
|
||||
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 (success) {
|
||||
loadPlayerList();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: CustomTheme.boxColor,
|
||||
content: Center(
|
||||
child: Text(
|
||||
'Successfully added player $playerName.',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
/// Adds a new player to the database from the search bar input.
|
||||
/// Shows a snackbar indicating success or failure.
|
||||
/// [context] - BuildContext to show the snackbar.
|
||||
void addNewPlayerFromSearch({required BuildContext context}) async {
|
||||
String playerName = _searchBarController.text.trim();
|
||||
Player createdPlayer = Player(name: playerName);
|
||||
bool success = await db.playerDao.addPlayer(player: createdPlayer);
|
||||
if (!context.mounted) return;
|
||||
if (success) {
|
||||
selectedPlayers.add(createdPlayer);
|
||||
allPlayers.add(createdPlayer);
|
||||
setState(() {
|
||||
_searchBarController.clear();
|
||||
suggestedPlayers = allPlayers.where((player) {
|
||||
return !selectedPlayers.contains(player);
|
||||
}).toList();
|
||||
});
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: CustomTheme.boxColor,
|
||||
content: Center(
|
||||
child: Text(
|
||||
'Successfully added player $playerName.',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
searchBarController.clear();
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: CustomTheme.boxColor,
|
||||
content: Center(
|
||||
child: Text(
|
||||
'Could not add player $playerName.',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
);
|
||||
} else {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: CustomTheme.boxColor,
|
||||
content: Center(
|
||||
child: Text(
|
||||
'Could not add player $playerName.',
|
||||
style: const TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,9 +69,9 @@ class _GroupsViewState extends State<GroupsView> {
|
||||
}
|
||||
final bool isLoading =
|
||||
snapshot.connectionState == ConnectionState.waiting;
|
||||
final List<Group> groups = isLoading
|
||||
? skeletonData
|
||||
: (snapshot.data ?? []);
|
||||
final List<Group> groups =
|
||||
isLoading ? skeletonData : (snapshot.data ?? [])
|
||||
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||
return Skeletonizer(
|
||||
effect: PulseEffect(
|
||||
from: Colors.grey[800]!,
|
||||
@@ -93,7 +93,9 @@ class _GroupsViewState extends State<GroupsView> {
|
||||
itemCount: groups.length + 1,
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
if (index == groups.length) {
|
||||
return const SizedBox(height: 60);
|
||||
return SizedBox(
|
||||
height: MediaQuery.paddingOf(context).bottom - 20,
|
||||
);
|
||||
}
|
||||
return GroupTile(group: groups[index]);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user