Skip to content

Commit

Permalink
add: tap action
Browse files Browse the repository at this point in the history
  • Loading branch information
LanceGin committed Sep 22, 2018
1 parent db2d079 commit 2c19c6c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class RandomWords extends StatefulWidget {

class RandomWordsState extends State<RandomWords> {
final _suggestions = <WordPair>[];
final _saved = new Set<WordPair>();
final _biggerFont = const TextStyle(fontSize: 18.0);

Widget _buildSuggestions() {
Expand All @@ -39,11 +40,25 @@ class RandomWordsState extends State<RandomWords> {
}

Widget _buildRow(WordPair pair) {
final alreadySaved = _saved.contains(pair);
return new ListTile(
title: new Text(
pair.asPascalCase,
style: _biggerFont,
),
trailing: new Icon(
alreadySaved ? Icons.favorite : Icons.favorite_border,
color: alreadySaved ? Colors.red : null,
),
onTap: () {
setState(() {
if (alreadySaved) {
_saved.remove(pair);
} else {
_saved.add(pair);
}
});
},
);
}

Expand Down

0 comments on commit 2c19c6c

Please sign in to comment.