MVP #141
@@ -37,6 +37,10 @@ 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);
|
||||||
|
loadPlayerList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loadPlayerList() {
|
||||||
_allPlayersFuture = db.playerDao.getAllPlayers();
|
_allPlayersFuture = db.playerDao.getAllPlayers();
|
||||||
_allPlayersFuture.then((loadedPlayers) {
|
_allPlayersFuture.then((loadedPlayers) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -99,6 +103,41 @@ class _CreateGroupViewState extends State<CreateGroupView> {
|
|||||||
minHeight: 45,
|
minHeight: 45,
|
||||||
),
|
),
|
||||||
hintText: 'Search for players',
|
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) {
|
onChanged: (value) {
|
||||||
setState(() {
|
setState(() {
|
||||||
if (value.isEmpty) {
|
if (value.isEmpty) {
|
||||||
|
|||||||
Reference in New Issue
Block a user