I'm starting to learn Flutter and I'm trying to write an application.
The application has a list of players in a ListView of SwitchListTile. This is working at the moment. I'm trying to add a function to delete one of the players from the lists.
class PlayersSwitchListTilesContainer extends StatelessWidget {
PlayersSwitchListTilesContainer({this.players});
final List<PlayerModel> players;
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children : players.map<Widget>((PlayerModel p){
return PlayerSwtichListTile(singlePlayer: p);
}).toList()
),
);
}
}
class PlayerSwtichListTile extends StatefulWidget {
PlayerSwtichListTile({this.singlePlayer});
final PlayerModel singlePlayer;
void removePlayer()
{
// What goes here ???
print('Delete ' + singlePlayer.playerName);
}
@override
_PlayerSwtichListTileState createState() => new _PlayerSwtichListTileState(player: singlePlayer);
}
At the moment, when I try to delete a player it calls the correct code and prints the player's name. However, I'm struggling to see how to delete the player from the players list.
I'd be grateful for any pointers anyone has