diff --git a/lib/presentation/views/main_menu/create_group_view.dart b/lib/presentation/views/main_menu/create_group_view.dart index db8890f..45f5af8 100644 --- a/lib/presentation/views/main_menu/create_group_view.dart +++ b/lib/presentation/views/main_menu/create_group_view.dart @@ -37,6 +37,10 @@ class _CreateGroupViewState extends State { void initState() { super.initState(); db = Provider.of(context, listen: false); + loadPlayerList(); + } + + void loadPlayerList() { _allPlayersFuture = db.playerDao.getAllPlayers(); _allPlayersFuture.then((loadedPlayers) { setState(() { @@ -99,6 +103,41 @@ class _CreateGroupViewState extends State { minHeight: 45, ), hintText: 'Search for players', + trailingButtonShown: true, + trailingButtonEnabled: + _searchBarController.text.isNotEmpty, + onTrailingButtonPressed: () async { + String playerName = _searchBarController.text; + if (playerName.isEmpty) return; + bool success = await db.playerDao.addPlayer( + player: Player(name: playerName), + ); + if (success) { + loadPlayerList(); + ScaffoldMessenger.of(context).showSnackBar( + SnackBar( + backgroundColor: CustomTheme.boxColor, + content: Center( + child: Text( + 'Successfully added player $playerName.', + style: TextStyle(color: Colors.white), + ), + ), + ), + ); + _searchBarController.clear(); + } else { + SnackBar( + backgroundColor: CustomTheme.boxColor, + content: Center( + child: Text( + 'Could not add player $playerName.', + style: TextStyle(color: Colors.white), + ), + ), + ); + } + }, onChanged: (value) { setState(() { if (value.isEmpty) {