Skip to content
Snippets Groups Projects
Commit de986225 authored by NOOBJE's avatar NOOBJE
Browse files

6단계 끝

parent 7b87272c
No related branches found
No related tags found
No related merge requests found
......@@ -32,6 +32,17 @@ class MyAppState extends ChangeNotifier {
current = WordPair.random();
notifyListeners();
}
var favorites = <WordPair>[];
void toggleFavorite() {
if (favorites.contains(current)) {
favorites.remove(current);
} else {
favorites.add(current);
}
notifyListeners();
}
}
class MyHomePage extends StatelessWidget {
......@@ -39,14 +50,32 @@ class MyHomePage extends StatelessWidget {
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
var pair = appState.current;
IconData icon;
if (appState.favorites.contains(pair)) {
icon = Icons.favorite;
} else {
icon = Icons.favorite_border;
}
return Scaffold(
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
BigCard(pair: pair),
SizedBox(height: 10),
Row(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton.icon(
onPressed: () {
appState.toggleFavorite();
},
icon: Icon(icon),
label: Text('Like'),
),
SizedBox(width: 10),
ElevatedButton(
onPressed: () {
appState.getNext();
......@@ -55,6 +84,8 @@ class MyHomePage extends StatelessWidget {
),
],
),
],
),
),
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment