Rework data structure to map from list
This commit is contained in:
@@ -53,7 +53,7 @@ class MyHomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MyHomePageState extends State<MyHomePage> {
|
||||
late List<Game> games = [];
|
||||
late Map<String, Game> games = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -86,31 +86,33 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
spacing: 4,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
...games.map((game) => SizedBox(
|
||||
width: 400,
|
||||
child: GameCard(
|
||||
game: game,
|
||||
onGameUpdated: (game) async {
|
||||
game = await GameRepository.upsert(game);
|
||||
setState(() {
|
||||
games[games.indexOf(game)] = game;
|
||||
});
|
||||
},
|
||||
onDelete: () async {
|
||||
await GameRepository.delete(game);
|
||||
setState(() {
|
||||
games.remove(game);
|
||||
});
|
||||
},
|
||||
...games.values.map(
|
||||
(game) => SizedBox(
|
||||
width: 400,
|
||||
child: GameCard(
|
||||
game: game,
|
||||
onGameUpdated: (game) async {
|
||||
game = await GameRepository.upsert(game);
|
||||
setState(() {
|
||||
games[game.name] = game;
|
||||
});
|
||||
},
|
||||
onDelete: () async {
|
||||
await GameRepository.delete(game);
|
||||
setState(() {
|
||||
games.remove(game.name);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
)),
|
||||
),
|
||||
SizedBox(
|
||||
width: 400,
|
||||
child: NewGameCard(
|
||||
onGameCreated: (game) async {
|
||||
game = await GameRepository.upsert(game);
|
||||
setState(() {
|
||||
games.add(game);
|
||||
games[game.name] = game;
|
||||
});
|
||||
},
|
||||
),
|
||||
|
Reference in New Issue
Block a user