can toggle heart icon

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2022-12-16 07:54:10 -06:00
parent 9d569531b6
commit 4a842d1698
1 changed files with 10 additions and 2 deletions

View File

@ -36,7 +36,7 @@ class MyApp extends StatelessWidget {
class _RandomWordsState extends State<RandomWords> {
final _suggestions = <WordPair>[];
final _saved = <WordPair>{}; // NEW
final _biggerFont = const TextStyle(fontSize: 24);
final _biggerFont = const TextStyle(fontSize: 36);
// #enddocregion RWS-var
// #docregion RWS-build
@ -64,7 +64,15 @@ class _RandomWordsState extends State<RandomWords> {
color: alreadySaved ? Colors.red : null,
semanticLabel: alreadySaved ? 'Remove from saved' : 'Save',
),
);
onTap: () { // NEW from here ...
setState(() {
if (alreadySaved) {
_saved.remove(_suggestions[index]);
} else {
_saved.add(_suggestions[index]);
}
});
});
// #enddocregion listTile
},
);