felix mach jetzt
This commit is contained in:
@@ -37,9 +37,23 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
db = Provider.of<AppDatabase>(context, listen: false);
|
db = Provider.of<AppDatabase>(context, listen: false);
|
||||||
|
_searchBarController.addListener(() {
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
|
_groupNameController.addListener(() {
|
||||||
|
setState(() {});
|
||||||
|
});
|
||||||
loadPlayerList();
|
loadPlayerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_groupNameController.dispose();
|
||||||
|
_searchBarController
|
||||||
|
.dispose(); // Listener entfernen und Controller aufräumen
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
void loadPlayerList() {
|
void loadPlayerList() {
|
||||||
_allPlayersFuture = db.playerDao.getAllPlayers();
|
_allPlayersFuture = db.playerDao.getAllPlayers();
|
||||||
_allPlayersFuture.then((loadedPlayers) {
|
_allPlayersFuture.then((loadedPlayers) {
|
||||||
@@ -104,40 +118,16 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
),
|
),
|
||||||
hintText: 'Search for players',
|
hintText: 'Search for players',
|
||||||
trailingButtonShown: true,
|
trailingButtonShown: true,
|
||||||
trailingButtonEnabled:
|
trailingButtonEnabled: _searchBarController.text
|
||||||
_searchBarController.text.isNotEmpty,
|
.trim()
|
||||||
|
.isNotEmpty,
|
||||||
onTrailingButtonPressed: () async {
|
onTrailingButtonPressed: () async {
|
||||||
String playerName = _searchBarController.text.trim();
|
addNewPlayerFromSearch(
|
||||||
if (playerName.isEmpty) return;
|
context,
|
||||||
bool success = await db.playerDao.addPlayer(
|
_searchBarController,
|
||||||
player: Player(name: playerName),
|
db,
|
||||||
|
loadPlayerList,
|
||||||
);
|
);
|
||||||
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),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
_searchBarController.clear();
|
|
||||||
} else {
|
|
||||||
SnackBar(
|
|
||||||
backgroundColor: CustomTheme.boxColor,
|
|
||||||
content: Center(
|
|
||||||
child: Text(
|
|
||||||
'Could not add player $playerName.',
|
|
||||||
style: const TextStyle(color: Colors.white),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -347,3 +337,41 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addNewPlayerFromSearch(
|
||||||
|
context,
|
||||||
|
searchBarController,
|
||||||
|
db,
|
||||||
|
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),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
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),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -28,12 +28,13 @@ class CustomSearchBar extends StatelessWidget {
|
|||||||
constraints:
|
constraints:
|
||||||
constraints ?? const BoxConstraints(maxHeight: 45, minHeight: 45),
|
constraints ?? const BoxConstraints(maxHeight: 45, minHeight: 45),
|
||||||
hintText: hintText,
|
hintText: hintText,
|
||||||
onChanged: onChanged,
|
onChanged: trailingButtonEnabled ? onChanged : null,
|
||||||
hintStyle: WidgetStateProperty.all(const TextStyle(fontSize: 16)),
|
hintStyle: WidgetStateProperty.all(const TextStyle(fontSize: 16)),
|
||||||
leading: const Icon(Icons.search),
|
leading: const Icon(Icons.search),
|
||||||
trailing: trailingButtonShown
|
trailing: [
|
||||||
? [
|
Visibility(
|
||||||
GestureDetector(
|
visible: trailingButtonShown,
|
||||||
|
child: GestureDetector(
|
||||||
onTap: onTrailingButtonPressed,
|
onTap: onTrailingButtonPressed,
|
||||||
child: Icon(
|
child: Icon(
|
||||||
Icons.add_circle,
|
Icons.add_circle,
|
||||||
@@ -42,9 +43,9 @@ class CustomSearchBar extends StatelessWidget {
|
|||||||
: Colors.grey.withValues(alpha: 0.2),
|
: Colors.grey.withValues(alpha: 0.2),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
const SizedBox(width: 5),
|
const SizedBox(width: 5),
|
||||||
]
|
],
|
||||||
: null,
|
|
||||||
backgroundColor: WidgetStateProperty.all(CustomTheme.boxColor),
|
backgroundColor: WidgetStateProperty.all(CustomTheme.boxColor),
|
||||||
side: WidgetStateProperty.all(BorderSide(color: CustomTheme.boxBorder)),
|
side: WidgetStateProperty.all(BorderSide(color: CustomTheme.boxBorder)),
|
||||||
shape: WidgetStateProperty.all(
|
shape: WidgetStateProperty.all(
|
||||||
|
|||||||
Reference in New Issue
Block a user