Merge branch 'development' into feature/6-statisticsview-erstellen
This commit is contained in:
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,19 +66,19 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return Scaffold(
|
||||||
child: Scaffold(
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
|
appBar: AppBar(
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
backgroundColor: CustomTheme.backgroundColor,
|
||||||
appBar: AppBar(
|
scrolledUnderElevation: 0,
|
||||||
backgroundColor: CustomTheme.backgroundColor,
|
title: const Text(
|
||||||
scrolledUnderElevation: 0,
|
'Create new group',
|
||||||
title: const Text(
|
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
||||||
'Create new group',
|
|
||||||
style: TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
centerTitle: true,
|
|
||||||
),
|
),
|
||||||
body: Column(
|
centerTitle: true,
|
||||||
|
),
|
||||||
|
body: SafeArea(
|
||||||
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Container(
|
Container(
|
||||||
@@ -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,48 +333,47 @@ 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,
|
if (!context.mounted) return;
|
||||||
required TextEditingController searchBarController,
|
if (success) {
|
||||||
required AppDatabase db,
|
selectedPlayers.add(createdPlayer);
|
||||||
required Function loadPlayerList,
|
allPlayers.add(createdPlayer);
|
||||||
}) async {
|
setState(() {
|
||||||
String playerName = searchBarController.text.trim();
|
_searchBarController.clear();
|
||||||
bool success = await db.playerDao.addPlayer(player: Player(name: playerName));
|
suggestedPlayers = allPlayers.where((player) {
|
||||||
if (!context.mounted) return;
|
return !selectedPlayers.contains(player);
|
||||||
if (success) {
|
}).toList();
|
||||||
loadPlayerList();
|
});
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
backgroundColor: CustomTheme.boxColor,
|
backgroundColor: CustomTheme.boxColor,
|
||||||
content: Center(
|
content: Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
'Successfully added player $playerName.',
|
'Successfully added player $playerName.',
|
||||||
style: const TextStyle(color: Colors.white),
|
style: const TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
} else {
|
||||||
searchBarController.clear();
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
} else {
|
SnackBar(
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
backgroundColor: CustomTheme.boxColor,
|
||||||
SnackBar(
|
content: Center(
|
||||||
backgroundColor: CustomTheme.boxColor,
|
child: Text(
|
||||||
content: Center(
|
'Could not add player $playerName.',
|
||||||
child: Text(
|
style: const TextStyle(color: Colors.white),
|
||||||
'Could not add player $playerName.',
|
),
|
||||||
style: const TextStyle(color: Colors.white),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,9 +69,9 @@ class _GroupsViewState extends State<GroupsView> {
|
|||||||
}
|
}
|
||||||
final bool isLoading =
|
final bool isLoading =
|
||||||
snapshot.connectionState == ConnectionState.waiting;
|
snapshot.connectionState == ConnectionState.waiting;
|
||||||
final List<Group> groups = isLoading
|
final List<Group> groups =
|
||||||
? skeletonData
|
isLoading ? skeletonData : (snapshot.data ?? [])
|
||||||
: (snapshot.data ?? []);
|
..sort((a, b) => b.createdAt.compareTo(a.createdAt));
|
||||||
return Skeletonizer(
|
return Skeletonizer(
|
||||||
effect: PulseEffect(
|
effect: PulseEffect(
|
||||||
from: Colors.grey[800]!,
|
from: Colors.grey[800]!,
|
||||||
@@ -93,7 +93,9 @@ class _GroupsViewState extends State<GroupsView> {
|
|||||||
itemCount: groups.length + 1,
|
itemCount: groups.length + 1,
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
if (index == groups.length) {
|
if (index == groups.length) {
|
||||||
return const SizedBox(height: 60);
|
return SizedBox(
|
||||||
|
height: MediaQuery.paddingOf(context).bottom - 20,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return GroupTile(group: groups[index]);
|
return GroupTile(group: groups[index]);
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user